Files
Checkmate/client/src/Components/common/charts/HeatmapResponseTimeTooltip.tsx
T

77 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-01-23 23:54:58 +00:00
import Stack from "@mui/material/Stack";
import Tooltip from "@mui/material/Tooltip";
import Typography from "@mui/material/Typography";
import { formatDateWithTz, formatMs } from "@/Utils/TimeUtils";
2026-01-27 19:23:34 +00:00
import type { CheckSnapshot } from "@/Types/Check";
2026-01-23 23:54:58 +00:00
import { useTheme } from "@mui/material/styles";
import { useSelector } from "react-redux";
import type { RootState } from "@/Types/state";
2026-01-26 23:44:40 +00:00
import { useTranslation } from "react-i18next";
2026-02-03 23:30:23 +00:00
2026-01-27 19:23:34 +00:00
type HeatmapCheck =
| CheckSnapshot
| { status: "placeholder"; responseTime: 0; createdAt: "" };
2026-01-23 23:54:58 +00:00
export const HeatmapResponseTimeTooltip = ({
children,
check,
}: {
children: React.ReactElement;
check: HeatmapCheck;
}) => {
2026-01-26 23:44:40 +00:00
const { t } = useTranslation();
2026-01-23 23:54:58 +00:00
const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
const theme = useTheme();
const getColor = (status: boolean) => {
if (status === true) return theme.palette.success.light;
if (status === false) return theme.palette.error.light;
};
if (check.status === "placeholder") {
return children;
}
return (
<Tooltip
slotProps={{
tooltip: {
sx: {
backgroundColor: "transparent",
color: "inherit",
boxShadow: "none",
},
},
}}
title={
<Stack
sx={{
backgroundColor: theme.palette.secondary.main,
border: 1,
borderColor: theme.palette.divider,
borderRadius: theme.shape.borderRadius,
p: theme.spacing(4),
}}
>
<Typography>
{formatDateWithTz(check?.createdAt, "ddd, MMMM D, YYYY, HH:mm A", uiTimezone)}
</Typography>
2026-02-03 23:30:23 +00:00
<Typography>
{t("common.labels.responseTime")}:{" "}
{check?.responseTime ? formatMs(check.responseTime) : "N/A"}
2026-02-03 23:30:23 +00:00
</Typography>
2026-01-23 23:54:58 +00:00
<Typography textTransform={"capitalize"}>
Status:{" "}
2026-01-26 23:44:40 +00:00
<span style={{ color: getColor(check?.status) }}>
{check?.status === true
? t("pages.common.monitors.status.up")
: t("pages.common.monitors.status.down")}
</span>
2026-01-23 23:54:58 +00:00
</Typography>
</Stack>
}
>
{children}
</Tooltip>
);
};