summaryrefslogtreecommitdiff
path: root/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-07-07 11:20:43 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:47:25 +0200
commit890cd3f7028bfccd77b0d04670f7bc07293ed383 (patch)
tree6be55c9c1330cb1d77cb7aaedcb91596f2e34574 /frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
parentb4bdf9fde013bb7ff9579693b64ff575f7b00e44 (diff)
Add new left sidebar, move topology controls
Diffstat (limited to 'frontend/src/components/modals/custom-components/NewTopologyModalComponent.js')
-rw-r--r--frontend/src/components/modals/custom-components/NewTopologyModalComponent.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js b/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
new file mode 100644
index 00000000..a0d736a1
--- /dev/null
+++ b/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
@@ -0,0 +1,92 @@
+import PropTypes from 'prop-types'
+import React from 'react'
+import Shapes from '../../../shapes'
+import Modal from '../Modal'
+
+class NewTopologyModalComponent extends React.Component {
+ static propTypes = {
+ show: PropTypes.bool.isRequired,
+ topologies: PropTypes.arrayOf(Shapes.Topology),
+ onCreateTopology: PropTypes.func.isRequired,
+ onDuplicateTopology: 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()
+ }
+
+ onCancel() {
+ this.props.onCancel()
+ this.reset()
+ }
+
+ render() {
+ return (
+ <Modal
+ title="New Topology"
+ show={this.props.show}
+ onSubmit={this.onSubmit.bind(this)}
+ onCancel={this.onCancel.bind(this)}
+ >
+ <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 (not supported yet)</label>
+ <select
+ className="form-control"
+ disabled
+ 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 NewTopologyModalComponent