Phone card layout, status symbols, breadcrumbs, integration cards and server trends

Tables stack into labelled cards on a phone. Green, red and amber badges carry
a check, cross or triangle as well as their colour. Pages inside a menu group
show a breadcrumb, with the thing's name on a server's page. Integrations are
cards with an Open button and a live status (working, failing, not checked yet,
disabled). Agent-reported servers keep a short history of load, memory and disk
use (migration 0019, one sample per ten minutes for 35 days) and show it as a
Trends card with a days-until-full forecast for a filling disk.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-14 23:56:05 +02:00
1 parent 617dc1ea2f
commit 9965d94036
22 files changed
+3000 -84

No files matched your search

+13
View File
@@ -126,6 +126,16 @@ export interface SecretInput {
checkPort?: number | null;
}
export interface ServerMetricSeries {
metric: string;
kind: "cpu" | "mem" | "disk";
label: string;
points: { t: string; v: number }[];
latest: number | null;
/** Disks only: the rate of change in points a day, and the days until full when it is rising. */
trend: { perDay: number; daysToFull: number | null } | null;
}
export interface IpamEntry {
id: number;
ipAddress: string;
@@ -580,6 +590,8 @@ export interface IntegrationSummary {
baseUrl: string;
enabled: boolean;
createdAt: string;
/** How its latest calls have gone since the app started. Only present on the integrations list. */
health?: { status: "ok" | "failing" | "unknown" | "disabled"; consecutiveFailures: number };
}
export interface TailscaleDevice {
@@ -1235,6 +1247,7 @@ export const api = {
request<{ server: ServerRecord }>(`/api/servers/${id}`, { method: "PATCH", body: JSON.stringify(data) }),
summary: () => request<ServerSummary>("/api/servers/summary"),
detail: (id: number) => request<ServerDetail>(`/api/servers/${id}/detail`),
metrics: (id: number, days: number) => request<{ days: number; series: ServerMetricSeries[] }>(`/api/servers/${id}/metrics?days=${days}`),
remove: (id: number) => request<void>(`/api/servers/${id}`, { method: "DELETE" }),
setTags: (id: number, tags: string[]) =>
request<{ tags: string[] }>(`/api/servers/${id}/tags`, { method: "PUT", body: JSON.stringify({ tags }) }),
+94
View File
@@ -0,0 +1,94 @@
import { useEffect, useState } from "react";
import { api, type ServerMetricSeries } from "../api/client";
import Sparkline from "./Sparkline";
const RANGES = [
{ days: 1, label: "24 hours" },
{ days: 7, label: "7 days" },
{ days: 30, label: "30 days" },
];
function levelColor(series: ServerMetricSeries): string {
const v = series.latest ?? 0;
if (series.kind === "disk") return v >= 90 ? "#f03e3e" : v >= 80 ? "#f59f00" : "#4299e1";
return "#4299e1";
}
/** One line of words about where a series is heading: a disk's rate and when it fills, or a load/memory range. */
function describeTrend(series: ServerMetricSeries): string {
if (series.kind === "disk" && series.trend) {
const { perDay, daysToFull } = series.trend;
if (daysToFull !== null) return `rising ${perDay.toFixed(1)} points a day — full in about ${daysToFull} day${daysToFull === 1 ? "" : "s"}`;
if (perDay <= -0.05) return `falling ${Math.abs(perDay).toFixed(1)} points a day`;
return "steady";
}
if (series.kind === "disk") return "not enough history for a trend yet";
const values = series.points.map((p) => p.v);
if (values.length === 0) return "";
return `${Math.round(Math.min(...values))}–${Math.round(Math.max(...values))}% over this time`;
}
/** How an agent-reported server's load, memory and disks have moved lately, with a forecast for a filling disk. */
export default function ServerTrends({ serverId }: { serverId: number }) {
const [days, setDays] = useState(7);
const [series, setSeries] = useState<ServerMetricSeries[] | null>(null);
const [failed, setFailed] = useState(false);
useEffect(() => {
let alive = true;
setFailed(false);
api.servers
.metrics(serverId, days)
.then((res) => alive && setSeries(res.series))
.catch(() => alive && setFailed(true));
return () => {
alive = false;
};
}, [serverId, days]);
return (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Trends</h3>
<div className="card-actions">
<select className="form-select form-select-sm" value={days} onChange={(e) => setDays(Number(e.target.value))} aria-label="Time range">
{RANGES.map((r) => (
<option key={r.days} value={r.days}>
Last {r.label}
</option>
))}
</select>
</div>
</div>
<div className="card-body">
{failed ? (
<div className="text-secondary">Couldn't load the history.</div>
) : series === null ? (
<div className="text-secondary">Loading…</div>
) : series.length === 0 ? (
<div className="text-secondary">
No history yet. A sample is kept about every ten minutes once the agent has reported, so lines appear here after a short while.
</div>
) : (
<div className="trend-grid">
{series.map((s) => {
const words = describeTrend(s);
return (
<div key={s.metric} className="trend-row">
<div className="trend-label">{s.label}</div>
<Sparkline
points={s.points}
color={levelColor(s)}
label={`${s.label}, ${s.latest !== null ? `${Math.round(s.latest)}% now` : "no reading"}${words ? `, ${words}` : ""}`}
/>
<div className="trend-now">{s.latest !== null ? `${Math.round(s.latest)}%` : "—"}</div>
<div className="trend-words text-secondary small">{words}</div>
</div>
);
})}
</div>
)}
</div>
</div>
);
}
+37
View File
@@ -0,0 +1,37 @@
/**
* A small line of how a percentage moved. The scale is always 0–100%, so a disk at 40% looks half-empty and one at 95% looks full
* however little it moved — a line that stretched to fit its own ups and downs would make every wobble look alarming.
*/
export default function Sparkline({
points,
color = "#4299e1",
label,
}: {
points: { t: string; v: number }[];
color?: string;
/** Read out by screen readers in place of the picture. */
label: string;
}) {
const W = 160;
const H = 36;
if (points.length < 2) {
return (
<svg viewBox={`0 0 ${W} ${H}`} className="sparkline" role="img" aria-label={label}>
<line x1="0" y1={H - 1} x2={W} y2={H - 1} stroke="currentColor" strokeOpacity="0.25" />
</svg>
);
}
const t0 = Date.parse(points[0].t);
const span = Math.max(Date.parse(points[points.length - 1].t) - t0, 1);
const xy = points.map((p) => {
const x = ((Date.parse(p.t) - t0) / span) * (W - 2) + 1;
const y = H - 2 - (Math.min(100, Math.max(0, p.v)) / 100) * (H - 4);
return `${x.toFixed(1)},${y.toFixed(1)}`;
});
return (
<svg viewBox={`0 0 ${W} ${H}`} className="sparkline" role="img" aria-label={label} preserveAspectRatio="none">
<polyline points={`1,${H - 1} ${xy.join(" ")} ${W - 1},${H - 1}`} fill={color} fillOpacity="0.15" stroke="none" />
<polyline points={xy.join(" ")} fill="none" stroke={color} strokeWidth="1.6" strokeLinejoin="round" strokeLinecap="round" vectorEffect="non-scaling-stroke" />
</svg>
);
}
+54
View File
@@ -0,0 +1,54 @@
import { useEffect } from "react";
const SORT_GLYPHS = /[↕↑↓▲▼⇅⇵]/g;
/** Writes each column's heading onto its cells (data-label), so the phone layout can show "Status: running" beside each value. */
function labelTable(table: HTMLTableElement): void {
const headRow = table.tHead?.rows[table.tHead.rows.length - 1];
if (!headRow) return;
const labels: string[] = [];
for (const th of Array.from(headRow.cells)) {
const text = (th.textContent ?? "").replace(SORT_GLYPHS, "").replace(/\s+/g, " ").trim();
for (let i = 0; i < Math.max(1, th.colSpan); i++) labels.push(text);
}
for (const body of Array.from(table.tBodies)) {
for (const row of Array.from(body.rows)) {
let col = 0;
for (const cell of Array.from(row.cells)) {
const label = cell.colSpan > 1 ? "" : (labels[col] ?? "");
if (label) {
if (cell.getAttribute("data-label") !== label) cell.setAttribute("data-label", label);
} else if (cell.hasAttribute("data-label")) {
cell.removeAttribute("data-label");
}
col += Math.max(1, cell.colSpan);
}
}
}
}
/**
* On a phone the wide tables are drawn as a stack of cards (see styles.css), which needs every cell to know its column's
* heading. This keeps that up to date as pages load, sort, filter and page — without each table having to do it.
*/
export function useStackedTables(): void {
useEffect(() => {
const root = document.querySelector(".page-body");
if (!root) return;
// A short timer rather than an animation frame: frames stop while the tab is in the background, and the labels should not.
let timer: ReturnType<typeof setTimeout> | null = null;
const run = () => {
timer = null;
root.querySelectorAll<HTMLTableElement>("table.card-table").forEach(labelTable);
};
const observer = new MutationObserver(() => {
if (!timer) timer = setTimeout(run, 30);
});
observer.observe(root, { childList: true, subtree: true });
run();
return () => {
observer.disconnect();
if (timer) clearTimeout(timer);
};
}, []);
}
+26
View File
@@ -43,6 +43,8 @@ import { DENSITIES, getDensity, setDensity, type Density } from "../utils/densit
import CommandPalette from "../components/CommandPalette";
import { isLightColor, useEnvironment } from "../utils/environment";
import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport";
import { useStackedTables } from "../hooks/useStackedTables";
import { useBreadcrumbTailValue } from "../utils/breadcrumb";
interface NavBadge {
text: string;
@@ -182,6 +184,8 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
const [density, setDensityState] = useState<Density>(() => getDensity());
const [maintenance, setMaintenance] = useState<MaintenanceWindow[]>([]);
const environment = useEnvironment();
useStackedTables();
const breadcrumbTail = useBreadcrumbTailValue();
const { report } = useAlertsReport();
const [menuOpen, setMenuOpen] = useState(false);
const menuRef = useRef<HTMLDivElement>(null);
@@ -223,6 +227,17 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
const nav = visibleNav(user.role);
const { pathname } = useLocation();
// Where this page sits in the menu: "Infrastructure › Servers", and on a page about one thing, that thing's name as well.
const crumbs: { label: string; to?: string }[] = [];
for (const entry of nav) {
if (!isGroup(entry)) continue;
const leaf = entry.items.find((item) => isCurrent(pathname, item.to));
if (!leaf) continue;
crumbs.push({ label: entry.label }, breadcrumbTail ? { label: leaf.label, to: leaf.to } : { label: leaf.label });
if (breadcrumbTail) crumbs.push({ label: breadcrumbTail });
break;
}
const [openGroups, setOpenGroups] = useState<Set<string>>(loadOpenGroups);
// The group holding the current page is always open, so you can see where you are (others stay as you left them).
@@ -437,6 +452,17 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
</div>
</div>
)}
{crumbs.length > 0 && (
<nav aria-label="breadcrumb" className="mb-2">
<ol className="breadcrumb breadcrumb-arrows mb-0">
{crumbs.map((c, i) => (
<li key={i} className={`breadcrumb-item ${i === crumbs.length - 1 ? "active" : ""}`} aria-current={i === crumbs.length - 1 ? "page" : undefined}>
{c.to ? <Link to={c.to}>{c.label}</Link> : c.label}
</li>
))}
</ol>
</nav>
)}
{children}
</div>
</div>
+116 -80
View File
@@ -1,10 +1,10 @@
import { useEffect, useState, type CSSProperties } from "react";
import { useSearchParams } from "react-router-dom";
import { Link, useSearchParams } from "react-router-dom";
import { api, type CurrentUser, type IntegrationSummary, type IntegrationType } from "../api/client";
import IntegrationForm from "../components/IntegrationForm";
import IntegrationEditForm from "../components/IntegrationEditForm";
import { useSortable } from "../hooks/useSortable";
import SortableTh from "../components/SortableTh";
import TableToolbar from "../components/TableToolbar";
import { useTableSearch } from "../hooks/useTableSearch";
import { downloadCsv } from "../utils/csv";
import { confirmDialog } from "../utils/dialogs";
import { ErrorNotice } from "../components/Notice";
@@ -23,6 +23,48 @@ const TYPE_LABELS: Record<IntegrationType, string> = {
osticket: "osTicket",
};
/** The page each kind of integration gets once it is connected. */
const TYPE_PAGES: Record<IntegrationType, string> = {
tailscale: "/tailscale",
proxmox: "/proxmox",
synology: "/synology",
semaphore: "/semaphore",
gitea: "/gitea",
dockhand: "/docker",
uptimekuma: "/uptime-kuma",
phpipam: "/ipam",
pbs: "/pbs",
osticket: "/osticket",
};
/** "pve.example.lan" out of "https://pve.example.lan:8006/", or the text itself when it isn't an address. */
function hostOf(baseUrl: string): string {
if (!baseUrl) return "";
try {
return new URL(baseUrl).host;
} catch {
return baseUrl;
}
}
function HealthBadge({ i }: { i: IntegrationSummary }) {
const health = i.health;
if (!i.enabled || health?.status === "disabled") return <span className="badge bg-secondary-lt text-secondary">Disabled</span>;
if (health?.status === "failing") {
return (
<span className="badge bg-red-lt text-red">
Failing — last {health.consecutiveFailures} call{health.consecutiveFailures === 1 ? "" : "s"} failed
</span>
);
}
if (health?.status === "ok") return <span className="badge bg-green-lt text-green">Working</span>;
return (
<span className="badge bg-secondary-lt text-secondary" title="Nothing has called it since the app started. Use Test to check it now.">
Not checked yet
</span>
);
}
function typeBadgeStyle(colors: Record<string, string>, type: IntegrationType): CSSProperties {
const color = colors[type];
if (!color) return {};
@@ -93,7 +135,8 @@ export default function Integrations({ user }: { user: CurrentUser }) {
}
}
const { sorted: sortedIntegrations, sortKey, sortDir, requestSort } = useSortable(integrations);
const tableSearch = useTableSearch(integrations);
const sortedIntegrations = tableSearch.filtered ? [...tableSearch.filtered].sort((a, b) => a.name.localeCompare(b.name)) : null;
function exportCsv() {
if (!sortedIntegrations) return;
@@ -143,97 +186,90 @@ export default function Integrations({ user }: { user: CurrentUser }) {
)
)}
<div className="card">
<div className="card-header justify-content-end">
<button className="btn btn-outline-secondary btn-sm" onClick={exportCsv} disabled={!integrations || integrations.length === 0}>
Export CSV
</button>
</div>
<div className="table-responsive">
<table className="table table-vcenter card-table">
<thead>
<tr>
<SortableTh<IntegrationSummary> label="Name" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
<SortableTh<IntegrationSummary> label="Type" sortKeyName="type" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
<SortableTh<IntegrationSummary>
label="Status"
sortKeyName="enabled"
activeKey={sortKey}
direction={sortDir}
onSort={requestSort}
/>
{isAdmin && <th className="w-1">Actions</th>}
</tr>
</thead>
<tbody>
{sortedIntegrations?.map((i) => (
<tr key={i.id}>
<td>{i.name}</td>
<td>
<span className="badge" style={typeBadgeStyle(integrationColors, i.type)}>
<div className="card mb-3">
<TableToolbar
search={tableSearch.query}
onSearch={tableSearch.setQuery}
placeholder="Search integrations…"
shown={sortedIntegrations?.length}
total={integrations?.length}
onExport={exportCsv}
exportDisabled={!integrations || integrations.length === 0}
/>
</div>
<div className="row row-cards">
{sortedIntegrations?.map((i) => {
const result = testResults[i.id];
const page = TYPE_PAGES[i.type];
return (
<div className="col-md-6 col-xl-4" key={i.id}>
<div className="card h-100">
<div className="card-body d-flex flex-column">
<div className="d-flex align-items-start gap-2 mb-2">
<div className="flex-fill" style={{ minWidth: 0 }}>
<div className="fw-bold text-truncate">{i.name}</div>
<div className="text-secondary small text-truncate">{hostOf(i.baseUrl) || "no web address"}</div>
</div>
<span className="badge flex-shrink-0" style={typeBadgeStyle(integrationColors, i.type)}>
{TYPE_LABELS[i.type]}
</span>
</td>
<td>
{isAdmin ? (
<button
className={`badge ${i.enabled ? "bg-green-lt text-green" : "bg-secondary-lt text-secondary"} border-0`}
onClick={() => toggleEnabled(i)}
>
{i.enabled ? "Enabled" : "Disabled"}
</button>
) : (
<span className={`badge ${i.enabled ? "bg-green-lt text-green" : "bg-secondary-lt text-secondary"}`}>
{i.enabled ? "Enabled" : "Disabled"}
</div>
<div className="mb-3">
<HealthBadge i={i} />
{result && testingId !== i.id && (
<span className={`badge ms-2 ${result.ok ? "bg-green-lt text-green" : "bg-red-lt text-red"}`}>
Test {result.ok ? `passed${result.latencyMs !== undefined ? ` (${result.latencyMs}ms)` : ""}` : "failed"}
</span>
)}
</td>
{isAdmin && (
<td>
<div className="btn-list flex-nowrap align-items-center">
</div>
{result && !result.ok && testingId !== i.id && <div className="text-red small mb-3">{result.error}</div>}
<div className="btn-list mt-auto">
{i.enabled && (
<Link to={page} className="btn btn-sm btn-primary">
Open
</Link>
)}
{isAdmin && (
<>
<button className="btn btn-sm" onClick={() => testIntegration(i)} disabled={testingId === i.id}>
{testingId === i.id ? "Testing…" : "Test"}
</button>
{testResults[i.id] && testingId !== i.id && (
<span className={`badge ${testResults[i.id].ok ? "bg-green-lt text-green" : "bg-red-lt text-red"}`}>
{testResults[i.id].ok
? `OK${testResults[i.id].latencyMs !== undefined ? ` (${testResults[i.id].latencyMs}ms)` : ""}`
: "Failed"}
</span>
)}
<button className="btn btn-sm" onClick={() => setEditingIntegration(i)}>
Edit
</button>
<button className="btn btn-sm" onClick={() => toggleEnabled(i)}>
{i.enabled ? "Disable" : "Enable"}
</button>
<button className="btn btn-sm btn-outline-danger" onClick={() => removeIntegration(i)}>
Delete
</button>
</div>
{testResults[i.id] && !testResults[i.id].ok && testingId !== i.id && (
<div className="text-red small mt-1">{testResults[i.id].error}</div>
)}
</td>
)}
</tr>
))}
{sortedIntegrations?.length === 0 && (
<tr>
<td colSpan={isAdmin ? 4 : 3} className="text-secondary text-center">
No integrations configured yet.
{isAdmin && (
<>
{" "}
<button className="btn btn-link p-0 align-baseline" onClick={() => setAdding(true)}>
Add one
</button>
.
</>
)}
</td>
</tr>
)}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
);
})}
{sortedIntegrations?.length === 0 && (
<div className="col-12">
<div className="card">
<div className="card-body text-secondary text-center">
{tableSearch.active ? "Nothing matches that search." : "No integrations configured yet."}
{isAdmin && !tableSearch.active && (
<>
{" "}
<button className="btn btn-link p-0 align-baseline" onClick={() => setAdding(true)}>
Add one
</button>
.
</>
)}
</div>
</div>
</div>
)}
</div>
</>
);
+5
View File
@@ -13,12 +13,14 @@ import {
type TaskRecord,
} from "../api/client";
import ServerPorts from "../components/ServerPorts";
import ServerTrends from "../components/ServerTrends";
import ServerTags from "../components/ServerTags";
import ServerTaskTable, { SCHEDULE_TYPE_LABELS } from "../components/ServerTaskTable";
import { formatDateTime } from "../utils/date";
import { guessAdminUrl, portOptionLabel } from "../utils/adminLinkUrl";
import { confirmDialog } from "../utils/dialogs";
import { ErrorNotice } from "../components/Notice";
import { useBreadcrumbTail } from "../utils/breadcrumb";
const SCHEDULE_TYPE_OPTIONS: { value: ScheduleType; label: string }[] = Object.entries(SCHEDULE_TYPE_LABELS).map(
([value, label]) => ({ value: value as ScheduleType, label }),
@@ -92,6 +94,7 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
const canEditTasks = user.role === "admin" || user.role === "operator";
const [detail, setDetail] = useState<ServerDetailResponse | null>(null);
useBreadcrumbTail(detail?.server.name);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [refreshing, setRefreshing] = useState(false);
@@ -750,6 +753,8 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
</div>
</div>
{hardware.source === "agent" && <ServerTrends serverId={serverId} />}
<ServerPorts
serverId={serverId}
addresses={[...ipAddresses, ...(server.hostname && !ipAddresses.includes(server.hostname) ? [server.hostname] : [])]}
+119
View File
@@ -145,6 +145,125 @@ html[data-env] .navbar-vertical {
background: color-mix(in srgb, currentColor 14%, transparent);
}
/* ── Status badges carry a symbol as well as a colour, so red, amber and green never have to be told apart by colour alone. ── */
.badge.bg-green-lt:not(:empty)::before,
.badge.bg-red-lt:not(:empty)::before,
.badge.bg-yellow-lt:not(:empty)::before {
display: inline-block;
margin-right: 0.35em;
font-weight: 700;
}
.badge.bg-green-lt:not(:empty)::before {
content: "✓";
content: "✓" / "";
}
.badge.bg-red-lt:not(:empty)::before {
content: "✕";
content: "✕" / "";
}
.badge.bg-yellow-lt:not(:empty)::before {
content: "▲";
content: "▲" / "";
font-size: 0.75em;
vertical-align: 0.1em;
}
/* ── On a phone, wide tables become a stack of cards: each row a card, each cell labelled with its column (data-label is set by useStackedTables). ── */
@media (max-width: 767.98px) {
.card > .table-responsive {
overflow: visible;
}
.card-table,
.card-table tbody,
.card-table tr {
display: block;
width: 100%;
}
.card-table thead {
display: none;
}
.card-table tbody tr {
padding: 0.5rem 0.9rem;
border-bottom: 1px solid var(--tblr-border-color);
}
.card-table tbody tr:last-child {
border-bottom: 0;
}
.card-table tbody td {
position: relative;
display: block;
min-height: 1.5rem;
padding: 0.25rem 0 0.25rem 40% !important;
overflow-wrap: anywhere;
text-align: left;
border: 0 !important;
}
.card-table tbody td[data-label]::before {
position: absolute;
top: 0.3rem;
left: 0;
width: 36%;
padding-right: 0.5rem;
font-size: 0.72rem;
font-weight: 600;
color: var(--tblr-secondary);
text-transform: uppercase;
letter-spacing: 0.04em;
content: attr(data-label);
}
/* Cells with no heading (a tick-box, the action buttons, a "nothing here" row) use the whole width. */
.card-table tbody td:not([data-label]) {
padding-left: 0 !important;
}
}
/* ── Trends on a server's page: a label, a small line, the latest figure, and a few words about where it is heading. ── */
.trend-row {
display: grid;
grid-template-columns: 9rem minmax(8rem, 14rem) 3.5rem 1fr;
align-items: center;
gap: 0.75rem;
padding: 0.4rem 0;
border-bottom: 1px solid var(--tblr-border-color);
}
.trend-row:last-child {
border-bottom: 0;
}
.trend-now {
font-weight: 600;
text-align: right;
}
.sparkline {
display: block;
width: 100%;
height: 2.25rem;
color: var(--tblr-secondary);
}
@media (max-width: 767.98px) {
.trend-row {
grid-template-columns: 1fr 3.5rem;
}
.trend-row .sparkline,
.trend-row .trend-words {
grid-column: 1 / -1;
}
}
/* Sidebar submenus: a little tighter than Tabler's dropdown rows, so several open groups still fit on one screen. */
.navbar-vertical .dropdown-menu .dropdown-item {
padding-top: 0.3rem;
+32
View File
@@ -0,0 +1,32 @@
import { useEffect, useSyncExternalStore } from "react";
// The last step of the breadcrumb on a page about one particular thing ("Infrastructure › Servers › elsa"). The pages that know
// the name — a server's detail page — set it with useBreadcrumbTail(); the shell draws the rest from the menu.
let tail: string | null = null;
const listeners = new Set<() => void>();
function set(next: string | null) {
if (next === tail) return;
tail = next;
for (const l of listeners) l();
}
function subscribe(listener: () => void): () => void {
listeners.add(listener);
return () => {
listeners.delete(listener);
};
}
export function useBreadcrumbTailValue(): string | null {
return useSyncExternalStore(subscribe, () => tail);
}
/** Names the thing this page is about, for the breadcrumb. Pass nothing (or undefined) until it is known. */
export function useBreadcrumbTail(name: string | null | undefined): void {
useEffect(() => {
set(name ?? null);
return () => set(null);
}, [name]);
}