summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/app/sidebars/topology/rack/MachineComponent.js
blob: b71918dac79503115136ac0688d086df1c187f56 (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
import PropTypes from 'prop-types'
import React from 'react'
import Image from 'next/image'
import { Machine } from '../../../../../shapes'
import { Badge, ListGroupItem } from 'reactstrap'

const UnitIcon = ({ id, type }) => (
    <div className="ml-1">
        <Image
            src={'/img/topology/' + id + '-icon.png'}
            alt={'Machine contains ' + type + ' units'}
            layout="intrinsic"
            height={35}
            width={35}
        />
    </div>
)

UnitIcon.propTypes = {
    id: PropTypes.string,
    type: PropTypes.string,
}

const MachineComponent = ({ position, machine, onClick }) => {
    const hasNoUnits =
        machine.cpus.length + machine.gpus.length + machine.memories.length + machine.storages.length === 0

    return (
        <ListGroupItem
            action
            className="d-flex justify-content-between align-items-center"
            onClick={onClick}
            style={{ backgroundColor: 'white' }}
        >
            <Badge color="info" className="mr-1">
                {position}
            </Badge>
            <div className="d-inline-flex">
                {machine.cpus.length > 0 ? <UnitIcon id="cpu" type="CPU" /> : undefined}
                {machine.gpus.length > 0 ? <UnitIcon id="gpu" type="GPU" /> : undefined}
                {machine.memories.length > 0 ? <UnitIcon id="memory" type="memory" /> : undefined}
                {machine.storages.length > 0 ? <UnitIcon id="storage" type="storage" /> : undefined}
                {hasNoUnits ? <Badge color="warning">Machine with no units</Badge> : undefined}
            </div>
        </ListGroupItem>
    )
}

MachineComponent.propTypes = {
    machine: Machine,
    position: PropTypes.number,
    onClick: PropTypes.func,
}

export default MachineComponent