summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-server/src/main/webui/components/topologies/sidebar/room/RackConstructionComponent.js
blob: f9eab381ec64cfaff81ca1c22320222921091d6f (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import PropTypes from 'prop-types'
import React from 'react'
import { Button, FormSelect, FormSelectOption } from '@patternfly/react-core'
import { PlusIcon, TimesIcon } from '@patternfly/react-icons'

const RackConstructionComponent = ({ onStart, onStop, inRackConstructionMode, isEditingRoom, prefabs = [] }) => {
    const [selectedPrefabId, setSelectedPrefabId] = React.useState('')

    if (inRackConstructionMode) {
        return (
            <Button isBlock={true} icon={<TimesIcon />} onClick={onStop} className="pf-u-mb-sm">
                Stop rack construction
            </Button>
        )
    }

    const onChangePrefab = (value) => {
        setSelectedPrefabId(value)
    }

    return (
        <>
            <FormSelect
                value={selectedPrefabId}
                onChange={onChangePrefab}
                aria-label="Select rack prefab"
                className="pf-u-mb-sm"
            >
                <FormSelectOption key="" value="" label="Empty Rack" />
                {prefabs.map((prefab) => (
                    <FormSelectOption key={prefab.id} value={prefab.id} label={prefab.name} />
                ))}
            </FormSelect>
            <Button
                icon={<PlusIcon />}
                isBlock
                isDisabled={isEditingRoom}
                onClick={() => {
                    if (!isEditingRoom) {
                        const prefab = prefabs.find((p) => p.id === parseInt(selectedPrefabId))
                        onStart(prefab)
                    }
                }}
                className="pf-u-mb-sm"
            >
                Start rack construction
            </Button>
        </>
    )
}

RackConstructionComponent.propTypes = {
    onStart: PropTypes.func,
    onStop: PropTypes.func,
    inRackConstructionMode: PropTypes.bool,
    isEditingRoom: PropTypes.bool,
    prefabs: PropTypes.array,
}

export default RackConstructionComponent