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

+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>
);
}