Files
Checkmate/client/src/components/common/HeatmapResponseTime.tsx
T

102 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-11-25 19:03:48 +00:00
import Box from "@mui/material/Box";
import { useTheme } from "@mui/material/styles";
import type { ICheck } from "@/types/check";
import { getResponseColor } from "@/utils/DataUtils";
2025-11-25 19:56:26 +00:00
import { HeatmapResponseTimeTooltip } from "./HeatmapResponseTimeTooltip";
import type { SxProps } from "@mui/material/styles";
2025-11-25 19:03:48 +00:00
interface HeatmapResponseTimeProps {
checks: ICheck[];
2025-11-25 19:56:26 +00:00
availabilityCellSx?: SxProps;
responseCellSx?: SxProps;
2025-11-25 19:03:48 +00:00
}
2025-11-25 19:56:26 +00:00
export const HeatmapResponseTime = ({
checks,
availabilityCellSx,
responseCellSx,
}: HeatmapResponseTimeProps) => {
2025-11-25 19:03:48 +00:00
const theme = useTheme();
if (!checks || checks.length === 0) return null;
let data = Array<any>();
if (!checks || checks.length === 0) {
checks = [];
}
if (checks.length !== 25) {
const placeholders = Array(25 - checks.length).fill({
status: "placeholder",
});
data = [...checks, ...placeholders];
} else {
data = checks;
}
return (
<Box sx={{ width: "100%" }}>
<Box
sx={{
width: "100%",
display: "grid",
gridTemplateColumns: "repeat(25, 1fr)",
gap: theme.spacing(0.5),
alignItems: "stretch",
}}
>
{data.map((check, index) => {
const statusBg =
check.status === "placeholder"
? theme.palette.primary.lowContrast
: check.status === "up"
? theme.palette.success.lowContrast
: theme.palette.error.lowContrast;
const respBg =
check.status === "placeholder"
? theme.palette.primary.lowContrast
: getResponseColor(check.responseTime, {
start: theme.palette.success.lowContrast,
mid: theme.palette.warning.lowContrast,
end: theme.palette.error.lowContrast,
});
return (
2025-11-25 19:56:26 +00:00
<HeatmapResponseTimeTooltip key={`${check}-${index}`} check={check}>
2025-11-25 19:03:48 +00:00
<Box
sx={{
display: "grid",
gridTemplateRows: "auto auto",
}}
>
<Box
sx={{
2025-11-25 19:56:26 +00:00
display: "flex",
flexDirection: "column",
gap: theme.spacing(2),
2025-11-25 19:03:48 +00:00
}}
2025-11-25 19:56:26 +00:00
>
<Box
sx={{
width: "100%",
aspectRatio: "10",
bgcolor: statusBg,
borderRadius: theme.spacing(0.5),
...availabilityCellSx,
}}
/>
<Box
sx={{
width: "100%",
aspectRatio: "1 / 1",
bgcolor: respBg,
borderRadius: theme.spacing(0.5),
...responseCellSx,
}}
/>
</Box>
2025-11-25 19:03:48 +00:00
</Box>
2025-11-25 19:56:26 +00:00
</HeatmapResponseTimeTooltip>
2025-11-25 19:03:48 +00:00
);
})}
</Box>
</Box>
);
};