Code review of the dashboard branch. Four correctness bugs, one shared
helper, and the comment density brought down.
Correctness:
- CurrentlyDownCard: downSince() broke its backwards walk only on
`status === true`, so a check with an undefined status kept the run
going and reported a downtime reaching back to the start of the
retained window. Break on `status !== false` instead, matching what
the doc comment already claimed.
- RankingCards: the lowest-uptime card barred the uptime percentage
itself, so the worst monitor drew the shortest bar - a chart that read
as "best uptime" directly against its own title and sort order. Bar
the shortfall instead.
- useCardTransitions: the FLIP rAF and its nested 260ms timeout were
never cancelled. Navigating away mid-animation wrote styles to
unmounted nodes, and a second move while the first was settling had
its inversion wiped by the earlier timeout, so the card jumped rather
than travelled. Handles are now tracked and cancelled on unmount and
at the start of each move.
- BreakdownCard: the bar scale took buckets[0].total, silently assuming
the caller sorted descending. Compute the max instead - both callers
do sort today, but nothing in the signature said they had to.
Redundancy:
- "newest check is the last element of recentChecks" was implemented
twice with its own copy of the explanation. Now one `latestCheck`
helper in checks.ts. RankingCards averages over all checks, which is
a different operation, and is left alone.
- DEFAULT_CARD_IDS is `readonly` and copied into state rather than
assigned by reference.
Comments and conventions:
- 283 comment lines down to ~220. Design rationale ("two lines rather
than one wide row", "the header controls stay invisible until...")
is gone; comments recording non-obvious API facts - recentChecks is
oldest-first, snake_case here but camelCase there, credential fields
must not reach the DOM - are kept and shortened.
- DashboardCard: display/flexDirection/height hoisted out of sx to
native props (frontend rule 1). A stale comment claiming a "34px
control height" is corrected; the codebase settled on 32.
Gates: tsc clean, build passes, format-check clean, lint unchanged from
develop (12 errors, all pre-existing in untouched files).
85 lines
2.5 KiB
TypeScript
85 lines
2.5 KiB
TypeScript
import type { ComponentType } from "react";
|
|
|
|
// The 12-column grid the dashboard lays cards out on.
|
|
//
|
|
// Every card is currently half-width, so they pair up down the page and the
|
|
// grid reads as one system. Full width stays in the type for a card whose
|
|
// content genuinely needs it. Width is declared per card type in code and is
|
|
// never a user setting.
|
|
export const CardWidths = [6, 12] as const;
|
|
export type CardWidth = (typeof CardWidths)[number];
|
|
|
|
export const GRID_COLUMNS = 12;
|
|
|
|
// Picker groups mirror the sidebar sections: you look for a card where you
|
|
// look for the feature it belongs to.
|
|
export const CardGroups = [
|
|
"uptime",
|
|
"infrastructure",
|
|
"incidents",
|
|
"notifications",
|
|
"maintenance",
|
|
"statusPages",
|
|
"checks",
|
|
"logs",
|
|
"settings",
|
|
] as const;
|
|
export type CardGroup = (typeof CardGroups)[number];
|
|
|
|
// The Containers card (CARD-SPECS.md #11) is deliberately absent: it needs
|
|
// `containerSummary` on the check snapshot, which arrives with the Docker
|
|
// monitoring work. Add it here once that lands on develop.
|
|
export const CardIds = [
|
|
"monitorStatus",
|
|
"currentlyDown",
|
|
"slowestMonitors",
|
|
"lowestUptime",
|
|
"monitorsByType",
|
|
"monitorsByGroup",
|
|
"recentIncidents",
|
|
"incidentStats",
|
|
"notificationChannels",
|
|
"maintenance",
|
|
"statusPages",
|
|
"failedChecks",
|
|
"busiestServers",
|
|
"checkmateServer",
|
|
"checksOnSchedule",
|
|
"recentErrors",
|
|
"team",
|
|
] as const;
|
|
export type CardId = (typeof CardIds)[number];
|
|
|
|
export interface CardDefinition {
|
|
id: CardId;
|
|
/** i18n key fragment under pages.dashboard.cards.<key>. */
|
|
key: string;
|
|
group: CardGroup;
|
|
width: CardWidth;
|
|
/** Hidden from the page and absent from the picker for non-admins. */
|
|
adminOnly?: boolean;
|
|
component: ComponentType;
|
|
}
|
|
|
|
// The cards a fresh dashboard starts with. Chosen so a brand new install still
|
|
// shows something real: Checkmate server works with zero monitors.
|
|
// Ordered so the declared widths pair into full rows: a card left alone in a
|
|
// row is stretched to fill it, so 8- and 4-wide cards are kept adjacent.
|
|
export const DEFAULT_CARD_IDS: readonly CardId[] = [
|
|
"monitorStatus",
|
|
"currentlyDown",
|
|
"failedChecks",
|
|
"monitorsByType",
|
|
"recentIncidents",
|
|
"checkmateServer",
|
|
];
|
|
|
|
export const DASHBOARD_CARDS_STORAGE_KEY = "checkmate-dashboard-cards";
|
|
|
|
/**
|
|
* Poll rates, in ms. Monitor and server figures move continuously; the log ring
|
|
* buffer rotates fast but is expensive to re-read, so it is polled slowly.
|
|
*/
|
|
export const REFRESH_INTERVAL_MS = 30000;
|
|
export const SLOW_REFRESH_INTERVAL_MS = 60000;
|