blob: 1617b3bffa45473175e5f44b6e0cc5358adf81ce (
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
|
import PropTypes from 'prop-types'
import React from 'react'
import Image from 'next/image'
import { Machine } from '../../../../../shapes'
import { Flex, Label } from '@patternfly/react-core'
const UnitIcon = ({ id, type }) => (
<Image
src={'/img/topology/' + id + '-icon.png'}
alt={'Machine contains ' + type + ' units'}
layout="intrinsic"
height={24}
width={24}
/>
)
UnitIcon.propTypes = {
id: PropTypes.string,
type: PropTypes.string,
}
const MachineComponent = ({ machine, onClick }) => {
const hasNoUnits =
machine.cpus.length + machine.gpus.length + machine.memories.length + machine.storages.length === 0
return (
<Flex onClick={() => onClick()}>
{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 ? (
<Label variant="outline" color="orange">
Machine with no units
</Label>
) : undefined}
</Flex>
)
}
MachineComponent.propTypes = {
machine: Machine.isRequired,
onClick: PropTypes.func,
}
export default MachineComponent
|