diff --git a/client/src/Pages/Dashboard/Components/Cards/CheckmateServerCard.tsx b/client/src/Pages/Dashboard/Components/Cards/CheckmateServerCard.tsx index 2d8c11cbd..d4fd4bc58 100644 --- a/client/src/Pages/Dashboard/Components/Cards/CheckmateServerCard.tsx +++ b/client/src/Pages/Dashboard/Components/Cards/CheckmateServerCard.tsx @@ -60,7 +60,7 @@ const MetricLine = ({ export const CheckmateServerCard = () => { const theme = useTheme(); const { t } = useTranslation(); - const { data, isLoading, error } = useGet( + const { data, isLoading, isValidating, error } = useGet( "/diagnostic/system", {}, { refreshInterval: 30000 } @@ -86,6 +86,7 @@ export const CheckmateServerCard = () => { to="/logs" isLoading={isLoading && !data} error={error} + isStale={isValidating && Boolean(data)} > {data && ( diff --git a/client/src/Pages/Dashboard/Components/Cards/CurrentlyDownCard.tsx b/client/src/Pages/Dashboard/Components/Cards/CurrentlyDownCard.tsx index 40f995327..1974a056d 100644 --- a/client/src/Pages/Dashboard/Components/Cards/CurrentlyDownCard.tsx +++ b/client/src/Pages/Dashboard/Components/Cards/CurrentlyDownCard.tsx @@ -5,10 +5,11 @@ import { useTheme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import { useMemo } from "react"; -import { Dot, StatusCodeLabel } from "@/Components/design-elements"; +import { Dot } from "@/Components/design-elements"; import { LAYOUT } from "@/Utils/Theme/constants"; import { typographyLevels } from "@/Utils/Theme/Palette"; import { getStatusColor, getMonitorPath } from "@/Utils/MonitorUtils"; +import { formatStatusCode } from "@/Utils/statusCode"; import { formatDuration } from "@/Utils/TimeUtils"; import { DashboardCard, CardMessage } from "../DashboardCard"; import { CardRow, CardRowLabel } from "../CardPrimitives"; @@ -19,34 +20,45 @@ import type { Monitor, MonitorStatus } from "@/Types/Monitor"; // Ordering, not a severity scale — Checkmate has none. Every input already // exists in the API response. +// +// `initializing` is deliberately excluded: on a fresh install every new monitor +// starts there, and counting it would open the card red claiming a fleet-wide +// outage that does not exist. It is "not checked yet", not "broken". const STATUS_RANK: Partial> = { down: 1, breached: 2, - initializing: 3, }; const isProblem = (monitor: Monitor) => STATUS_RANK[monitor.status] !== undefined; /** * How long the monitor has been in its current state, inferred from the oldest - * consecutive failing check. recentChecks is newest-first. + * consecutive failing check. + * + * recentChecks is oldest-first — the server appends each snapshot with + * `$push … $slice: -N` — so the run of current failures is walked backwards + * from the end. */ const downSince = (monitor: Monitor): string | null => { const checks = monitor.recentChecks ?? []; let oldestFailing: string | null = null; - for (const check of checks) { - if (check.status === true) { + for (let index = checks.length - 1; index >= 0; index -= 1) { + if (checks[index].status === true) { break; } - oldestFailing = check.createdAt; + oldestFailing = checks[index].createdAt; } return oldestFailing; }; +/** The newest retained check — recentChecks is oldest-first. */ +const latestCheck = (monitor: Monitor) => + monitor.recentChecks?.[monitor.recentChecks.length - 1]; + export const CurrentlyDownCard = () => { const theme = useTheme(); const { t } = useTranslation(); - const { data, isLoading, error } = useMonitors(); + const { data, isLoading, isValidating, error } = useMonitors(); const problems = useMemo(() => { const monitors = data?.monitors ?? []; @@ -70,6 +82,7 @@ export const CurrentlyDownCard = () => { to="/incidents" isLoading={isLoading && !data} error={error} + isStale={isValidating && Boolean(data)} action={ problems.length > 0 ? ( { color={theme.palette.error.main} /> - - - + {/* + * Plain text rather than StatusCodeLabel: that component wraps + * its body in a Tooltip, and a focusable element nested inside + * the row's link is unreachable by keyboard — tabbing lands on + * the link and activating it navigates away. + */} + + {formatStatusCode(latestCheck(monitor)?.statusCode, t)} + ))} diff --git a/client/src/Pages/Dashboard/Components/Cards/FailedChecksCard.tsx b/client/src/Pages/Dashboard/Components/Cards/FailedChecksCard.tsx index 4abec8ad5..7b51ce317 100644 --- a/client/src/Pages/Dashboard/Components/Cards/FailedChecksCard.tsx +++ b/client/src/Pages/Dashboard/Components/Cards/FailedChecksCard.tsx @@ -16,7 +16,7 @@ const SUMMARY_URL = "/checks/team/summary?dateRange=day"; export const FailedChecksCard = () => { const theme = useTheme(); const { t } = useTranslation(); - const { data, isLoading, error } = useGet(SUMMARY_URL); + const { data, isLoading, isValidating, error } = useGet(SUMMARY_URL); const total = data?.totalChecks ?? 0; const failed = data?.downChecks ?? 0; @@ -29,6 +29,7 @@ export const FailedChecksCard = () => { to="/checks" isLoading={isLoading && !data} error={error} + isStale={isValidating && Boolean(data)} > {total === 0 ? ( diff --git a/client/src/Pages/Dashboard/Components/Cards/MonitorStatusCard.tsx b/client/src/Pages/Dashboard/Components/Cards/MonitorStatusCard.tsx index 439862451..8c02f9df0 100644 --- a/client/src/Pages/Dashboard/Components/Cards/MonitorStatusCard.tsx +++ b/client/src/Pages/Dashboard/Components/Cards/MonitorStatusCard.tsx @@ -13,12 +13,14 @@ import { useMonitors } from "../../useDashboardData"; import type { MonitorStatus, MonitorsSummary } from "@/Types/Monitor"; -// The five counts, in the order they read: healthy first, then what is wrong, -// then what is not being checked. +// Every state the summary reports, in the order they read: healthy first, then +// what is wrong, then what is not being checked. All six are listed so the +// tiles always sum to totalMonitors — omitting one leaves an unexplained gap. const COUNTS: { key: string; status: MonitorStatus; field: keyof MonitorsSummary }[] = [ { key: "up", status: "up", field: "upMonitors" }, { key: "down", status: "down", field: "downMonitors" }, { key: "breached", status: "breached", field: "breachedMonitors" }, + { key: "maintenance", status: "maintenance", field: "maintenanceMonitors" }, { key: "paused", status: "paused", field: "pausedMonitors" }, { key: "initializing", status: "initializing", field: "initializingMonitors" }, ]; @@ -26,7 +28,7 @@ const COUNTS: { key: string; status: MonitorStatus; field: keyof MonitorsSummary export const MonitorStatusCard = () => { const theme = useTheme(); const { t } = useTranslation(); - const { data, isLoading, error } = useMonitors(); + const { data, isLoading, isValidating, error } = useMonitors(); const summary = data?.summary ?? null; return ( @@ -35,6 +37,7 @@ export const MonitorStatusCard = () => { to="/uptime" isLoading={isLoading && !summary} error={error} + isStale={isValidating && Boolean(data)} > {!summary || summary.totalMonitors === 0 ? ( @@ -48,7 +51,10 @@ export const MonitorStatusCard = () => { { const theme = useTheme(); const { t } = useTranslation(); - const { data, isLoading, error } = useMonitors(); + const { data, isLoading, isValidating, error } = useMonitors(); const buckets = useMemo(() => { const byType = new Map(); @@ -50,6 +50,7 @@ export const MonitorsByTypeCard = () => { to="/uptime" isLoading={isLoading && !data} error={error} + isStale={isValidating && Boolean(data)} > {buckets.length === 0 ? ( diff --git a/client/src/Pages/Dashboard/Components/Cards/RecentIncidentsCard.tsx b/client/src/Pages/Dashboard/Components/Cards/RecentIncidentsCard.tsx index 0ad22443a..c1ebf1b2a 100644 --- a/client/src/Pages/Dashboard/Components/Cards/RecentIncidentsCard.tsx +++ b/client/src/Pages/Dashboard/Components/Cards/RecentIncidentsCard.tsx @@ -28,7 +28,9 @@ const incidentDuration = (incident: IncidentSummaryItem): string | null => { export const RecentIncidentsCard = () => { const theme = useTheme(); const { t } = useTranslation(); - const { data, isLoading, error } = useGet("/incidents/team/summary"); + const { data, isLoading, isValidating, error } = useGet( + "/incidents/team/summary" + ); const incidents = (data?.latestIncidents ?? []).slice(0, MAX_ROWS); @@ -38,6 +40,7 @@ export const RecentIncidentsCard = () => { to="/incidents" isLoading={isLoading && !data} error={error} + isStale={isValidating && Boolean(data)} action={ data && data.totalActive > 0 ? ( { const values = checks .map((check) => check.responseTime) - .filter((value): value is number => typeof value === "number") - .reverse(); + .filter((value): value is number => typeof value === "number"); if (values.length < 2) { return null; diff --git a/client/src/Pages/Dashboard/useCardSelection.ts b/client/src/Pages/Dashboard/useCardSelection.ts index 267aa42c7..a3db5310b 100644 --- a/client/src/Pages/Dashboard/useCardSelection.ts +++ b/client/src/Pages/Dashboard/useCardSelection.ts @@ -26,8 +26,11 @@ const readStored = (): CardId[] | null => { if (!Array.isArray(parsed)) { return null; } - const valid = parsed.filter(isCardId); - return valid.length > 0 ? valid : null; + // An empty array is a real choice — a dashboard the user emptied — and + // must not fall back to the defaults. Only an absent or malformed key + // returns null. Unknown ids are dropped so a card removed in a later + // release cannot break the page. + return parsed.filter(isCardId); } catch (error) { logger.error( "Could not read dashboard card selection", diff --git a/client/src/Pages/Dashboard/useDashboardData.ts b/client/src/Pages/Dashboard/useDashboardData.ts index ca25b16b8..b6136b3d6 100644 --- a/client/src/Pages/Dashboard/useDashboardData.ts +++ b/client/src/Pages/Dashboard/useDashboardData.ts @@ -1,21 +1,20 @@ import { createContext, useContext } from "react"; import { useGet } from "@/Hooks/UseApi"; -import { - MAX_RECENT_CHECKS, - MonitorTypes, - type MonitorsWithChecksResponse, -} from "@/Types/Monitor"; +import { MonitorTypes, type MonitorsWithChecksResponse } from "@/Types/Monitor"; const REFRESH_INTERVAL = 30000; // One request feeds every monitor-derived card. Cards read it from context so // adding a monitor card costs no extra call. +// +// No rowsPerPage: the repository treats 0 as "no limit", so every monitor comes +// back. The dashboard summarises the whole fleet, it never pages. `limit` is +// deliberately not sent — findByTeamIdWithStats derives its page size from +// rowsPerPage alone and never reads it, so passing it would only imply a +// recent-check truncation that is not actually in effect. const buildMonitorsUrl = () => { const params = new URLSearchParams(); MonitorTypes.forEach((type) => params.append("type", type)); - // No rowsPerPage: the repository treats 0 as "no limit", so every monitor - // comes back. The dashboard summarises the whole fleet, it never pages. - params.append("limit", String(MAX_RECENT_CHECKS)); return `/monitors/team/with-checks?${params.toString()}`; };