diff --git a/client/src/Pages/Dashboard/Components/CardPrimitives.tsx b/client/src/Pages/Dashboard/Components/CardPrimitives.tsx index 71c0d59ab..497d91ec3 100644 --- a/client/src/Pages/Dashboard/Components/CardPrimitives.tsx +++ b/client/src/Pages/Dashboard/Components/CardPrimitives.tsx @@ -4,6 +4,7 @@ import Typography from "@mui/material/Typography"; import { useTheme } from "@mui/material/styles"; import { Link as RouterLink } from "react-router-dom"; +import { Tooltip } from "@/Components/design-elements"; import { LAYOUT } from "@/Utils/Theme/constants"; import { typographyLevels } from "@/Utils/Theme/Palette"; @@ -11,6 +12,16 @@ import type { ReactNode } from "react"; /** Thin enough to read as a proportion indicator, not a progress bar. */ const BAR_HEIGHT = 4; +/** The segmented bar carries more meaning, so it gets a little more presence. */ +const SEGMENTED_BAR_HEIGHT = 8; + +export interface BarSegment { + key: string; + value: number; + color: string; + /** Tooltip text, since the segments themselves carry no labels. */ + label: string; +} /** * A proportional bar. `value` and `max` share whatever unit the caller uses; @@ -46,6 +57,46 @@ export const CardBar = ({ ); }; +/** + * One bar divided into proportional segments — the shape of a whole split into + * parts, where the relative sizes are the point rather than any single value. + * + * Zero-value segments are dropped so they cannot appear as hairlines, and each + * segment carries a tooltip because the bar itself has no room for labels. + */ +export const CardSegmentedBar = ({ segments }: { segments: BarSegment[] }) => { + const theme = useTheme(); + const visible = segments.filter((segment) => segment.value > 0); + const total = visible.reduce((sum, segment) => sum + segment.value, 0); + + return ( + + {total > 0 && + visible.map((segment) => ( + + + + ))} + + ); +}; + /** A clickable list row. Rows link to the entity they describe. */ export const CardRow = ({ to, children }: { to?: string; children: ReactNode }) => { const theme = useTheme(); diff --git a/client/src/Pages/Dashboard/Components/Cards/MonitorStatusCard.tsx b/client/src/Pages/Dashboard/Components/Cards/MonitorStatusCard.tsx index 7a0997e2a..20994eacd 100644 --- a/client/src/Pages/Dashboard/Components/Cards/MonitorStatusCard.tsx +++ b/client/src/Pages/Dashboard/Components/Cards/MonitorStatusCard.tsx @@ -9,23 +9,20 @@ import { LAYOUT } from "@/Utils/Theme/constants"; import { typographyLevels } from "@/Utils/Theme/Palette"; import { getStatusColor } from "@/Utils/MonitorUtils"; import { DashboardCard, CardMessage } from "../DashboardCard"; +import { CardSegmentedBar, type BarSegment } from "../CardPrimitives"; import { useMonitors } from "../../useDashboardData"; import type { MonitorStatus, MonitorsSummary } from "@/Types/Monitor"; -// Wide enough for a three-digit count beside its label before the tiles wrap. -const TILE_MIN_WIDTH = 96; - -// 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" }, +// Every state the summary reports, ordered worst first so the bar reads +// problems-to-healthy left to right and the chips below list what is wrong +// before what is merely idle. `up` is handled separately as the headline. +const STATES: { key: string; status: MonitorStatus; field: keyof MonitorsSummary }[] = [ { key: "down", status: "down", field: "downMonitors" }, { key: "breached", status: "breached", field: "breachedMonitors" }, + { key: "initializing", status: "initializing", field: "initializingMonitors" }, { key: "maintenance", status: "maintenance", field: "maintenanceMonitors" }, { key: "paused", status: "paused", field: "pausedMonitors" }, - { key: "initializing", status: "initializing", field: "initializingMonitors" }, ]; export const MonitorStatusCard = () => { @@ -34,6 +31,32 @@ export const MonitorStatusCard = () => { const { data, isLoading, isValidating, error } = useMonitors(); const summary = data?.summary ?? null; + // Only states that actually have monitors are shown. Padding the card with + // zeros says nothing, and a healthy fleet should read as calm rather than as + // a row of empty counters. + const present = summary + ? STATES.map((state) => ({ ...state, count: summary[state.field] })).filter( + (state) => state.count > 0 + ) + : []; + + const segments: BarSegment[] = summary + ? [ + { + key: "up", + value: summary.upMonitors, + color: getStatusColor("up", theme), + label: `${t("pages.common.monitors.status.up")} — ${summary.upMonitors}`, + }, + ...present.map((state) => ({ + key: state.key, + value: state.count, + color: getStatusColor(state.status, theme), + label: `${t(`pages.common.monitors.status.${state.key}`)} — ${state.count}`, + })), + ] + : []; + return ( { {!summary || summary.totalMonitors === 0 ? ( ) : ( - - {COUNTS.map(({ key, status, field }) => ( + + - - - - {t(`pages.common.monitors.status.${key}`)} - - - {summary[field]} + {summary.upMonitors} + + + {t("pages.dashboard.cards.monitorStatus.upOfTotal", { + total: summary.totalMonitors, + })} - ))} + + + {present.length > 0 && ( + + {present.map((state) => ( + + + + {t(`pages.common.monitors.status.${state.key}`)} + + + {state.count} + + + ))} + + )} )} diff --git a/client/src/Pages/Dashboard/Components/Cards/SummaryCards.tsx b/client/src/Pages/Dashboard/Components/Cards/SummaryCards.tsx index f627ea122..edf6aefec 100644 --- a/client/src/Pages/Dashboard/Components/Cards/SummaryCards.tsx +++ b/client/src/Pages/Dashboard/Components/Cards/SummaryCards.tsx @@ -10,7 +10,13 @@ import { LAYOUT } from "@/Utils/Theme/constants"; import { typographyLevels } from "@/Utils/Theme/Palette"; import { formatTimestamp } from "@/Utils/TimeUtils"; import { DashboardCard, CardMessage } from "../DashboardCard"; -import { CardFigure, CardRow, CardRowLabel, CardStatLine } from "../CardPrimitives"; +import { + CardFigure, + CardRow, + CardRowLabel, + CardSegmentedBar, + CardStatLine, +} from "../CardPrimitives"; import type { IncidentSummary } from "@/Types/Incident"; import type { Notification } from "@/Types/Notification"; @@ -34,26 +40,71 @@ export const IncidentStatsCard = () => { isStale={isValidating && Boolean(data)} > {data && ( - - 0 ? theme.palette.error.main : theme.palette.text.primary - } - /> - - {data.topMonitor?.monitorName && ( - + {/* Open now leads, paired with the all-time total for context: two + open means something different against 12 incidents than 183. */} + + 0 + ? theme.palette.error.main + : theme.palette.success.main + } /> + + + {/* How much of the fleet heals itself — the automatic/manual split + is already computed server-side and said nothing on the card + before. A high manual share means people are doing the work. */} + {data.totalAutomaticResolutions + data.totalManualResolutions > 0 && ( + + + + )} + + + {data.topMonitor?.monitorName && ( + + )} + )} diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 2c3967e2e..d8c817b4e 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -257,7 +257,8 @@ "cards": { "monitorStatus": { "title": "Monitor status", - "empty": "No monitors yet." + "empty": "No monitors yet.", + "upOfTotal": "of {{total}} up" }, "currentlyDown": { "title": "Currently down", @@ -316,7 +317,12 @@ "openNow": "Open now", "avgResolution": "Average time to resolve", "hours": "{{hours}} h", - "mostIncidents": "Most incidents" + "mostIncidents": "Most incidents", + "total": "total", + "resolved": "Resolved", + "automatic": "Automatic", + "manual": "Manual", + "autoManual": "{{automatic}} automatic · {{manual}} manual" }, "notificationChannels": { "title": "Notification channels",