summaryrefslogtreecommitdiff
path: root/frontend/src/components/app/sidebars/topology/rack/MachineComponent.js
blob: 2521f4a20a7180f321d44236257a34ecdb4f1353 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from "react";
import Shapes from "../../../../../shapes";
import { convertLoadToSimulationColor } from "../../../../../util/simulation-load";

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,
  inSimulation,
  machineLoad,
  onClick
}) => {
  let color = "white";
  if (inSimulation && machineLoad >= 0) {
    color = convertLoadToSimulationColor(machineLoad);
  }
  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: color }}
    >
      <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;