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), currentTopologyId: PropTypes.string, onChooseTopology: PropTypes.func.isRequired, 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() } } onChoose(id) { this.props.onChooseTopology(id) this.reset() } 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.map((topology, idx) => (
{topology._id === this.props.currentTopologyId ? 'Active: ' : ''} {topology.name}
this.onChoose(topology._id)} > Choose idx !== 0 ? this.onDelete(topology._id) : undefined} > Delete
))}
New Topology
{ e.preventDefault() this.onSubmit() }} >
(this.textInput = textInput)} />
) } } export default ChangeTopologyModalComponent