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