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 (
{ e.preventDefault() this.onSubmit() }} >
(this.textInput = textInput)} />
) } } export default NewTopologyModalComponent