summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/machine/UnitAddComponent.js
blob: 4e9dbc7e31dc4026d436ead2db53f26216be9df0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import PropTypes from 'prop-types'
import React from 'react'

class UnitAddComponent extends React.Component {
    static propTypes = {
        units: PropTypes.array.isRequired,
        onAdd: PropTypes.func.isRequired,
    }

    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>
            </div>
        )
    }
}

export default UnitAddComponent