From d354e0a3762953d3c159f5347d9aeab490664864 Mon Sep 17 00:00:00 2001 From: Markus Grigull Date: Tue, 4 Apr 2017 20:29:05 +0200 Subject: [PATCH] Change import dialog before modal dialog Name exported file after simulator name --- src/components/dialog/import-node.js | 13 ++--- src/components/dialog/import-simulator.js | 63 +++++++++++++---------- src/containers/simulators.js | 20 +++++++ 3 files changed, 61 insertions(+), 35 deletions(-) diff --git a/src/components/dialog/import-node.js b/src/components/dialog/import-node.js index 6b19e46..ed10849 100644 --- a/src/components/dialog/import-node.js +++ b/src/components/dialog/import-node.js @@ -7,18 +7,13 @@ * Unauthorized copying of this file, via any medium is strictly prohibited. **********************************************************************************/ -import React, { Component, PropTypes } from 'react'; +import React from 'react'; import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; import Dialog from './dialog'; -class ImportSimulatorDialog extends Component { - static propTypes = { - show: PropTypes.bool.isRequired, - onClose: PropTypes.func.isRequired - }; - - valid: false; +class ImportNodeDialog extends React.Component { + valid = false; constructor(props) { super(props); @@ -91,4 +86,4 @@ class ImportSimulatorDialog extends Component { } } -export default ImportSimulatorDialog; +export default ImportNodeDialog; diff --git a/src/components/dialog/import-simulator.js b/src/components/dialog/import-simulator.js index 6b19e46..996c323 100644 --- a/src/components/dialog/import-simulator.js +++ b/src/components/dialog/import-simulator.js @@ -42,47 +42,58 @@ class ImportSimulatorDialog extends Component { } resetState() { - this.setState({ name: '', endpoint: '' }); - } + this.setState({ + name: this.props.simulator.name, + endpoint: this.props.simulator.endpoint + }); - loadFile(fileList) { - // get file - const file = fileList[0]; - if (!file.type.match('application/json')) { - return; + // validate incoming state + var endpoint = true; + var name = true; + + if (this.props.simulator.name === '') { + name = false; } - // create file reader - var reader = new FileReader(); - var self = this; + if (this.props.simulator.endpoint === '') { + endpoint = false; + } - reader.onload = function(event) { - // read simulator - const simulator = JSON.parse(event.target.result); - self.valid = true; - self.setState({ name: simulator.name, endpoint: simulator.endpoint }); - }; + this.valid = endpoint && name; + } - reader.readAsText(file); + validateForm(target) { + // check all controls + var endpoint = true; + var name = true; + + if (this.state.name === '') { + name = false; + } + + if (this.state.endpoint === '') { + endpoint = false; + } + + this.valid = endpoint && name; + + // return state to control + if (target === 'name') return name ? "success" : "error"; + else return endpoint ? "success" : "error"; } render() { return ( this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}>
- - Simulator File - this.loadFile(e.target.files)} /> - - - + Name - this.handleChange(e)} /> + this.handleChange(e)} /> - + Endpoint - this.handleChange(e)} /> + this.handleChange(e)} /> diff --git a/src/containers/simulators.js b/src/containers/simulators.js index 7111ddf..31ed312 100644 --- a/src/containers/simulators.js +++ b/src/containers/simulators.js @@ -253,6 +253,26 @@ class Simulators extends Component { } } + loadFile(fileList) { + // get file + const file = fileList[0]; + if (!file.type.match('application/json')) { + return; + } + + // create file reader + var reader = new FileReader(); + var self = this; + + reader.onload = function(event) { + // read simulator + const simulator = JSON.parse(event.target.result); + self.setState({ importModal: true, modalSimulator: simulator }); + }; + + reader.readAsText(file); + } + render() { return (