|
| 1 | +// Components |
| 2 | +import { Stack } from "@mui/material"; |
| 3 | +import InfraAreaChart from "./InfraAreaChart"; |
| 4 | +import SkeletonLayout from "./skeleton"; |
| 5 | + |
| 6 | +// Utils |
| 7 | +import { |
| 8 | + PercentTick, |
| 9 | + TzTick, |
| 10 | + InfrastructureTooltip, |
| 11 | + TemperatureTooltip, |
| 12 | +} from "../../../../../Components/Charts/Utils/chartUtils"; |
| 13 | +import { useTheme } from "@emotion/react"; |
| 14 | +import { useHardwareUtils } from "../../Hooks/useHardwareUtils"; |
| 15 | +const AreaChartBoxes = ({ shouldRender, monitor, dateRange }) => { |
| 16 | + const theme = useTheme(); |
| 17 | + const { buildTemps } = useHardwareUtils(); |
| 18 | + |
| 19 | + if (!shouldRender) { |
| 20 | + return <SkeletonLayout />; |
| 21 | + } |
| 22 | + |
| 23 | + const { stats } = monitor ?? {}; |
| 24 | + const { checks } = stats; |
| 25 | + |
| 26 | + let latestCheck = checks[0]; |
| 27 | + const { temps, tempKeys } = buildTemps(checks); |
| 28 | + |
| 29 | + const configs = [ |
| 30 | + { |
| 31 | + type: "memory", |
| 32 | + data: checks, |
| 33 | + dataKeys: ["avgMemoryUsage"], |
| 34 | + heading: "Memory usage", |
| 35 | + strokeColor: theme.palette.accent.main, // CAIO_REVIEW |
| 36 | + gradientStartColor: theme.palette.accent.main, // CAIO_REVIEW |
| 37 | + yLabel: "Memory usage", |
| 38 | + yDomain: [0, 1], |
| 39 | + yTick: <PercentTick />, |
| 40 | + xTick: <TzTick dateRange={dateRange} />, |
| 41 | + toolTip: ( |
| 42 | + <InfrastructureTooltip |
| 43 | + dotColor={theme.palette.primary.main} |
| 44 | + yKey={"avgMemoryUsage"} |
| 45 | + yLabel={"Memory usage"} |
| 46 | + dateRange={dateRange} |
| 47 | + /> |
| 48 | + ), |
| 49 | + }, |
| 50 | + { |
| 51 | + type: "cpu", |
| 52 | + data: checks, |
| 53 | + dataKeys: ["avgCpuUsage"], |
| 54 | + heading: "CPU usage", |
| 55 | + strokeColor: theme.palette.success.main, |
| 56 | + gradientStartColor: theme.palette.success.main, |
| 57 | + yLabel: "CPU usage", |
| 58 | + yDomain: [0, 1], |
| 59 | + yTick: <PercentTick />, |
| 60 | + xTick: <TzTick dateRange={dateRange} />, |
| 61 | + toolTip: ( |
| 62 | + <InfrastructureTooltip |
| 63 | + dotColor={theme.palette.success.main} |
| 64 | + yKey={"avgCpuUsage"} |
| 65 | + yLabel={"CPU usage"} |
| 66 | + dateRange={dateRange} |
| 67 | + /> |
| 68 | + ), |
| 69 | + }, |
| 70 | + { |
| 71 | + type: "temperature", |
| 72 | + data: temps, |
| 73 | + dataKeys: tempKeys, |
| 74 | + strokeColor: theme.palette.error.main, |
| 75 | + gradientStartColor: theme.palette.error.main, |
| 76 | + heading: "CPU Temperature", |
| 77 | + yLabel: "Temperature", |
| 78 | + xTick: <TzTick dateRange={dateRange} />, |
| 79 | + yDomain: [ |
| 80 | + 0, |
| 81 | + Math.max(Math.max(...temps.flatMap((t) => tempKeys.map((k) => t[k]))) * 1.1, 200), |
| 82 | + ], |
| 83 | + toolTip: ( |
| 84 | + <TemperatureTooltip |
| 85 | + keys={tempKeys} |
| 86 | + dotColor={theme.palette.error.main} |
| 87 | + dateRange={dateRange} |
| 88 | + /> |
| 89 | + ), |
| 90 | + }, |
| 91 | + ...(latestCheck?.disks?.map((disk, idx) => ({ |
| 92 | + type: "disk", |
| 93 | + data: checks, |
| 94 | + diskIndex: idx, |
| 95 | + dataKeys: [`disks[${idx}].usagePercent`], |
| 96 | + heading: `Disk${idx} usage`, |
| 97 | + strokeColor: theme.palette.warning.main, |
| 98 | + gradientStartColor: theme.palette.warning.main, |
| 99 | + yLabel: "Disk Usage", |
| 100 | + yDomain: [0, 1], |
| 101 | + yTick: <PercentTick />, |
| 102 | + xTick: <TzTick dateRange={dateRange} />, |
| 103 | + toolTip: ( |
| 104 | + <InfrastructureTooltip |
| 105 | + dotColor={theme.palette.warning.main} |
| 106 | + yKey={`disks.usagePercent`} |
| 107 | + yLabel={"Disc usage"} |
| 108 | + yIdx={idx} |
| 109 | + dateRange={dateRange} |
| 110 | + /> |
| 111 | + ), |
| 112 | + })) || []), |
| 113 | + ]; |
| 114 | + |
| 115 | + return ( |
| 116 | + <Stack |
| 117 | + direction={"row"} |
| 118 | + // height={chartContainerHeight} // FE team HELP! Possibly no longer needed? |
| 119 | + gap={theme.spacing(8)} // FE team HELP! |
| 120 | + flexWrap="wrap" // //FE team HELP! Better way to do this? |
| 121 | + sx={{ |
| 122 | + "& > *": { |
| 123 | + flexBasis: `calc(50% - ${theme.spacing(8)})`, |
| 124 | + maxWidth: `calc(50% - ${theme.spacing(8)})`, |
| 125 | + }, |
| 126 | + }} |
| 127 | + > |
| 128 | + {configs.map((config) => ( |
| 129 | + <InfraAreaChart |
| 130 | + key={`${config.type}-${config.diskIndex ?? ""}`} |
| 131 | + config={config} |
| 132 | + /> |
| 133 | + ))} |
| 134 | + </Stack> |
| 135 | + ); |
| 136 | +}; |
| 137 | + |
| 138 | +export default AreaChartBoxes; |
0 commit comments