Skip to content

Commit cd9fee0

Browse files
committed
add confirmation
1 parent d8f19cb commit cd9fee0

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/dashboard/Data/Browser/Browser.react.js

+2
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,8 @@ class Browser extends DashboardView {
18641864
<ExportSelectedRowsDialog
18651865
className={className}
18661866
selection={this.state.rowsToExport}
1867+
count={this.state.counts[className]}
1868+
data={this.state.data}
18671869
onCancel={this.cancelExportSelectedRows}
18681870
onConfirm={(type, indentation) => this.confirmExportSelectedRows(this.state.rowsToExport, type, indentation)}
18691871
/>

src/dashboard/Data/Browser/ExportSelectedRowsDialog.react.js

+34
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import Field from 'components/Field/Field.react';
1212
import Label from 'components/Label/Label.react';
1313
import Option from 'components/Dropdown/Option.react';
1414
import Toggle from 'components/Toggle/Toggle.react';
15+
import TextInput from 'components/TextInput/TextInput.react';
16+
import styles from 'dashboard/Data/Browser/ExportSelectedRowsDialog.scss';
1517

1618
export default class ExportSelectedRowsDialog extends React.Component {
1719
constructor() {
@@ -25,11 +27,28 @@ export default class ExportSelectedRowsDialog extends React.Component {
2527
}
2628

2729
valid() {
30+
if (this.state.confirmation !== 'export all') {
31+
return false;
32+
}
2833
return true;
2934
}
3035

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+
3149
render() {
3250
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
3352
return (
3453
<Modal
3554
type={Modal.Types.INFO}
@@ -41,6 +60,9 @@ export default class ExportSelectedRowsDialog extends React.Component {
4160
cancelText='Cancel'
4261
onCancel={this.props.onCancel}
4362
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>
4466
<Field
4567
label={<Label text='Select export type' />}
4668
input={
@@ -55,6 +77,18 @@ export default class ExportSelectedRowsDialog extends React.Component {
5577
label={<Label text='Indentation' />}
5678
input={<Toggle value={this.state.indentation} type={Toggle.Types.YES_NO} onChange={(indentation) => {this.setState({indentation})}} />} />
5779
}
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+
} />
5892
</Modal>
5993
);
6094
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.row {
2+
display: block;
3+
position: relative;
4+
height: 100px;
5+
border-bottom: 1px solid #e0e0e1;
6+
}
7+
.label {
8+
line-height: 16px;
9+
}

0 commit comments

Comments
 (0)