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 <noreply@anthropic.com>
This commit is contained in:
1 parent
43fc5e0272
commit
b5384c1e03
12 files changed
+429
-118
No files matched your search
+17
-20
@@ -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<AlertSeverity, { label: string; badge: string; rank: number }> = {
|
||||
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<string | null>(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 }) {
|
||||
<div className={`card mb-3 alerts-headline alerts-headline-${headline.tone}`} role="status">
|
||||
<div className="card-body py-3">
|
||||
<div className="h3 mb-1">
|
||||
{headline.standing === 0 ? "Nothing needs attention" : `${headline.standing} ${headline.standing === 1 ? "problem needs" : "problems need"} attention`}
|
||||
{headline.acknowledged > 0 && headline.standing > 0 && <span className="text-secondary fw-normal fs-4"> · {headline.acknowledged} acknowledged</span>}
|
||||
{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 && <span className="text-secondary fw-normal fs-4"> · {headline.acknowledged} acknowledged</span>}
|
||||
</div>
|
||||
{headline.held > 0 && (
|
||||
<div className="text-secondary">
|
||||
@@ -216,7 +213,7 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="row g-3 mb-3">
|
||||
<div className="row g-3 mb-3 d-none d-md-flex">
|
||||
{cards.map((c) => (
|
||||
<div className="col-6 col-md-3" key={c.label}>
|
||||
<div className="card card-sm">
|
||||
@@ -309,7 +306,7 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
/>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<table className="table table-vcenter card-table table-stack">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortableTh<Row> label="Severity" sortKeyName="rank" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
@@ -332,7 +329,7 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
</td>
|
||||
<td>{CATEGORY_LABELS[a.category]}</td>
|
||||
<td>{a.link ? <Link to={a.link}>{a.source}</Link> : a.source}</td>
|
||||
<td>
|
||||
<td className="stack-wide">
|
||||
{a.message}
|
||||
{a.causedBy ? (
|
||||
<span className="badge bg-secondary-lt text-secondary ms-2" title={`${a.causedBy.name} is down too, which explains this — notifications for this are held back. If ${a.causedBy.name} comes back and this stays down, it alerts then.`}>
|
||||
@@ -404,7 +401,7 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
})()}
|
||||
</td>
|
||||
{canSilence && (
|
||||
<td className="text-nowrap">
|
||||
<td className="text-nowrap stack-wide">
|
||||
<div className="btn-list flex-nowrap">
|
||||
{!a.silenced && (
|
||||
<button type="button" className={`btn btn-sm ${a.ack?.active ? "btn-outline-primary" : "btn-outline-secondary"}`} onClick={() => setAcking(a)}>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { isValidElement, useEffect, useState, type ReactNode } from "react";
|
||||
import { IconArrowLeft, IconArrowRight, IconEye, IconEyeOff } from "@tabler/icons-react";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import WhatChanged from "../components/WhatChanged";
|
||||
import { setProblemsFirst, useProblemsFirst } from "../utils/problemsFirst";
|
||||
import { UNPLACED, moveCard, resetDashboardLayout, setCardHidden, setEditingDashboard, useDashboardLayout } from "../utils/dashboardLayout";
|
||||
import { Link } from "react-router-dom";
|
||||
import {
|
||||
@@ -188,16 +189,25 @@ function MiniStat({ label, value, accent }: { label: string; value: ReactNode; a
|
||||
}
|
||||
|
||||
/** The single card shape shared by every dashboard widget — DNS, Secrets, and each integration — so they all read as one family: a label + status badge, then whatever stats/breakdown that widget has. */
|
||||
/** Whether a card's status badge says something is wrong: the badges of a card in trouble are red or yellow, so that is what is read. */
|
||||
function problemOf(badge: ReactNode): "bad" | "warn" | null {
|
||||
if (!isValidElement(badge)) return null;
|
||||
const cls = String((badge.props as { className?: string }).className ?? "");
|
||||
return /\bbg-red/.test(cls) ? "bad" : /\bbg-yellow/.test(cls) ? "warn" : null;
|
||||
}
|
||||
|
||||
function WidgetCard({ label, badge, hide, children }: { label: string; badge?: ReactNode; /** Nothing is set up for this yet: it is listed under "Not set up yet" instead of taking a card. */ hide?: boolean; children: ReactNode }) {
|
||||
const { layout, editing } = useDashboardLayout();
|
||||
const problemsFirst = useProblemsFirst();
|
||||
if (hide) return null;
|
||||
// The person's own arrangement: cards they hid are gone (shown dimmed while arranging, so they can be brought back), and the
|
||||
// rest follow the order they chose — a card nobody has placed goes last, in the order it was drawn.
|
||||
const hidden = layout.hidden.includes(label);
|
||||
const problem = problemOf(badge);
|
||||
if (hidden && !editing) return null;
|
||||
return (
|
||||
<div className="col-md-6" data-card={label} style={{ order: layout.order[label] ?? UNPLACED }}>
|
||||
<div className={`card h-100 ${hidden ? "card-hidden" : ""}`}>
|
||||
<div className="col-md-6" data-card={label} style={{ order: (layout.order[label] ?? UNPLACED) - (problemsFirst && !editing ? (problem === "bad" ? 2_000_000 : problem === "warn" ? 1_000_000 : 0) : 0) }}>
|
||||
<div className={`card h-100 ${hidden ? "card-hidden" : ""} ${problem ? `card-problem card-problem-${problem}` : ""}`}>
|
||||
{editing && (
|
||||
<div className="card-customise">
|
||||
<button type="button" className="btn btn-sm btn-icon" aria-label={`Move ${label} earlier`} title="Move earlier" onClick={(e) => void moveCard(e.currentTarget.closest<HTMLElement>("[data-card]")!, -1)}>
|
||||
@@ -314,6 +324,7 @@ function formatBytes(bytes: number | null): string {
|
||||
|
||||
export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
const { editing } = useDashboardLayout();
|
||||
const problemsFirst = useProblemsFirst();
|
||||
const [integrations, setIntegrations] = useState<IntegrationSummary[] | null>(null);
|
||||
const [tailscaleSummary, setTailscaleSummary] = useState<TailscaleDevicesResponse["summary"] | null>(null);
|
||||
const [tailscaleExtra, setTailscaleExtra] = useState<TailscaleExtra | null>(null);
|
||||
@@ -623,7 +634,11 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
{editing && (
|
||||
<div className="alert alert-info d-flex flex-wrap align-items-center gap-2" role="status">
|
||||
<span>Move the cards with the arrows and hide the ones you don't use. It saves as you go, for you only, and follows you to other browsers.</span>
|
||||
<button type="button" className="btn btn-sm ms-auto" onClick={() => void resetDashboardLayout()}>
|
||||
<label className="form-check mb-0 ms-auto">
|
||||
<input type="checkbox" className="form-check-input" checked={problemsFirst} onChange={(e) => setProblemsFirst(e.target.checked)} />
|
||||
<span className="form-check-label">Cards with a problem come first</span>
|
||||
</label>
|
||||
<button type="button" className="btn btn-sm" onClick={() => void resetDashboardLayout()}>
|
||||
Reset to default
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -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 = <K extends keyof Draft>(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 }) {
|
||||
<div className="card mb-3 border-primary">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{focused.name}</h3>
|
||||
<div className="card-actions">
|
||||
<div className="card-actions btn-list">
|
||||
{canEdit && (
|
||||
<button className="btn btn-sm btn-primary" onClick={() => setDraft(toDraft(focused))}>
|
||||
Edit
|
||||
</button>
|
||||
)}
|
||||
<button className="btn btn-sm" onClick={() => setParams((p) => { const n = new URLSearchParams(p); n.delete("asset"); return n; }, { replace: true })}>
|
||||
Close
|
||||
</button>
|
||||
@@ -290,7 +301,7 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
</div>
|
||||
|
||||
{draft && (
|
||||
<form className="card mb-3" onSubmit={save}>
|
||||
<form id="inventory-form" className="card mb-3" onSubmit={save}>
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{draft.id === null ? "Add hardware" : `Edit ${draft.name || "hardware"}`}</h3>
|
||||
</div>
|
||||
@@ -446,7 +457,7 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
exportDisabled={!sorted || sorted.length === 0}
|
||||
/>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<table className="table table-vcenter card-table table-stack">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortableTh<Asset> 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) => (
|
||||
<tr key={a.id}>
|
||||
<td>
|
||||
<td className="stack-wide">
|
||||
{a.name}
|
||||
{(a.manufacturer || a.model) && <div className="text-secondary small">{[a.manufacturer, a.model].filter(Boolean).join(" ")}</div>}
|
||||
{a.server && (
|
||||
@@ -486,20 +497,20 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
)}
|
||||
</td>
|
||||
<td>{KIND_LABELS[a.kind]}</td>
|
||||
<td>
|
||||
<td className="stack-label" data-label="Where">
|
||||
{a.location ?? "—"}
|
||||
{a.rackUnit && <span className="text-secondary"> · {a.rackUnit}</span>}
|
||||
</td>
|
||||
<td className="text-secondary">
|
||||
<td className="text-secondary stack-label" data-label="Bought">
|
||||
{a.purchaseDate ?? "—"}
|
||||
{a.purchasePrice !== null && <div className="small">{money(a.purchasePrice, config.currency)}</div>}
|
||||
</td>
|
||||
<td>
|
||||
<td className="stack-label" data-label="Warranty">
|
||||
<WarrantyBadge until={a.warrantyUntil} />
|
||||
</td>
|
||||
<td>{a.powerWatts === null ? <span className="text-secondary">—</span> : `${a.powerWatts} W`}</td>
|
||||
<td className="stack-label" data-label="Power">{a.powerWatts === null ? <span className="text-secondary">—</span> : `${a.powerWatts} W`}</td>
|
||||
{canEdit && (
|
||||
<td>
|
||||
<td className="stack-wide">
|
||||
<div className="btn-list flex-nowrap">
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => setDraft(toDraft(a))}>
|
||||
Edit
|
||||
|
||||
@@ -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 Asset } from "../api/client";
|
||||
import QrCode from "../components/QrCode";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
@@ -28,15 +28,19 @@ export default function InventoryLabels() {
|
||||
const [chosen, setChosen] = useState<Set<number>>(new Set());
|
||||
const [size, setSize] = useState<SizeKey>("medium");
|
||||
const [showBorder, setShowBorder] = useState(true);
|
||||
// From the command palette (?only=ID): start with just that piece of hardware ticked.
|
||||
const [params] = useSearchParams();
|
||||
const only = /^\d+$/.test(params.get("only") ?? "") ? Number(params.get("only")) : null;
|
||||
|
||||
useEffect(() => {
|
||||
api.inventory
|
||||
.list()
|
||||
.then((res) => {
|
||||
setAssets(res.assets);
|
||||
setChosen(new Set(res.assets.map((a) => a.id)));
|
||||
setChosen(new Set(only !== null && res.assets.some((a) => a.id === only) ? [only] : res.assets.map((a) => a.id)));
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const picked = useMemo(() => (assets ?? []).filter((a) => chosen.has(a.id)), [assets, chosen]);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { api, type AgentLatest, type CurrentUser, type DockhandContainer, type UpdatesServer } from "../api/client";
|
||||
import { agentState, agentVersionWords } from "../utils/agent";
|
||||
import SortableTh from "../components/SortableTh";
|
||||
@@ -65,6 +65,22 @@ export default function Updates({ user }: { user: CurrentUser }) {
|
||||
const [containers, setContainers] = useState<(DockhandContainer & { integrationName: string })[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [onlyWaiting, setOnlyWaiting] = useState(false);
|
||||
// The command palette sends people here with ?update=ID to update that server straight away.
|
||||
const [params, setParams] = useSearchParams();
|
||||
const wantedUpdate = params.get("update");
|
||||
useEffect(() => {
|
||||
if (!wantedUpdate || !servers || !canRun) return;
|
||||
const server = servers.find((s) => String(s.id) === wantedUpdate);
|
||||
if (server) setUpdating(server);
|
||||
setParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev);
|
||||
next.delete("update");
|
||||
return next;
|
||||
},
|
||||
{ replace: true },
|
||||
);
|
||||
}, [wantedUpdate, servers, canRun, setParams]);
|
||||
|
||||
function reload() {
|
||||
api.servers
|
||||
@@ -178,7 +194,7 @@ export default function Updates({ user }: { user: CurrentUser }) {
|
||||
exportDisabled={!sorted || sorted.length === 0}
|
||||
/>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<table className="table table-vcenter card-table table-stack">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortableTh<Row> label="Server" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
@@ -200,16 +216,16 @@ export default function Updates({ user }: { user: CurrentUser }) {
|
||||
)}
|
||||
{sorted?.map((r) => (
|
||||
<tr key={r.id}>
|
||||
<td>
|
||||
<td className="stack-wide">
|
||||
<Link to={`/servers/${r.id}`}>{r.name}</Link> <span className="text-secondary small">{r.manager}</span>
|
||||
</td>
|
||||
<td>
|
||||
<UpdatesBadge updates={r.server.updates} />
|
||||
</td>
|
||||
<td>{r.security === null ? <span className="text-secondary">—</span> : r.security}</td>
|
||||
<td className="text-secondary">{r.since ? <TimeAgo value={r.since} /> : "—"}</td>
|
||||
<td className="text-secondary">{r.reportedAt ? <TimeAgo value={r.reportedAt} /> : "—"}</td>
|
||||
<td>
|
||||
<td className="stack-label" data-label="Security">{r.security === null ? <span className="text-secondary">—</span> : r.security}</td>
|
||||
<td className="text-secondary stack-label" data-label="Waiting since">{r.since ? <TimeAgo value={r.since} /> : "—"}</td>
|
||||
<td className="text-secondary stack-label" data-label="Reported">{r.reportedAt ? <TimeAgo value={r.reportedAt} /> : "—"}</td>
|
||||
<td className="stack-label" data-label="Agent">
|
||||
{agentVersionWords(r.agentVersion)}{" "}
|
||||
{agentState(r.server, agentLatest) === "behind" && (
|
||||
<span className="badge bg-yellow-lt text-yellow" title="Older than the agent this Homelab Manager would install now.">
|
||||
@@ -218,7 +234,7 @@ export default function Updates({ user }: { user: CurrentUser }) {
|
||||
)}
|
||||
</td>
|
||||
{canRun && (
|
||||
<td>
|
||||
<td className="stack-wide">
|
||||
<button type="button" className="btn btn-sm btn-outline-primary" disabled={r.count === null || r.count === 0 || r.server.lastSeenAt === null} title={r.count ? "Apply this server's updates through a Semaphore playbook" : "Nothing is waiting, or the agent hasn't said"} onClick={() => setUpdating(r.server)}>
|
||||
Update…
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user