summaryrefslogtreecommitdiff
path: root/frontend/src/components/app/sidebars/topology/rack/MachineComponent.js
blob: caa3dc046a416b7434851c4bcf52fedbde595c0e (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
import React from 'react'
import Shapes from '../../../../../shapes'

const UnitIcon = ({ id, type }) => (
    <div>
        <img
            src={'/img/topology/' + id + '-icon.png'}
            alt={'Machine contains ' + type + ' units'}
            className="img-fluid ml-1"
            style={{ maxHeight: '35px' }}
        />
    </div>
)

const MachineComponent = ({ position, machine, onClick }) => {
    const hasNoUnits =
        machine.cpuIds.length + machine.gpuIds.length + machine.memoryIds.length + machine.storageIds.length === 0

    return (
        <li
            className="d-flex list-group-item list-group-item-action justify-content-between align-items-center"
            onClick={onClick}
            style={{ backgroundColor: 'white' }}
        >
            <span className="badge badge-default badge-info mr-1">{position}</span>
            <div className="d-inline-flex">
                {machine.cpuIds.length > 0 ? <UnitIcon id="cpu" type="CPU" /> : undefined}
                {machine.gpuIds.length > 0 ? <UnitIcon id="gpu" type="GPU" /> : undefined}
                {machine.memoryIds.length > 0 ? <UnitIcon id="memory" type="memory" /> : undefined}
                {machine.storageIds.length > 0 ? <UnitIcon id="storage" type="storage" /> : undefined}
                {hasNoUnits ? (
                    <span className="badge badge-default badge-warning">Machine with no units</span>
                ) : undefined}
            </div>
        </li>
    )
}

MachineComponent.propTypes = {
    machine: Shapes.Machine,
}

export default MachineComponent