diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-05-13 13:00:00 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-05-17 17:06:49 +0200 |
| commit | 24147cba0f5723be3525e8f40d1954144841629b (patch) | |
| tree | d44727504f7a9c579219616cbdba5e965543561a /opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js | |
| parent | 4397a959e806bf476be4c81bc804616adf58b969 (diff) | |
ui: Address technical dept in frontend
Diffstat (limited to 'opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js')
| -rw-r--r-- | opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js index 4e9dbc7e..f80fccc8 100644 --- a/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js +++ b/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js @@ -1,35 +1,35 @@ import PropTypes from 'prop-types' -import React from 'react' +import React, { useRef } from 'react' -class UnitAddComponent extends React.Component { - static propTypes = { - units: PropTypes.array.isRequired, - onAdd: PropTypes.func.isRequired, - } +function UnitAddComponent({ units, onAdd }) { + const unitSelect = useRef(null) - render() { - return ( - <div className="form-inline"> - <div className="form-group w-100"> - <select className="form-control w-70 mr-1" ref={(unitSelect) => (this.unitSelect = unitSelect)}> - {this.props.units.map((unit) => ( - <option value={unit._id} key={unit._id}> - {unit.name} - </option> - ))} - </select> - <button - type="submit" - className="btn btn-outline-primary" - onClick={() => this.props.onAdd(this.unitSelect.value)} - > - <span className="fa fa-plus mr-2" /> - Add - </button> - </div> + return ( + <div className="form-inline"> + <div className="form-group w-100"> + <select className="form-control w-70 mr-1" ref={unitSelect}> + {units.map((unit) => ( + <option value={unit._id} key={unit._id}> + {unit.name} + </option> + ))} + </select> + <button + type="submit" + className="btn btn-outline-primary" + onClick={() => onAdd(unitSelect.current.value)} + > + <span className="fa fa-plus mr-2" /> + Add + </button> </div> - ) - } + </div> + ) +} + +UnitAddComponent.propTypes = { + units: PropTypes.array.isRequired, + onAdd: PropTypes.func.isRequired, } export default UnitAddComponent |
