Add a since-you-last-looked summary, 30-day uptime ribbons, a maintenance timeline and hover timestamps

- Dashboard card on what changed since the user pressed Got it (users.last_looked_at,
  migration 0021), folding each problem and its recovery into one line.
- Uptime ribbons on servers and integrations, built from the audit log; integrations'
  failing/working-again moments are now recorded.
- Timeline of running and scheduled maintenance windows on the Maintenance page.
- TimeAgo component: relative times with the exact time in the chosen format on hover.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-16 21:55:04 +02:00
1 parent 3945c60681
commit 906220040e
32 files changed
+3380 -15

No files matched your search

+161
View File
@@ -0,0 +1,161 @@
import { useMemo, useState } from "react";
import type { MaintenanceWindow } from "../api/client";
import { formatDate, formatDateTime, formatTime } from "../utils/date";
const HOUR = 3600_000;
const DAY = 24 * HOUR;
const RANGES = [
{ key: "24h", label: "Next 24 hours", span: DAY, tickEvery: 3 * HOUR },
{ key: "7d", label: "Next 7 days", span: 7 * DAY, tickEvery: DAY },
{ key: "30d", label: "Next 30 days", span: 30 * DAY, tickEvery: 5 * DAY },
] as const;
interface Span {
from: number;
to: number;
}
/** Overlapping or touching spans folded into the stretches during which at least one is running. */
function union(spans: Span[]): Span[] {
const sorted = [...spans].sort((a, b) => a.from - b.from);
const out: Span[] = [];
for (const s of sorted) {
const last = out[out.length - 1];
if (last && s.from <= last.to) last.to = Math.max(last.to, s.to);
else out.push({ ...s });
}
return out;
}
/**
* The running and scheduled windows laid out along a time axis, one row per server, integration or DNS provider, plus a top row for
* "anything at all in maintenance". It shows what a list can't: which windows overlap, and where there are gaps. The tables further
* down the page hold the same windows for reading and for ending them, so this is a picture only.
*/
export default function MaintenanceTimeline({ windows, now }: { windows: MaintenanceWindow[]; now: number }) {
const [rangeKey, setRangeKey] = useState<(typeof RANGES)[number]["key"]>("7d");
const range = RANGES.find((r) => r.key === rangeKey)!;
const start = now;
const end = now + range.span;
const { rows, everything, further } = useMemo(() => {
const inRange = windows.filter((w) => Date.parse(w.endsAt) > start && Date.parse(w.startedAt) < end);
const byTarget = new Map<string, { name: string; kind: string; windows: MaintenanceWindow[] }>();
for (const w of inRange) {
const key = `${w.targetType}:${w.targetId}`;
const row = byTarget.get(key) ?? { name: w.targetName, kind: w.targetKind, windows: [] };
row.windows.push(w);
byTarget.set(key, row);
}
return {
rows: [...byTarget.values()].sort((a, b) => a.name.localeCompare(b.name)),
everything: union(inRange.map((w) => ({ from: Math.max(Date.parse(w.startedAt), start), to: Math.min(Date.parse(w.endsAt), end) }))),
further: windows.length - inRange.length,
};
}, [windows, start, end]);
const pct = (t: number) => ((Math.min(Math.max(t, start), end) - start) / range.span) * 100;
const bar = (from: number, to: number) => ({ left: `${pct(from)}%`, width: `${Math.max(pct(to) - pct(from), 0.6)}%` });
const ticks: number[] = [];
// First tick at the next whole step after now (the next midnight for day steps), so labels land on round times.
const stepStart = new Date(now);
if (range.tickEvery >= DAY) stepStart.setHours(24, 0, 0, 0);
else {
stepStart.setMinutes(0, 0, 0);
const hours = range.tickEvery / HOUR;
stepStart.setHours(Math.floor(stepStart.getHours() / hours) * hours);
}
for (let t = stepStart.getTime(); t < end; t += range.tickEvery) if (t > start) ticks.push(t);
const tickLabel = (t: number) => (range.tickEvery >= DAY ? formatDate(new Date(t)).replace(/^\d{4}-|\/\d{4}$/, "") : formatTime(new Date(t), false));
return (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Timeline</h3>
<div className="card-actions">
<div className="btn-group btn-group-sm" role="group" aria-label="Time range">
{RANGES.map((r) => (
<button key={r.key} type="button" className={`btn btn-sm ${r.key === rangeKey ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={r.key === rangeKey} onClick={() => setRangeKey(r.key)}>
{r.label}
</button>
))}
</div>
</div>
</div>
<div className="card-body">
{rows.length === 0 ? (
<div className="text-secondary">Nothing running or scheduled in this time.{further > 0 ? ` ${further} further ahead.` : ""}</div>
) : (
<>
<div className="timeline-scroll" aria-hidden="true">
<div className="timeline">
<div className="timeline-row timeline-axis">
<div className="timeline-label text-secondary">From now</div>
<div className="timeline-track">
{ticks.map((t) => (
<span key={t} className="timeline-tick" style={{ left: `${pct(t)}%` }}>
{tickLabel(t)}
</span>
))}
</div>
</div>
<div className="timeline-row timeline-union">
<div className="timeline-label fw-bold">Anything</div>
<div className="timeline-track">
{ticks.map((t) => (
<span key={t} className="timeline-grid" style={{ left: `${pct(t)}%` }} />
))}
{everything.map((s, i) => (
<span key={i} className="timeline-bar timeline-bar-union" style={bar(s.from, s.to)} title={`${formatDateTime(new Date(s.from))} – ${formatDateTime(new Date(s.to))}`} />
))}
</div>
</div>
{rows.map((row) => (
<div key={row.name + row.kind} className="timeline-row">
<div className="timeline-label" title={`${row.name} · ${row.kind}`}>
{row.name}
</div>
<div className="timeline-track">
{ticks.map((t) => (
<span key={t} className="timeline-grid" style={{ left: `${pct(t)}%` }} />
))}
{row.windows.map((w) => {
const from = Date.parse(w.startedAt);
const to = Date.parse(w.endsAt);
const running = from <= now;
return (
<span
key={w.id}
className={`timeline-bar ${running ? "timeline-bar-running" : "timeline-bar-scheduled"} ${w.source ? "timeline-bar-mirrored" : ""}`}
style={bar(from, to)}
title={`${row.name}: ${formatDateTime(new Date(from))} – ${formatDateTime(new Date(to))}${w.reason ? ` · ${w.reason}` : ""}`}
/>
);
})}
</div>
</div>
))}
</div>
</div>
<div className="text-secondary small mt-2 d-flex flex-wrap gap-3 align-items-center">
<span>
<span className="timeline-key timeline-bar-running" /> Running
</span>
<span>
<span className="timeline-key timeline-bar-scheduled" /> Scheduled
</span>
<span>
<span className="timeline-key timeline-bar-mirrored" /> From Uptime Kuma
</span>
<span>The same windows are listed in the tables below.</span>
{further > 0 && <span>{further} further ahead than this range.</span>}
</div>
</>
)}
</div>
</div>
);
}
+45
View File
@@ -0,0 +1,45 @@
import { useSyncExternalStore } from "react";
import { formatDateTime, parseDbTimestamp } from "../utils/date";
import { formatAgo, formatRemaining } from "../utils/duration";
// One shared clock for every TimeAgo on screen: "5 min ago" moves on by itself without each one running its own timer.
const listeners = new Set<() => void>();
let tick = 0;
let timer: ReturnType<typeof setInterval> | undefined;
function subscribe(listener: () => void): () => void {
listeners.add(listener);
if (!timer) {
timer = setInterval(() => {
tick++;
listeners.forEach((l) => l());
}, 30_000);
}
return () => {
listeners.delete(listener);
if (listeners.size === 0 && timer) {
clearInterval(timer);
timer = undefined;
}
};
}
const getTick = () => tick;
/**
* A time as people say it ("5 min ago", "in 2 h"), with the exact date and time — in the format chosen under Settings → Display —
* as the hover text. `fromDb` is for the plain "2026-10-02 20:27:55" timestamps SQLite writes, which are UTC without saying so.
*/
export default function TimeAgo({ value, fromDb, empty = "—" }: { value: string | Date | null | undefined; fromDb?: boolean; empty?: string }) {
useSyncExternalStore(subscribe, getTick);
if (value === null || value === undefined || value === "") return <>{empty}</>;
const date = value instanceof Date ? value : fromDb ? parseDbTimestamp(value) : new Date(value);
if (Number.isNaN(date.getTime())) return <>{empty}</>;
const iso = date.toISOString();
const future = date.getTime() > Date.now() + 60_000;
return (
<time dateTime={iso} title={formatDateTime(date)}>
{future ? `in ${formatRemaining(iso)}` : formatAgo(iso)}
</time>
);
}
+43
View File
@@ -0,0 +1,43 @@
import { useUptime } from "../hooks/useUptime";
import { formatDate } from "../utils/date";
const DAY_MS = 24 * 3600_000;
function minutesLabel(minutes: number): string {
if (minutes < 60) return `${minutes} min`;
const h = Math.floor(minutes / 60);
return minutes % 60 && h < 10 ? `${h} h ${minutes % 60} min` : `${h} h`;
}
/**
* A thin strip of one bar per day for the last 30 days — green for a day with nothing wrong, amber for some time down, red for
* half the day or more, grey where nothing is known (before it was added, or before the app began keeping this) — with the share of
* time up beside it. The bars are for the eye; the percentage and the hover text carry the same information in words.
*/
export default function UptimeRibbon({ kind, id, name, showPercent = true }: { kind: "servers" | "integrations"; id: number; name: string; showPercent?: boolean }) {
const report = useUptime();
const series = report?.[kind][id];
if (!report || !series) return null;
const end = Date.parse(report.endsAt);
const summary = `${name}: ${series.percent}% up over the last ${report.days} days`;
return (
<span className="uptime" title={summary}>
<span className="uptime-ribbon" aria-hidden="true">
{series.buckets.map((b, i) => {
const start = new Date(end - (report.days - i) * DAY_MS);
const state = b.k === 0 ? "none" : b.d === 0 ? "up" : b.d / b.k >= 0.5 ? "down" : "some";
const text = b.k === 0 ? "no record" : b.d === 0 ? "up all day" : `down ${minutesLabel(b.d)}`;
return <i key={i} className={`uptime-${state}`} title={`${formatDate(start)}: ${text}`} />;
})}
</span>
{showPercent ? (
<span className="uptime-percent">
{series.percent}% <span className="visually-hidden">up over the last {report.days} days</span>
</span>
) : (
<span className="visually-hidden">{summary}</span>
)}
</span>
);
}
+101
View File
@@ -0,0 +1,101 @@
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { IconAlertTriangle, IconCircleCheck, IconPlugConnected, IconServer, IconTool } from "@tabler/icons-react";
import { api, type ChangeEvent, type ChangesSummary, type UserRole } from "../api/client";
import TimeAgo from "./TimeAgo";
import { toast } from "../utils/toast";
const TONE_CLASS: Record<ChangeEvent["tone"], string> = { good: "text-green", bad: "text-red", info: "text-blue", neutral: "text-secondary" };
function EventIcon({ event }: { event: ChangeEvent }) {
const cls = TONE_CLASS[event.tone];
if (event.kind === "maintenance") return <IconTool size={18} className={cls} aria-hidden="true" />;
if (event.tone === "bad") return <IconAlertTriangle size={18} className={cls} aria-hidden="true" />;
if (event.tone === "good") return <IconCircleCheck size={18} className={cls} aria-hidden="true" />;
return event.kind === "integration" ? <IconPlugConnected size={18} className={cls} aria-hidden="true" /> : <IconServer size={18} className={cls} aria-hidden="true" />;
}
/**
* What happened since this person last pressed "Got it": servers that stopped reporting, services that stopped answering, maintenance
* that began or ended. Nothing to say means nothing shown. The mark is theirs alone and follows them to any browser.
*/
export default function WhatChanged({ role }: { role: UserRole }) {
const [summary, setSummary] = useState<ChangesSummary | null>(null);
const [dismissed, setDismissed] = useState(false);
const [busy, setBusy] = useState(false);
useEffect(() => {
let alive = true;
api.me
.changes()
.then((s) => alive && setSummary(s))
.catch(() => {
// Only a nicety on the dashboard: if it can't load, the dashboard simply doesn't have it.
});
return () => {
alive = false;
};
}, []);
if (!summary || dismissed) return null;
const others = role !== "viewer" ? (summary.changesByOthers ?? 0) : 0;
if (summary.events.length === 0 && others === 0) return null;
async function gotIt() {
setBusy(true);
try {
await api.me.markChangesSeen();
setDismissed(true);
} catch {
toast.error("Couldn't save that. Try again.");
} finally {
setBusy(false);
}
}
return (
<section className="card mb-3" aria-label="Since you last looked">
<div className="card-header">
<div>
<h3 className="card-title">Since you last looked</h3>
<div className="text-secondary small">{summary.firstTime ? "In the last day" : <>Since <TimeAgo value={summary.since} /></>}</div>
</div>
<div className="card-actions">
<button type="button" className="btn btn-sm btn-primary" onClick={gotIt} disabled={busy}>
Got it
</button>
</div>
</div>
<div className="card-body">
{summary.events.length > 0 ? (
<ol className="activity-list">
{summary.events.map((e, i) => (
<li key={`${e.at}-${i}`}>
<EventIcon event={e} />
<div className="flex-fill" style={{ minWidth: 0 }}>
<div>{e.link ? <Link to={e.link}>{e.title}</Link> : e.title}</div>
{e.detail && <div className="text-secondary small">{e.detail}</div>}
</div>
<span className="text-secondary small text-nowrap">
<TimeAgo value={e.at} />
</span>
</li>
))}
</ol>
) : (
<div className="text-secondary">Nothing went wrong or came back.</div>
)}
{(summary.moreEvents > 0 || others > 0) && (
<div className="text-secondary small mt-2">
{summary.moreEvents > 0 && <>and {summary.moreEvents} more. </>}
{others > 0 && (
<>
{others} change{others === 1 ? "" : "s"} made by other people — <Link to="/audit-log">see the audit log</Link>.
</>
)}
</div>
)}
</div>
</section>
);
}