From f119fc78dda4d1e828dde04f378a63a93e3a0a7e Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Thu, 2 Jul 2020 18:39:28 +0200 Subject: Add current progress on frontend port --- .../ChangeTopologyModalComponent.js | 111 +++++++++++++++++++++ .../NewExperimentModalComponent.js | 21 ++-- 2 files changed, 122 insertions(+), 10 deletions(-) create mode 100644 frontend/src/components/modals/custom-components/ChangeTopologyModalComponent.js (limited to 'frontend/src/components/modals') 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 ( + +
+ {this.props.topologies.forEach(topology => ( +
+ {topology.name} +
this.onDelete(topology._id)} + > + Delete +
+
+ ))} +
+ +
{ + e.preventDefault() + this.onSubmit() + }} + > +
+ + (this.textInput = textInput)} + /> +
+
+ + +
+
+
+ ) + } +} + +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 { (this.textInput = textInput)} />
- + @@ -76,7 +77,7 @@ class NewExperimentModalComponent extends React.Component { ref={traceSelect => (this.traceSelect = traceSelect)} > {this.props.traces.map(trace => ( - ))} -- cgit v1.2.3