This commit is contained in:
Alex Holliday committed 2025-10-07 14:44:55 -07:00
1 parent 8a1fc94c31
commit 29fbf0a362
11 files changed
+587 -20

No files matched your search

+60 -3
View File
@@ -2,20 +2,25 @@ 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 { HistogramStatus } from "@/Components/v2/Monitors/HistogramStatus";
import { ChartAvgResponse } from "@/Components/v2/Monitors/ChartAvgResponse";
import { useMediaQuery } from "@mui/material";
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";
import { ChartResponseTime } from "@/Components/v2/Monitors/ChartResponseTime";
const UptimeDetailsPage = () => {
const { id } = useParams();
const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
// Local state
const [range, setRange] = useState("30m");
const [range, setRange] = useState("2h");
const { response, loading, error, refetch } = useGet<ApiResponse>(
`/monitors/${id}?embedChecks=true&range=${range}`,
@@ -23,6 +28,27 @@ const UptimeDetailsPage = () => {
{},
{ refreshInterval: 30000 }
);
const {
response: upResponse,
error: upError,
loading: upLoading,
} = useGet<ApiResponse>(
`/monitors/${id}?embedChecks=true&range=${range}&status=up`,
{},
{}
);
const {
response: downResponse,
error: downError,
loading: downLoading,
} = useGet<ApiResponse>(
`/monitors/${id}?embedChecks=true&range=${range}&status=down`,
{},
{}
);
const {
patch,
loading: isPatching,
@@ -35,6 +61,8 @@ const UptimeDetailsPage = () => {
}
const stats = response?.data?.stats || null;
const avgResponseTime = stats?.avgResponseTime || 0;
const maxResponseTime = stats?.maxResponseTime || 0;
const streakDuration = stats?.currentStreakStartedAt
? Date.now() - stats?.currentStreakStartedAt
@@ -44,9 +72,13 @@ const UptimeDetailsPage = () => {
? Date.now() - stats?.lastCheckTimestamp
: -1;
const checks = response?.data?.checks || null;
const checks = response?.data?.checks || [];
const upChecks = upResponse?.data?.checks || [];
const downChecks = downResponse?.data?.checks || [];
console.log(response);
// TODO something with these
console.log(loading, error, postError, checks, setRange);
const palette = getStatusPalette(monitor.status);
@@ -80,6 +112,31 @@ const UptimeDetailsPage = () => {
subtitle={stats?.lastResponseTime ? `${stats?.lastResponseTime} ms` : "N/A"}
/>
</Stack>
<Stack
direction={isSmall ? "column" : "row"}
gap={theme.spacing(8)}
>
<HistogramStatus
title="Uptime"
status={"up"}
checks={upChecks.reverse()}
range={range}
/>
<HistogramStatus
title="Incidents"
checks={downChecks.reverse()}
status={"down"}
range={range}
/>
<ChartAvgResponse
avg={avgResponseTime}
max={maxResponseTime}
/>
</Stack>
<ChartResponseTime
checks={checks}
range={range}
/>
</BasePage>
);
};