Files
Checkmate/client/src/Pages/StatusPage/Status/themes/shared/ThemedHeatmap.tsx
T

70 lines
1.8 KiB
TypeScript
Raw Normal View History

import Tooltip from "@mui/material/Tooltip";
import Box from "@mui/material/Box";
import type { SxProps, Theme } from "@mui/material/styles";
import { useTranslation } from "react-i18next";
import type { CheckSnapshot } from "@/Types/Check";
import { MAX_RECENT_CHECKS } from "@/Types/Monitor";
2026-07-31 11:41:18 -07:00
import { ThemedChartTooltip } from "@/Pages/StatusPage/Status/themes/shared/ThemedChartTooltip";
import { formatMs } from "@/Utils/TimeUtils";
const CELLS = MAX_RECENT_CHECKS;
export type HeatCellKind = "fast" | "med" | "slow" | "down" | "empty";
interface Props {
checks: CheckSnapshot[];
containerSx: SxProps<Theme>;
cellSx: (kind: HeatCellKind) => SxProps<Theme>;
}
const classify = (check: CheckSnapshot): Exclude<HeatCellKind, "empty"> => {
if (!check.status) return "down";
const rt = check.responseTime ?? 0;
if (rt > 500) return "slow";
if (rt > 250) return "med";
return "fast";
};
export const ThemedHeatmap = ({ checks, containerSx, cellSx }: Props) => {
const { t } = useTranslation();
2026-04-29 12:03:23 -07:00
const source = checks.slice(-CELLS);
const padded: (CheckSnapshot | null)[] = [
...source,
2026-04-29 12:03:23 -07:00
...Array.from({ length: Math.max(0, CELLS - source.length) }, () => null),
];
return (
<Box
sx={containerSx}
role="img"
aria-label={t("pages.statusPages.monitorsList.chart.heatmapAria")}
>
{padded.map((check, i) => {
if (!check) {
return (
<Box
key={`empty-${i}`}
sx={cellSx("empty")}
/>
);
}
const kind = classify(check);
2026-07-31 11:41:18 -07:00
const tooltipContent = <ThemedChartTooltip check={check} />;
return (
<Tooltip
key={check.id ?? i}
title={tooltipContent}
arrow
placement="top"
>
<Box
sx={cellSx(kind)}
aria-label={`${formatMs(check.responseTime)}, ${check.status ? "up" : "down"}`}
/>
</Tooltip>
);
})}
</Box>
);
};