import Tooltip from "@mui/material/Tooltip"; import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; import type { SxProps, Theme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import type { CheckSnapshot } from "@/Types/Check"; import { formatDateWithTz } from "@/Utils/TimeUtils"; import { MAX_RECENT_CHECKS } from "@/Types/Monitor"; import { useStatusPageTheme } from "../StatusPageThemeProvider"; const CELLS = MAX_RECENT_CHECKS; export type HeatCellKind = "fast" | "med" | "slow" | "down" | "empty"; interface Props { checks: CheckSnapshot[]; containerSx: SxProps; cellSx: (kind: HeatCellKind) => SxProps; } const classify = (check: CheckSnapshot): Exclude => { 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(); const { timezone } = useStatusPageTheme(); const source = checks.slice(-CELLS); const padded: (CheckSnapshot | null)[] = [ ...source, ...Array.from({ length: Math.max(0, CELLS - source.length) }, () => null), ]; return ( {padded.map((check, i) => { if (!check) { return ( ); } const kind = classify(check); const tooltipContent = ( {check.status ? `${check.responseTime} ms` : t("pages.statusPages.monitorsList.chart.downTooltip")} {formatDateWithTz(check.createdAt, "ddd, MMMM D, YYYY, HH:mm A", timezone)} ); return ( ); })} ); };