diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-07-02 18:39:28 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-08-24 19:47:21 +0200 |
| commit | f119fc78dda4d1e828dde04f378a63a93e3a0a7e (patch) | |
| tree | bea1eace5d47f21a7ccb835c6a6079bc92e48710 /frontend/src/components/modals/custom-components | |
| parent | 7f27a6370a0af25e1bf6ff8f46360c6c26c21e0b (diff) | |
Add current progress on frontend port
Diffstat (limited to 'frontend/src/components/modals/custom-components')
| -rw-r--r-- | frontend/src/components/modals/custom-components/ChangeTopologyModalComponent.js | 111 | ||||
| -rw-r--r-- | frontend/src/components/modals/custom-components/NewExperimentModalComponent.js | 21 |
2 files changed, 122 insertions, 10 deletions
diff --git a/frontend/src/components/modals/custom-components/ChangeTopologyModalComponent.js b/frontend/src/components/modals/custom-components/ChangeTopologyModalComponent.js new file mode 100644 index 00000000..e36bde48 --- /dev/null +++ b/frontend/src/components/modals/custom-components/ChangeTopologyModalComponent.js @@ -0,0 +1,111 @@ +import PropTypes from 'prop-types' +import React from 'react' +import Shapes from '../../../shapes' +import Modal from '../Modal' + +class ChangeTopologyModalComponent extends React.Component { + static propTypes = { + show: PropTypes.bool.isRequired, + topologies: PropTypes.arrayOf(Shapes.Topology), + onCreateTopology: PropTypes.func.isRequired, + onDuplicateTopology: PropTypes.func.isRequired, + onDeleteTopology: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, + } + + reset() { + this.textInput.value = '' + this.originTopology.selectedIndex = 0 + } + + onSubmit() { + if (this.originTopology.selectedIndex === 0) { + this.onCreate() + } else { + this.onDuplicate() + } + } + + onCreate() { + this.props.onCreateTopology(this.textInput.value) + this.reset() + } + + onDuplicate() { + this.props.onCreateTopology( + this.textInput.value, + this.originTopology.value, + ) + this.reset() + } + + onDelete(id) { + this.props.onDeleteTopology(id) + this.reset() + } + + onCancel() { + this.props.onCancel() + this.reset() + } + + render() { + return ( + <Modal + title="Change Topology" + show={this.props.show} + onSubmit={this.onSubmit.bind(this)} + onCancel={this.onCancel.bind(this)} + > + <div> + {this.props.topologies.forEach(topology => ( + <div key={topology._id}> + {topology.name} + <div + className="btn btn-danger" + onClick={() => this.onDelete(topology._id)} + > + Delete + </div> + </div> + ))} + </div> + + <form + onSubmit={e => { + e.preventDefault() + this.onSubmit() + }} + > + <div className="form-group"> + <label className="form-control-label">Name</label> + <input + type="text" + className="form-control" + required + ref={textInput => (this.textInput = textInput)} + /> + </div> + <div className="form-group"> + <label className="form-control-label">Topology to duplicate</label> + <select + className="form-control" + ref={originTopology => (this.originTopology = originTopology)} + > + <option value={-1} key={-1}> + None - start from scratch + </option> + {this.props.topologies.map(topology => ( + <option value={topology._id} key={topology._id}> + {topology.name} + </option> + ))} + </select> + </div> + </form> + </Modal> + ) + } +} + +export default ChangeTopologyModalComponent diff --git a/frontend/src/components/modals/custom-components/NewExperimentModalComponent.js b/frontend/src/components/modals/custom-components/NewExperimentModalComponent.js index 143109ff..ce685837 100644 --- a/frontend/src/components/modals/custom-components/NewExperimentModalComponent.js +++ b/frontend/src/components/modals/custom-components/NewExperimentModalComponent.js @@ -6,7 +6,7 @@ import Modal from '../Modal' class NewExperimentModalComponent extends React.Component { static propTypes = { show: PropTypes.bool.isRequired, - paths: PropTypes.arrayOf(Shapes.Path), + topologies: PropTypes.arrayOf(Shapes.Topology), schedulers: PropTypes.arrayOf(Shapes.Scheduler), traces: PropTypes.arrayOf(Shapes.Trace), callback: PropTypes.func.isRequired, @@ -14,7 +14,7 @@ class NewExperimentModalComponent extends React.Component { reset() { this.textInput.value = '' - this.pathSelect.selectedIndex = 0 + this.topologySelect.selectedIndex = 0 this.traceSelect.selectedIndex = 0 this.schedulerSelect.selectedIndex = 0 } @@ -22,8 +22,8 @@ class NewExperimentModalComponent extends React.Component { onSubmit() { this.props.callback( this.textInput.value, - parseInt(this.pathSelect.value, 10), - parseInt(this.traceSelect.value, 10), + this.topologySelect.value, + this.traceSelect.value, this.schedulerSelect.value, ) this.reset() @@ -53,18 +53,19 @@ class NewExperimentModalComponent extends React.Component { <input type="text" className="form-control" + required ref={textInput => (this.textInput = textInput)} /> </div> <div className="form-group"> - <label className="form-control-label">Path</label> + <label className="form-control-label">Topology</label> <select className="form-control" - ref={pathSelect => (this.pathSelect = pathSelect)} + ref={topologySelect => (this.topologySelect = topologySelect)} > - {this.props.paths.map(path => ( - <option value={path.id} key={path.id}> - {path.name ? path.name : 'Path ' + path.id} + {this.props.topologies.map(topology => ( + <option value={topology._id} key={topology._id}> + {topology.name} </option> ))} </select> @@ -76,7 +77,7 @@ class NewExperimentModalComponent extends React.Component { ref={traceSelect => (this.traceSelect = traceSelect)} > {this.props.traces.map(trace => ( - <option value={trace.id} key={trace.id}> + <option value={trace._id} key={trace._id}> {trace.name} </option> ))} |
