Files
Checkmate/client/src/Components/v2/Monitors/HistogramResponseTime.tsx
T

87 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-10-03 15:40:53 -07:00
import Stack from "@mui/material/Stack";
import Box from "@mui/material/Box";
import { useTheme } from "@mui/material/styles";
import type { Check } from "@/Types/Check";
2025-10-06 10:56:29 -07:00
import { HistogramResponseTimeTooltip } from "@/Components/v2/Monitors/HistogramResponseTimeTooltip";
2025-10-09 13:53:34 -07:00
import { normalizeResponseTimes } from "@/Utils/DataUtils";
2025-10-03 15:40:53 -07:00
export const HistogramResponseTime = ({ checks }: { checks: Check[] }) => {
2025-10-09 13:53:34 -07:00
const normalChecks = normalizeResponseTimes(checks, "responseTime");
2025-10-03 15:40:53 -07:00
let data = Array<any>();
2025-10-09 13:53:34 -07:00
if (!normalChecks || normalChecks.length === 0) {
2025-10-03 15:40:53 -07:00
return null;
}
2025-10-09 13:53:34 -07:00
if (normalChecks.length !== 25) {
const placeholders = Array(25 - normalChecks.length).fill("placeholder");
data = [...normalChecks, ...placeholders];
2025-10-03 15:40:53 -07:00
} else {
2025-10-09 13:53:34 -07:00
data = normalChecks;
2025-10-03 15:40:53 -07:00
}
const theme = useTheme();
return (
<Stack
direction="row"
flexWrap="nowrap"
gap={theme.spacing(1.5)}
height="50px"
width="fit-content"
onClick={(event) => event.stopPropagation()}
sx={{
cursor: "default",
}}
>
{data.map((check, index) => {
if (check === "placeholder") {
return (
<Box
key={`${check}-${index}`}
position="relative"
width={theme.spacing(4.5)}
height="100%"
bgcolor={theme.palette.primary.lowContrast}
sx={{
borderRadius: theme.spacing(1.5),
}}
/>
);
} else {
return (
2025-10-06 10:56:29 -07:00
<HistogramResponseTimeTooltip
2025-10-03 15:40:53 -07:00
key={`${check}-${index}`}
2025-10-06 10:56:29 -07:00
check={check}
2025-10-03 15:40:53 -07:00
>
<Box
2025-10-06 10:56:29 -07:00
position="relative"
width="9px"
height="100%"
bgcolor={theme.palette.primary.lowContrast}
2025-10-03 15:40:53 -07:00
sx={{
borderRadius: theme.spacing(1.5),
}}
2025-10-06 10:56:29 -07:00
>
<Box
position="absolute"
bottom={0}
width="100%"
2025-10-09 13:53:34 -07:00
height={`${check.normalResponseTime}%`}
2025-10-06 10:56:29 -07:00
bgcolor={
check.status
? theme.palette.success.lowContrast
: theme.palette.error.lowContrast
}
sx={{
borderRadius: theme.spacing(1.5),
transition: "height 600ms cubic-bezier(0.4, 0, 0.2, 1)",
}}
/>
</Box>
</HistogramResponseTimeTooltip>
2025-10-03 15:40:53 -07:00
);
}
})}
</Stack>
);
};