|
@@ -4,22 +4,48 @@ import FormGroup from 'react-bootstrap/es/FormGroup';
|
|
|
import ControlLabel from 'react-bootstrap/es/ControlLabel';
|
|
import ControlLabel from 'react-bootstrap/es/ControlLabel';
|
|
|
import FormControl from 'react-bootstrap/es/FormControl';
|
|
import FormControl from 'react-bootstrap/es/FormControl';
|
|
|
import Button from 'react-bootstrap/es/Button';
|
|
import Button from 'react-bootstrap/es/Button';
|
|
|
|
|
+import MarkdownTable from '../../models/MarkdownTable';
|
|
|
|
|
+import Collapse from 'react-bootstrap/es/Collapse';
|
|
|
|
|
|
|
|
-export default class TableDataImportForm extends React.Component {
|
|
|
|
|
|
|
+export default class MarkdownTableDataImportForm extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
this.state = {
|
|
|
dataFormat: 'csv',
|
|
dataFormat: 'csv',
|
|
|
- data: ''
|
|
|
|
|
|
|
+ data: '',
|
|
|
|
|
+ parserErrorMessage: null
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
this.importButtonHandler = this.importButtonHandler.bind(this);
|
|
this.importButtonHandler = this.importButtonHandler.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
importButtonHandler() {
|
|
importButtonHandler() {
|
|
|
- this.props.onImport(this.state.dataFormat, this.state.data);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const markdownTable = this.convertFormDataToMarkdownTable();
|
|
|
|
|
+ this.props.onImport(markdownTable);
|
|
|
|
|
+ this.setState({parserErrorMessage: null});
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (e) {
|
|
|
|
|
+ this.setState({parserErrorMessage: e.message});
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ convertFormDataToMarkdownTable() {
|
|
|
|
|
+ let result;
|
|
|
|
|
+ switch (this.state.dataFormat) {
|
|
|
|
|
+ case 'csv':
|
|
|
|
|
+ result = MarkdownTable.fromDSV(this.state.data, ',');
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'tsv':
|
|
|
|
|
+ result = MarkdownTable.fromDSV(this.state.data, '\t');
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'html':
|
|
|
|
|
+ result = MarkdownTable.fromHTMLTableTag(this.state.data);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
@@ -31,7 +57,7 @@ export default class TableDataImportForm extends React.Component {
|
|
|
value={this.state.dataFormat} onChange={e => this.setState({dataFormat: e.target.value})}>
|
|
value={this.state.dataFormat} onChange={e => this.setState({dataFormat: e.target.value})}>
|
|
|
<option value="csv">CSV</option>
|
|
<option value="csv">CSV</option>
|
|
|
<option value="tsv">TSV</option>
|
|
<option value="tsv">TSV</option>
|
|
|
- <option value="html">(TBD) HTML</option>
|
|
|
|
|
|
|
+ <option value="html">HTML</option>
|
|
|
</FormControl>
|
|
</FormControl>
|
|
|
</FormGroup>
|
|
</FormGroup>
|
|
|
<FormGroup>
|
|
<FormGroup>
|
|
@@ -39,6 +65,12 @@ export default class TableDataImportForm extends React.Component {
|
|
|
<FormControl componentClass="textarea" placeholder="Paste table data" style={{ height: 200 }}
|
|
<FormControl componentClass="textarea" placeholder="Paste table data" style={{ height: 200 }}
|
|
|
onChange={e => this.setState({data: e.target.value})}/>
|
|
onChange={e => this.setState({data: e.target.value})}/>
|
|
|
</FormGroup>
|
|
</FormGroup>
|
|
|
|
|
+ <Collapse in={this.state.parserErrorMessage != null}>
|
|
|
|
|
+ <FormGroup>
|
|
|
|
|
+ <ControlLabel>Parse Error</ControlLabel>
|
|
|
|
|
+ <FormControl componentClass="textarea" style={{ height: 100 }} value={this.state.parserErrorMessage} readOnly/>
|
|
|
|
|
+ </FormGroup>
|
|
|
|
|
+ </Collapse>
|
|
|
<div className="d-flex justify-content-end">
|
|
<div className="d-flex justify-content-end">
|
|
|
<Button bsStyle="default" onClick={this.props.onCancel}>Cancel</Button>
|
|
<Button bsStyle="default" onClick={this.props.onCancel}>Cancel</Button>
|
|
|
<Button bsStyle="primary" onClick={this.importButtonHandler}>Import</Button>
|
|
<Button bsStyle="primary" onClick={this.importButtonHandler}>Import</Button>
|
|
@@ -48,7 +80,7 @@ export default class TableDataImportForm extends React.Component {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-TableDataImportForm.propTypes = {
|
|
|
|
|
|
|
+MarkdownTableDataImportForm.propTypes = {
|
|
|
onCancel: PropTypes.func,
|
|
onCancel: PropTypes.func,
|
|
|
onImport: PropTypes.func
|
|
onImport: PropTypes.func
|
|
|
};
|
|
};
|