@@ -12,6 +12,8 @@ import Field from 'components/Field/Field.react';
12
12
import Label from 'components/Label/Label.react' ;
13
13
import Option from 'components/Dropdown/Option.react' ;
14
14
import Toggle from 'components/Toggle/Toggle.react' ;
15
+ import TextInput from 'components/TextInput/TextInput.react' ;
16
+ import styles from 'dashboard/Data/Browser/ExportSelectedRowsDialog.scss' ;
15
17
16
18
export default class ExportSelectedRowsDialog extends React . Component {
17
19
constructor ( ) {
@@ -25,11 +27,28 @@ export default class ExportSelectedRowsDialog extends React.Component {
25
27
}
26
28
27
29
valid ( ) {
30
+ if ( this . state . confirmation !== 'export all' ) {
31
+ return false ;
32
+ }
28
33
return true ;
29
34
}
30
35
36
+ formatBytes ( bytes ) {
37
+ if ( ! + bytes ) return '0 Bytes'
38
+
39
+ const k = 1024
40
+ const decimals = 2
41
+ const sizes = [ 'Bytes' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ]
42
+
43
+ const i = Math . floor ( Math . log ( bytes ) / Math . log ( k ) )
44
+
45
+ return `${ parseFloat ( ( bytes / Math . pow ( k , i ) ) . toFixed ( decimals ) ) } ${ sizes [ i ] } `
46
+ }
47
+
48
+
31
49
render ( ) {
32
50
let selectionLength = Object . keys ( this . props . selection ) . length ;
51
+ const fileSize = new TextEncoder ( ) . encode ( JSON . stringify ( this . props . data , null , this . state . exportType === '.json' && this . state . indentation ? 2 : null ) ) . length / this . props . data . length
33
52
return (
34
53
< Modal
35
54
type = { Modal . Types . INFO }
@@ -41,6 +60,9 @@ export default class ExportSelectedRowsDialog extends React.Component {
41
60
cancelText = 'Cancel'
42
61
onCancel = { this . props . onCancel }
43
62
onConfirm = { ( ) => this . props . onConfirm ( this . state . exportType , this . state . indentation ) } >
63
+ < div className = { styles . row } >
64
+ < Label text = "Do you really want to export all rows?" description = { < span className = { styles . label } > Estimated row count: { this . props . count } < br /> Estimated export size: { this . formatBytes ( fileSize ) } </ span > } />
65
+ </ div >
44
66
< Field
45
67
label = { < Label text = 'Select export type' /> }
46
68
input = {
@@ -55,6 +77,18 @@ export default class ExportSelectedRowsDialog extends React.Component {
55
77
label = { < Label text = 'Indentation' /> }
56
78
input = { < Toggle value = { this . state . indentation } type = { Toggle . Types . YES_NO } onChange = { ( indentation ) => { this . setState ( { indentation} ) } } /> } />
57
79
}
80
+ < Field
81
+ label = {
82
+ < Label
83
+ text = 'Confirm Export all'
84
+ description = 'Enter "export all" to continue.' />
85
+ }
86
+ input = {
87
+ < TextInput
88
+ placeholder = 'export all'
89
+ value = { this . state . confirmation }
90
+ onChange = { ( confirmation ) => this . setState ( { confirmation } ) } />
91
+ } />
58
92
</ Modal >
59
93
) ;
60
94
}
0 commit comments