From b5384c1e0369d0d45e758d9c473d455adfdc0f8f Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Sun, 18 Oct 2026 22:00:19 +0200 Subject: [PATCH] Dashboard status banner, phone-friendly lists, and more command palette actions - Dashboard: a banner that answers "is it fine?" (headline, root cause, kinds of problem, worst few); cards with a problem come first in their row - Phone: Alerts, Updates and Inventory rows become compact cards, finger-sized buttons, Alerts drops its figure row; scanned inventory labels get an Edit button - Command palette: acknowledge alerts, update a server, print a label, open hardware, "What depends on ...?" Co-Authored-By: Claude Sonnet 5.5 --- README.md | 14 ++- web/src/components/CommandPalette.tsx | 76 +++++++++++++- web/src/components/DependencyMap.tsx | 6 +- web/src/components/StatusStrip.tsx | 145 ++++++++++++++------------ web/src/pages/Alerts.tsx | 37 +++---- web/src/pages/Dashboard.tsx | 23 +++- web/src/pages/Inventory.tsx | 29 ++++-- web/src/pages/InventoryLabels.tsx | 8 +- web/src/pages/Updates.tsx | 32 ++++-- web/src/styles.css | 103 ++++++++++++++++++ web/src/utils/alertSummary.ts | 36 +++++++ web/src/utils/problemsFirst.ts | 38 +++++++ 12 files changed, 429 insertions(+), 118 deletions(-) create mode 100644 web/src/utils/alertSummary.ts create mode 100644 web/src/utils/problemsFirst.ts diff --git a/README.md b/README.md index 7ba7624..2567628 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,10 @@ All modules from the original plan are built: - Authentik OIDC login, roles (first user to sign in becomes admin), audit log (changes made in the app, sign-ins and sign-outs with the IP they came from, new accounts, and the log's own automatic trimming — attributed to "system"; settings changes show what changed, but never credentials) -- **Dashboard** — an overview of every system this app tracks, all sharing +- **Dashboard** — opens with a status banner that answers "is it fine?": one sentence ("All clear", "3 things need attention"), the root cause when one + problem explains others, which kinds of thing are wrong (each links to those alerts) and the worst few. Below it, a card whose status badge is red or yellow + comes first in its row, with a coloured top edge (switchable under Customise, remembered in that browser; your own arrangement is untouched underneath). + The rest is an overview of every system this app tracks, all sharing one widget-card design (label + status badge, a small stat row, then its own breakdown): DNS (domain/record counts per provider, cached records by type), Secrets (monitored/expiring/expired, by type), and one widget per @@ -379,12 +382,17 @@ button at the foot of the sidebar — or the `[` key — narrows it to a strip of icons for more room on a laptop screen: a group's pages then open in a small menu beside its icon, the alert and maintenance counts stay visible, and your choice is remembered in that browser. On a phone -the sidebar is the same slide-out menu as ever. +the sidebar is the same slide-out menu as ever, and the pages people reach from a notification or a printed label are made for one hand: on Alerts, +Updates and Inventory each row becomes a compact card (worst first, with its buttons underneath), the buttons are finger-sized, the +acknowledge panel fills the screen, and the Alerts page leaves out its row of figures — the headline already says them. Scanning an +inventory label opens that piece of hardware at the top of the page, with an Edit button for operators. **Getting around.** Ctrl/Cmd+K opens a search that also runs actions: go to any page, switch light/dark or the density, start (or end) a maintenance window on a server, integration or DNS provider ("silence elsa"), open the wall display, -sign out. "g" then a letter goes to a page (`g d` dashboard, `g a` alerts, +sign out. It also does the things you do most often: **acknowledge** one of the worst alerts nobody is on (for 4 hours, handed to you) or all of them +at once, **update** a server that has updates waiting (it opens the update panel, which still asks before anything runs), **print the label** for a piece of +hardware or open it in the inventory, and ask **"What depends on …?"** of a server or service (it opens the dependency map with that box picked). "g" then a letter goes to a page (`g d` dashboard, `g a` alerts, `g s` servers, `g m` maintenance, `g i` integrations, `g k` secrets, `g p` map, `g w` wall display), "/" jumps to the page's table search, and "?" lists them all, and "j" / "k" move down and up the rows of a table that opens a panel (Enter diff --git a/web/src/components/CommandPalette.tsx b/web/src/components/CommandPalette.tsx index fd45da5..07193fb 100644 --- a/web/src/components/CommandPalette.tsx +++ b/web/src/components/CommandPalette.tsx @@ -3,6 +3,8 @@ import { useLocation, useNavigate } from "react-router-dom"; import { IconSearch } from "@tabler/icons-react"; import { api, + type AlertItem, + type Asset, type CurrentUser, type DnsProviderType, type IntegrationType, @@ -11,6 +13,7 @@ import { type MaintenanceWindow, type SearchResponse, type SecretType, + type UpdatesServer, } from "../api/client"; import { isCurrent, isGroup, visibleNav, type NavLeaf } from "../layout/nav"; import { toggleFavorite, useFavorites } from "../utils/favorites"; @@ -159,6 +162,10 @@ export default function CommandPalette({ const [activeIndex, setActiveIndex] = useState(0); const [targets, setTargets] = useState(null); const [windows, setWindows] = useState([]); + // What the actions below are offered for, read each time the palette opens. + const [alertsToAck, setAlertsToAck] = useState([]); + const [updatable, setUpdatable] = useState([]); + const [assets, setAssets] = useState([]); const inputRef = useRef(null); const opener = useRef(null); const navigate = useNavigate(); @@ -200,6 +207,21 @@ export default function CommandPalette({ setWindows(res.windows); }) .catch(() => {}); + if (canAct) { + api.alerts + .list(false) + .then((res) => setAlertsToAck(res.alerts.filter((a) => !a.silenced && a.severity !== "info" && !a.ack?.active).sort((a, b) => Number(b.severity === "critical") - Number(a.severity === "critical")))) + .catch(() => setAlertsToAck([])); + api.servers + .updates() + .then((res) => setUpdatable(res.servers.filter((s) => (s.updates?.count ?? 0) > 0))) + .catch(() => setUpdatable([])); + } + api.inventory + .list() + .then((res) => setAssets(res.assets)) + .catch(() => setAssets([])); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [open]); // The commands: pages to go to, and things to do. @@ -248,6 +270,56 @@ export default function CommandPalette({ }, keywords: "refresh reload alerts", }); + // Quick acknowledgements: the worst few alerts nobody is on, and all of them at once. + if (canAct && alertsToAck.length > 0) { + const ack = async (list: AlertItem[]) => { + try { + await Promise.all(list.map((a) => api.alerts.ack({ alertId: a.id, note: "Acknowledged from the command palette", assigneeId: user.id, hours: 4 }))); + toast.success(list.length === 1 ? "Acknowledged for 4 hours, handed to you. Change that on the Alerts page." : `Acknowledged ${list.length} alerts for 4 hours, handed to you.`); + window.dispatchEvent(new Event("maintenance-changed")); + } catch (err) { + toast.error(readableError(err)); + } + }; + for (const a of alertsToAck.slice(0, 5)) { + items.push({ key: `ack-${a.id}`, category: "Alerts", title: `Acknowledge: ${a.message}`, subtitle: `${a.severity} · for 4 hours, handed to you`, run: () => ack([a]), keywords: "acknowledge ack alert on it mine" }); + } + if (alertsToAck.length > 1) { + items.push({ key: "ack-all", category: "Alerts", title: `Acknowledge all ${alertsToAck.length} alerts nobody is on`, subtitle: "for 4 hours, handed to you", run: () => ack(alertsToAck), keywords: "acknowledge ack alerts all" }); + } + } + items.push({ key: "go-alerts-open", category: "Alerts", title: "Show the alerts nobody is on", subtitle: "", path: "/alerts", keywords: "alerts unacknowledged attention" }); + + // Update a server straight from here: opens the update drawer for it, which asks before it does anything. + if (canAct) { + for (const s of updatable) { + items.push({ + key: `update-${s.id}`, + category: "Updates", + title: `Update ${s.name} now`, + subtitle: `${s.updates?.count ?? 0} waiting${s.updates?.security ? ` · ${s.updates.security} security` : ""}`, + path: `/updates?update=${s.id}`, + keywords: "update upgrade patch install run", + }); + } + } + + // Hardware: open it, or print its label. + items.push({ key: "inv-labels", category: "Inventory", title: "Print inventory labels", subtitle: "a sheet of QR stickers", path: "/inventory/labels", keywords: "label labels qr print sticker" }); + for (const a of assets) { + items.push({ key: `inv-open-${a.id}`, category: "Inventory", title: `Open ${a.name} in the inventory`, subtitle: [a.manufacturer, a.model].filter(Boolean).join(" "), path: `/inventory?asset=${a.id}`, keywords: "hardware asset inventory serial" }); + items.push({ key: `inv-label-${a.id}`, category: "Inventory", title: `Print the label for ${a.name}`, subtitle: a.rackUnit ?? a.location ?? "", path: `/inventory/labels?only=${a.id}`, keywords: "label qr print sticker" }); + } + + // What would go down with a server or a service. + if (targets) { + for (const s of targets.servers) { + items.push({ key: `dep-server-${s.id}`, category: "Dependencies", title: `What depends on ${s.name}?`, subtitle: "server · opens the dependency map", path: `/map?view=dependencies&select=server:${s.id}`, keywords: "depends dependency impact reboot down" }); + } + for (const i of targets.integrations) { + items.push({ key: `dep-int-${i.id}`, category: "Dependencies", title: `What depends on ${i.name}?`, subtitle: `${i.type} · opens the dependency map`, path: `/map?view=dependencies&select=integration:${i.id}`, keywords: "depends dependency impact down" }); + } + } items.push({ key: "act-shortcuts", category: "Actions", title: "Show keyboard shortcuts", subtitle: "", hint: "?", run: () => void window.dispatchEvent(new Event(SHOW_SHORTCUTS_EVENT)), keywords: "keys help" }); if (user.role === "admin") { items.push({ @@ -315,7 +387,7 @@ export default function CommandPalette({ } return items; // eslint-disable-next-line react-hooks/exhaustive-deps - }, [user.role, canAct, targets, windows, onToggleTheme, onSetDensity, pathname, favorites]); + }, [user.role, user.id, canAct, targets, windows, alertsToAck, updatable, assets, onToggleTheme, onSetDensity, pathname, favorites]); const terms = query.trim().toLowerCase().split(/\s+/).filter(Boolean); @@ -438,7 +510,7 @@ export default function CommandPalette({ aria-autocomplete="list" aria-label="Search, or type a command" className="form-control form-control-lg border-0" - placeholder="Search, or type a command: silence, theme, wall…" + placeholder="Search, or type a command: acknowledge, update, label…" value={query} onChange={(e) => setQuery(e.target.value)} onKeyDown={handleInputKeyDown} diff --git a/web/src/components/DependencyMap.tsx b/web/src/components/DependencyMap.tsx index 74b0b35..fe5ae7e 100644 --- a/web/src/components/DependencyMap.tsx +++ b/web/src/components/DependencyMap.tsx @@ -1,5 +1,5 @@ import { useEffect, useMemo, useState } from "react"; -import { Link } from "react-router-dom"; +import { Link, useSearchParams } from "react-router-dom"; import { api, type DependencyGraph, type DependencyGraphNode } from "../api/client"; import { ErrorNotice } from "./Notice"; import { PageSkeleton } from "./Skeleton"; @@ -88,7 +88,9 @@ const names = (graph: DependencyGraph, keys: Iterable) => [...keys].map( export default function DependencyMap() { const [graph, setGraph] = useState(null); const [error, setError] = useState(null); - const [selected, setSelected] = useState(null); + // From the command palette ("What depends on …?"): start with that box picked. + const [params] = useSearchParams(); + const [selected, setSelected] = useState(params.get("select")); const [hover, setHover] = useState(null); useEffect(() => { diff --git a/web/src/components/StatusStrip.tsx b/web/src/components/StatusStrip.tsx index 5269761..e026d06 100644 --- a/web/src/components/StatusStrip.tsx +++ b/web/src/components/StatusStrip.tsx @@ -1,10 +1,16 @@ import { Link } from "react-router-dom"; import { IconAlertTriangle, IconCircleCheck, IconInfoCircle } from "@tabler/icons-react"; -import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport"; +import { useAlertsReport } from "../hooks/useAlertsReport"; +import { summariseAlerts } from "../utils/alertSummary"; +import { CATEGORY_LABELS } from "./RoutingEditor"; +import TimeAgo from "./TimeAgo"; const SEVERITY_ORDER = { critical: 0, warning: 1, info: 2 } as const; -/** One line at the top of the dashboard: is anything wrong right now? Reads the same alert report as the Alerts page. */ +/** + * The first thing on the dashboard, and the answer to "is it fine?": one sentence, the cause when one problem explains several, which kinds of + * thing are wrong, and the worst few. Reads the same alert report as the Alerts page. + */ export default function StatusStrip() { const { report, failed, reload } = useAlertsReport(); @@ -22,82 +28,85 @@ export default function StatusStrip() { ); } - const badge = alertBadge(report); - const active = report.alerts - .filter((a) => !a.silenced && a.severity !== "info") - .sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]); - const silenced = report.counts.silenced; - const grouped = report.counts.grouped ?? 0; + const sum = summariseAlerts(report); + const needs = sum.standing - sum.acknowledged; const blind = report.couldntCheck.length; - const acked = report.counts.acknowledged ?? 0; + const silenced = report.counts.silenced; + const active = report.alerts + .filter((a) => !a.silenced && a.severity !== "info" && !a.ack?.active) + .sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]); + + // "All clear" would claim more than is known if some checks couldn't run. + const unsure = needs === 0 && blind > 0; + const tone = unsure ? "yellow" : sum.tone; + const headline = unsure + ? "No active alerts, but some checks couldn't run" + : needs > 0 + ? `${needs} ${needs === 1 ? "thing needs" : "things need"} attention` + : sum.acknowledged > 0 + ? "Nothing new" + : "All clear"; const notes: string[] = []; + if (needs === 0 && sum.acknowledged > 0) notes.push(`${sum.acknowledged} acknowledged — somebody is on ${sum.acknowledged === 1 ? "it" : "them"}`); + else if (sum.acknowledged > 0) notes.push(`${sum.acknowledged} more acknowledged`); if (silenced > 0) notes.push(`${silenced} silenced by maintenance`); - if (grouped > 0) notes.push(`${grouped} more explained by a server that is down`); - if (blind > 0 && badge) notes.push(`${blind} check${blind === 1 ? "" : "s"} couldn't run`); + if (sum.held > 0 && sum.roots.length === 0) notes.push(`${sum.held} more explained by something that is down`); + if (needs === 0 && !unsure && notes.length === 0) notes.push("No active alerts."); + if (unsure) notes.push(`${report.couldntCheck.map((c) => c.name).join(", ")} — see Alerts for what that leaves unchecked`); + else if (blind > 0) notes.push(`${blind} check${blind === 1 ? "" : "s"} couldn't run`); - if (!badge) { - // Nothing is wrong that we can see — but if some checks couldn't run, "all clear" would claim more than is known. - const unsure = blind > 0; - return ( -
-
- {unsure ? : } -
- {unsure ? "No active alerts, but some checks couldn't run." : acked > 0 ? "Nothing new." : "All clear."}{" "} - {unsure ? ( - - {report.couldntCheck.map((c) => c.name).join(", ")} — see Alerts for what that leaves unchecked. - - ) : ( - {acked > 0 ? `${acked} acknowledged — somebody is on ${acked === 1 ? "it" : "them"}. See Alerts.` : "No active alerts."} - )} - {silenced > 0 && {silenced} silenced by maintenance.} - {grouped > 0 && {grouped} more explained by a server that is down.} -
-
-
- ); - } - - const need = report.counts.attention ?? report.counts; - const parts = [ - need.critical > 0 ? `${need.critical} critical` : null, - need.warning > 0 ? `${need.warning} warning${need.warning === 1 ? "" : "s"}` : null, - (report.counts.acknowledged ?? 0) > 0 ? `${report.counts.acknowledged} acknowledged` : null, - ].filter(Boolean); + const Icon = tone === "green" ? IconCircleCheck : IconAlertTriangle; return ( -
-
- -
-
-
- - {badge.count} {badge.count === 1 ? "thing needs" : "things need"} attention - {" "} - — {parts.join(", ")} - {notes.length > 0 && · {notes.join(" · ")}} +
+
+
+
+ )} + {active.length > 0 && ( +
    + {active.slice(0, 3).map((a) => ( +
  • + {a.message} +
  • + ))} + {active.length > 3 &&
  • and {active.length - 3} more
  • } +
+ )} +
+ Checked +
+
-
+ ); } diff --git a/web/src/pages/Alerts.tsx b/web/src/pages/Alerts.tsx index be15ff6..86c0986 100644 --- a/web/src/pages/Alerts.tsx +++ b/web/src/pages/Alerts.tsx @@ -1,5 +1,5 @@ import { Fragment, useEffect, useMemo, useState } from "react"; -import { Link } from "react-router-dom"; +import { Link, useSearchParams } from "react-router-dom"; import { api, type AlertCategory, type AlertItem, type AlertSeverity, type AlertsReport, type CurrentUser } from "../api/client"; import { useSortable } from "../hooks/useSortable"; import SortableTh from "../components/SortableTh"; @@ -16,6 +16,7 @@ import RunPlaybookButton from "../components/RunPlaybookButton"; import RunbookEntry from "../components/RunbookEntry"; import AckDrawer, { ackWords } from "../components/AckDrawer"; import { useAlertsReport } from "../hooks/useAlertsReport"; +import { summariseAlerts } from "../utils/alertSummary"; const SEVERITY: Record = { critical: { label: "Critical", badge: "bg-red-lt text-red", rank: 0 }, @@ -46,7 +47,12 @@ export default function Alerts({ user }: { user: CurrentUser }) { const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const [severity, setSeverity] = useState<"all" | AlertSeverity>("all"); - const [category, setCategory] = useState<"all" | AlertCategory>("all"); + // The dashboard's chips link here with ?category=… + const [params] = useSearchParams(); + const [category, setCategory] = useState<"all" | AlertCategory>(() => { + const wanted = params.get("category"); + return wanted && wanted in CATEGORY_LABELS ? (wanted as AlertCategory) : "all"; + }); const [search, setSearch] = useState(""); const [showSilenced, setShowSilenced] = useState(true); // Which alerts to show by whether somebody is on them, and the one whose acknowledgement is being edited. @@ -115,18 +121,7 @@ export default function Alerts({ user }: { user: CurrentUser }) { }, [report, severity, category, search, showSilenced, attention, user.id, grouped]); // One line on where things stand: how many need someone, and which problems explain the rest. - const headline = useMemo(() => { - if (!report || report.alerts.length === 0) return null; - const standing = report.alerts.filter((a) => !a.silenced); - const acknowledged = standing.filter((a) => a.ack?.active).length; - const held = report.alerts.filter((a) => a.causedBy).length; - const roots = standing - .filter((a) => (a.affects?.length ?? 0) > 0) - .map((a) => ({ name: a.target?.name ?? a.source, count: report.alerts.filter((x) => x.causedBy?.alertId === a.id).length })) - .filter((r) => r.count > 0); - const critical = standing.some((a) => a.severity === "critical"); - return { standing: standing.length, acknowledged, held, roots, tone: standing.length === 0 ? "green" : critical ? "red" : "yellow" }; - }, [report]); + const headline = useMemo(() => (report && report.alerts.length > 0 ? summariseAlerts(report) : null), [report]); // No initial sort: the server already puts active problems first, worst first. const { sorted, sortKey, sortDir, requestSort } = useSortable(rows); @@ -193,8 +188,10 @@ export default function Alerts({ user }: { user: CurrentUser }) {
- {headline.standing === 0 ? "Nothing needs attention" : `${headline.standing} ${headline.standing === 1 ? "problem needs" : "problems need"} attention`} - {headline.acknowledged > 0 && headline.standing > 0 && · {headline.acknowledged} acknowledged} + {headline.standing - headline.acknowledged === 0 + ? "Nothing needs attention" + : `${headline.standing - headline.acknowledged} ${headline.standing - headline.acknowledged === 1 ? "problem needs" : "problems need"} attention`} + {headline.acknowledged > 0 && · {headline.acknowledged} acknowledged}
{headline.held > 0 && (
@@ -216,7 +213,7 @@ export default function Alerts({ user }: { user: CurrentUser }) {
)} -
+
{cards.map((c) => (
@@ -309,7 +306,7 @@ export default function Alerts({ user }: { user: CurrentUser }) { } />
- +
label="Severity" sortKeyName="rank" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> @@ -332,7 +329,7 @@ export default function Alerts({ user }: { user: CurrentUser }) { - {canSilence && ( -
{CATEGORY_LABELS[a.category]} {a.link ? {a.source} : a.source} + {a.message} {a.causedBy ? ( @@ -404,7 +401,7 @@ export default function Alerts({ user }: { user: CurrentUser }) { })()} +
{!a.silenced && (
diff --git a/web/src/pages/Inventory.tsx b/web/src/pages/Inventory.tsx index 9d19eb5..ed064a1 100644 --- a/web/src/pages/Inventory.tsx +++ b/web/src/pages/Inventory.tsx @@ -203,6 +203,12 @@ export default function Inventory({ user }: { user: CurrentUser }) { return servers.find((s) => s.name.toLowerCase() === n) ?? servers.find((s) => s.name.length >= 3 && n.includes(s.name.toLowerCase())) ?? null; })(); + // The form can be a long way down (on a phone, below the cards): bring it into view when it opens. + useEffect(() => { + if (draft) document.getElementById("inventory-form")?.scrollIntoView({ behavior: "smooth", block: "start" }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [draft === null, draft?.id]); + const set = (key: K, value: Draft[K]) => setDraft((d) => (d ? { ...d, [key]: value } : d)); const cards: { label: string; value: string; note?: string; color: string }[] = [ @@ -238,7 +244,12 @@ export default function Inventory({ user }: { user: CurrentUser }) {

{focused.name}

-
+
+ {canEdit && ( + + )} @@ -290,7 +301,7 @@ export default function Inventory({ user }: { user: CurrentUser }) {
{draft && ( -
+

{draft.id === null ? "Add hardware" : `Edit ${draft.name || "hardware"}`}

@@ -446,7 +457,7 @@ export default function Inventory({ user }: { user: CurrentUser }) { exportDisabled={!sorted || sorted.length === 0} />
- +
label="Name" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> @@ -468,7 +479,7 @@ export default function Inventory({ user }: { user: CurrentUser }) { )} {page.pageItems?.map((a) => ( - - - - - + {canEdit && ( -
+ {a.name} {(a.manufacturer || a.model) &&
{[a.manufacturer, a.model].filter(Boolean).join(" ")}
} {a.server && ( @@ -486,20 +497,20 @@ export default function Inventory({ user }: { user: CurrentUser }) { )}
{KIND_LABELS[a.kind]} + {a.location ?? "—"} {a.rackUnit && · {a.rackUnit}} + {a.purchaseDate ?? "—"} {a.purchasePrice !== null &&
{money(a.purchasePrice, config.currency)}
}
+ {a.powerWatts === null ? — : `${a.powerWatts} W`}{a.powerWatts === null ? — : `${a.powerWatts} W`} +