|
|
@@ -1,19 +1,14 @@
|
|
|
import React from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
|
-
|
|
|
import Modal from 'react-bootstrap/es/Modal';
|
|
|
import Button from 'react-bootstrap/es/Button';
|
|
|
import ButtonGroup from 'react-bootstrap/es/ButtonGroup';
|
|
|
-
|
|
|
-import { debounce } from 'throttle-debounce';
|
|
|
import Collapse from 'react-bootstrap/es/Collapse';
|
|
|
-import FormGroup from 'react-bootstrap/es/FormGroup';
|
|
|
-import ControlLabel from 'react-bootstrap/es/ControlLabel';
|
|
|
-import FormControl from 'react-bootstrap/es/FormControl';
|
|
|
-
|
|
|
import Handsontable from 'handsontable';
|
|
|
import { HotTable } from '@handsontable/react';
|
|
|
+import { debounce } from 'throttle-debounce';
|
|
|
|
|
|
+import TableDataImportForm from './TableDataImportForm';
|
|
|
import MarkdownTable from '../../models/MarkdownTable';
|
|
|
|
|
|
const DEFAULT_HOT_HEIGHT = 300;
|
|
|
@@ -51,6 +46,7 @@ export default class HandsontableModal extends React.PureComponent {
|
|
|
this.synchronizeAlignment = this.synchronizeAlignment.bind(this);
|
|
|
this.alignButtonHandler = this.alignButtonHandler.bind(this);
|
|
|
this.toggleDataImportArea = this.toggleDataImportArea.bind(this);
|
|
|
+ this.importData = this.importData.bind(this);
|
|
|
this.expandWindow = this.expandWindow.bind(this);
|
|
|
this.contractWindow = this.contractWindow.bind(this);
|
|
|
|
|
|
@@ -248,6 +244,18 @@ export default class HandsontableModal extends React.PureComponent {
|
|
|
this.setState({ isDataImportAreaExpanded: !this.state.isDataImportAreaExpanded });
|
|
|
}
|
|
|
|
|
|
+ importData(dataFormat, data) {
|
|
|
+ switch (dataFormat) {
|
|
|
+ case 'csv':
|
|
|
+ this.init(MarkdownTable.fromDSV(data, ','));
|
|
|
+ break;
|
|
|
+ case 'tsv':
|
|
|
+ this.init(MarkdownTable.fromDSV(data, '\t'));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ this.toggleDataImportArea();
|
|
|
+ }
|
|
|
+
|
|
|
expandWindow() {
|
|
|
this.setState({ isWindowExpanded: true });
|
|
|
|
|
|
@@ -298,7 +306,7 @@ export default class HandsontableModal extends React.PureComponent {
|
|
|
<Modal.Body className="p-0 d-flex flex-column">
|
|
|
<div className="px-4 py-3 modal-navbar">
|
|
|
<Button className="m-r-20 data-import-button" onClick={this.toggleDataImportArea}>
|
|
|
- (TBD) Data Import<i className={this.state.isDataImportAreaExpanded ? 'fa fa-angle-up' : 'fa fa-angle-down' }></i>
|
|
|
+ Data Import<i className={this.state.isDataImportAreaExpanded ? 'fa fa-angle-up' : 'fa fa-angle-down' }></i>
|
|
|
</Button>
|
|
|
<ButtonGroup>
|
|
|
<Button onClick={() => { this.alignButtonHandler('l') }}><i className="ti-align-left"></i></Button>
|
|
|
@@ -307,24 +315,7 @@ export default class HandsontableModal extends React.PureComponent {
|
|
|
</ButtonGroup>
|
|
|
<Collapse in={this.state.isDataImportAreaExpanded}>
|
|
|
<div> {/* This div is necessary for smoothing animations. (https://react-bootstrap.github.io/utilities/transitions/#transitions-collapse) */}
|
|
|
- <form action="" className="data-import-form pt-5">
|
|
|
- <FormGroup>
|
|
|
- <ControlLabel>Select Data Format</ControlLabel>
|
|
|
- <FormControl componentClass="select" placeholder="select">
|
|
|
- <option value="select">(TBD) CSV</option>
|
|
|
- <option value="other">(TBD) TSV</option>
|
|
|
- <option value="other">(TBD) HTML</option>
|
|
|
- </FormControl>
|
|
|
- </FormGroup>
|
|
|
- <FormGroup>
|
|
|
- <ControlLabel>Import Data</ControlLabel>
|
|
|
- <FormControl componentClass="textarea" placeholder="Paste table data" style={{ height: 200 }} />
|
|
|
- </FormGroup>
|
|
|
- <div className="d-flex justify-content-end">
|
|
|
- <Button bsStyle="default" onClick={this.toggleDataImportArea}>Cancel</Button>
|
|
|
- <Button bsStyle="primary">(TBD) Import</Button>
|
|
|
- </div>
|
|
|
- </form>
|
|
|
+ <TableDataImportForm onCancel={this.toggleDataImportArea} onImport={this.importData}/>
|
|
|
</div>
|
|
|
</Collapse>
|
|
|
</div>
|