stat boxes

This commit is contained in:
Alex Holliday committed 2025-10-06 15:08:55 -07:00
1 parent abadc99bf1
commit 8a1fc94c31
6 files changed
+129 -3

No files matched your search

+50 -2
View File
@@ -1,17 +1,27 @@
import { BasePage } from "@/Components/v2/DesignElements";
import { HeaderControls } from "@/Components/v2/Monitors/HeaderControls";
import Stack from "@mui/material/Stack";
import { StatBox } from "@/Components/v2/DesignElements";
import { useTheme } from "@mui/material/styles";
import { useParams } from "react-router";
import { useGet, usePatch, type ApiResponse } from "@/Hooks/v2/UseApi";
import { useState } from "react";
import { getStatusPalette } from "@/Utils/MonitorUtils";
import prettyMilliseconds from "pretty-ms";
const UptimeDetailsPage = () => {
const { id } = useParams();
const theme = useTheme();
// Local state
const [range, setRange] = useState("30m");
const { response, loading, error, refetch } = useGet<ApiResponse>(
`/monitors/${id}?range=${range}`
`/monitors/${id}?embedChecks=true&range=${range}`,
{},
{ refreshInterval: 30000 }
);
const {
patch,
@@ -19,11 +29,27 @@ const UptimeDetailsPage = () => {
error: postError,
} = usePatch<ApiResponse>(`/monitors/${id}/active`);
const monitor = response?.data || null;
const monitor = response?.data?.monitor || null;
if (!monitor) {
return null;
}
const stats = response?.data?.stats || null;
const streakDuration = stats?.currentStreakStartedAt
? Date.now() - stats?.currentStreakStartedAt
: 0;
const lastChecked = stats?.lastCheckTimestamp
? Date.now() - stats?.lastCheckTimestamp
: -1;
const checks = response?.data?.checks || null;
console.log(response);
const palette = getStatusPalette(monitor.status);
return (
<BasePage>
<HeaderControls
@@ -32,6 +58,28 @@ const UptimeDetailsPage = () => {
isPatching={isPatching}
refetch={refetch}
/>
<Stack
direction="row"
gap={theme.spacing(8)}
>
<StatBox
palette={palette}
title="Active for"
subtitle={prettyMilliseconds(streakDuration, { secondsDecimalDigits: 0 })}
/>
<StatBox
title="Last check"
subtitle={
lastChecked >= 0
? `${prettyMilliseconds(lastChecked, { secondsDecimalDigits: 0 })} ago`
: "N/A"
}
/>
<StatBox
title="Last response time"
subtitle={stats?.lastResponseTime ? `${stats?.lastResponseTime} ms` : "N/A"}
/>
</Stack>
</BasePage>
);
};
@@ -18,7 +18,7 @@ const UptimeMonitors = () => {
const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
const { response, loading } = useGet<ApiResponse>("/monitors?embedChecks=true");
const { response, loading } = useGet<ApiResponse>("/monitors?embedChecks=true", {});
const monitors = response?.data ?? ([] as IMonitor[]);
if (monitors.length === 0 && !loading) {