import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import { BaseChart } from "@/components/monitors/Chart";
import { ResponsiveContainer, BarChart, XAxis, Bar, Cell } from "recharts";
import { TrendingUp, AlertTriangle } from "lucide-react";
import type { GroupedCheck } from "@/types/check";
import type { MonitorStatus } from "@/types/monitor";
import { normalizeResponseTimes } from "@/utils/DataUtils";
import { useState } from "react";
import { formatDateWithTz } from "@/utils/TimeUtils";
import { useAppSelector } from "@/hooks/AppHooks";
import { useTheme } from "@mui/material/styles";
import { getResponseTimeColor } from "@/utils/MonitorUtils";
const XLabel = ({
p1,
p2,
range,
}: {
p1: GroupedCheck;
p2: GroupedCheck;
range: string;
}) => {
const theme = useTheme();
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
const dateFormat = range === "day" ? "MMM D, h:mm A" : "MMM D";
return (
<>
{formatDateWithTz(p1._id, dateFormat, uiTimezone)}
{formatDateWithTz(p2._id, dateFormat, uiTimezone)}
>
);
};
export const HistogramStatus = ({
checks,
status,
range,
title,
}: {
checks: GroupedCheck[];
status: MonitorStatus;
range: string;
title: string;
}) => {
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
const icon = status === "up" ? : ;
const theme = useTheme();
const [idx, setIdx] = useState(null);
const dateFormat = range === "1d" || range === "2h" ? "MMM D, h A" : "MMM D";
const normalChecks = normalizeResponseTimes(checks, "avgResponseTime");
if (normalChecks.length === 0) {
return (
{status === "up" ? "No checks yet" : "Great, no downtime yet!"}
);
}
const totalChecks = normalChecks.reduce((count, check) => {
return count + check.count;
}, 0);
return (
Total checks
{idx ? (
{normalChecks?.[idx]?.count}
{formatDateWithTz(
normalChecks?.[idx]?._id,
dateFormat,
uiTimezone
)}
) : (
{totalChecks}
)}
}
/>
{normalChecks?.map((groupedCheck, idx) => {
const fillColor = getResponseTimeColor(
groupedCheck.normalResponseTime
);
return (
| setIdx(idx)}
onMouseLeave={() => setIdx(null)}
key={groupedCheck._id}
fill={theme.palette[fillColor].main}
/>
);
})}
|
);
};