Files
Checkmate/client/src/Pages/Infrastructure/Details/Components/AreaChartBoxes/index.jsx
T

140 lines
3.5 KiB
React
Raw Normal View History

2025-01-31 13:43:57 -08:00
// Components
import { Stack } from "@mui/material";
2025-09-25 10:11:41 -07:00
import InfraAreaChart from "./InfraAreaChart.jsx";
import SkeletonLayout from "./skeleton.jsx";
2025-01-31 13:43:57 -08:00
// Utils
import {
PercentTick,
TzTick,
InfrastructureTooltip,
TemperatureTooltip,
2025-09-27 14:54:55 -07:00
} from "@/Components/v1/Charts/Utils/chartUtils.jsx";
2025-01-31 13:43:57 -08:00
import { useTheme } from "@emotion/react";
2025-09-25 10:11:41 -07:00
import { useHardwareUtils } from "../../Hooks/useHardwareUtils.jsx";
2025-03-12 00:56:28 +05:30
import { useTranslation } from "react-i18next";
2025-01-31 13:43:57 -08:00
const AreaChartBoxes = ({ shouldRender, monitor, dateRange }) => {
const theme = useTheme();
2025-03-12 00:56:28 +05:30
const { t } = useTranslation();
2025-01-31 13:43:57 -08:00
const { buildTemps } = useHardwareUtils();
if (!shouldRender) {
return <SkeletonLayout />;
}
const { stats } = monitor ?? {};
const { checks } = stats;
let latestCheck = checks[0];
const { temps, tempKeys } = buildTemps(checks);
const configs = [
{
type: "memory",
data: checks,
dataKeys: ["avgMemoryUsage"],
2025-03-12 00:56:28 +05:30
heading: t("memoryUsage"),
2025-01-31 13:43:57 -08:00
strokeColor: theme.palette.accent.main, // CAIO_REVIEW
gradientStartColor: theme.palette.accent.main, // CAIO_REVIEW
2025-03-12 00:56:28 +05:30
yLabel: t("memoryUsage"),
2025-01-31 13:43:57 -08:00
yDomain: [0, 1],
yTick: <PercentTick />,
xTick: <TzTick dateRange={dateRange} />,
toolTip: (
<InfrastructureTooltip
dotColor={theme.palette.primary.main}
yKey={"avgMemoryUsage"}
yLabel={"Memory usage"}
dateRange={dateRange}
/>
),
},
{
type: "cpu",
data: checks,
dataKeys: ["avgCpuUsage"],
2025-03-12 00:56:28 +05:30
heading: t("cpuUsage"),
2025-01-31 13:43:57 -08:00
strokeColor: theme.palette.success.main,
gradientStartColor: theme.palette.success.main,
2025-03-12 00:56:28 +05:30
yLabel: t("cpuUsage"),
2025-01-31 13:43:57 -08:00
yDomain: [0, 1],
yTick: <PercentTick />,
xTick: <TzTick dateRange={dateRange} />,
toolTip: (
<InfrastructureTooltip
dotColor={theme.palette.success.main}
yKey={"avgCpuUsage"}
yLabel={"CPU usage"}
dateRange={dateRange}
/>
),
},
{
type: "temperature",
data: temps,
dataKeys: tempKeys,
strokeColor: theme.palette.error.main,
gradientStartColor: theme.palette.error.main,
2025-03-12 00:56:28 +05:30
heading: t("cpuTemperature"),
2025-01-31 13:43:57 -08:00
yLabel: "Temperature",
xTick: <TzTick dateRange={dateRange} />,
yDomain: [
0,
Math.max(Math.max(...temps.flatMap((t) => tempKeys.map((k) => t[k]))) * 1.1, 200),
],
toolTip: (
<TemperatureTooltip
keys={tempKeys}
dotColor={theme.palette.error.main}
dateRange={dateRange}
/>
),
},
...(latestCheck?.disks?.map((disk, idx) => ({
type: "disk",
data: checks,
diskIndex: idx,
dataKeys: [`disks[${idx}].usagePercent`],
heading: `Disk${idx} usage`,
strokeColor: theme.palette.warning.main,
gradientStartColor: theme.palette.warning.main,
2025-03-12 00:56:28 +05:30
yLabel: t("diskUsage"),
2025-01-31 13:43:57 -08:00
yDomain: [0, 1],
yTick: <PercentTick />,
xTick: <TzTick dateRange={dateRange} />,
toolTip: (
<InfrastructureTooltip
dotColor={theme.palette.warning.main}
yKey={`disks.usagePercent`}
yLabel={"Disc usage"}
yIdx={idx}
dateRange={dateRange}
/>
),
})) || []),
];
return (
<Stack
direction={"row"}
// height={chartContainerHeight} // FE team HELP! Possibly no longer needed?
gap={theme.spacing(8)} // FE team HELP!
flexWrap="wrap" // //FE team HELP! Better way to do this?
sx={{
"& > *": {
flexBasis: `calc(50% - ${theme.spacing(8)})`,
maxWidth: `calc(50% - ${theme.spacing(8)})`,
},
}}
>
{configs.map((config) => (
<InfraAreaChart
key={`${config.type}-${config.diskIndex ?? ""}`}
config={config}
/>
))}
</Stack>
);
};
export default AreaChartBoxes;