Add rotation to the wall display: overview, what needs attention, and one page per group of integrations
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fa7cc282bb
commit
d980c12a04
8 files changed
+398
-4
No files matched your search
@@ -2,6 +2,7 @@ import { useEffect, useState, type ReactNode } from "react";
|
||||
import type { WallGroup, WallTile } from "../api/client";
|
||||
import { formatDate, formatTime } from "../utils/date";
|
||||
import { formatRemaining } from "../utils/duration";
|
||||
import { groupMembers, pageOrOverview, ROTATE_CHOICES, stepPage, wallPages } from "../utils/wallPages";
|
||||
|
||||
export const REFRESH_MS = 30_000;
|
||||
|
||||
@@ -108,9 +109,49 @@ function useWakeLock() {
|
||||
* The board itself: a full-screen status picture in type big enough to read across a room. It only draws what it is given, so the
|
||||
* signed-in wall and the one a share link opens look the same and can't drift apart.
|
||||
*/
|
||||
export default function WallView({ data, idle, footerActions }: { data: WallData; idle: boolean; footerActions: ReactNode }) {
|
||||
export default function WallView({
|
||||
data,
|
||||
idle,
|
||||
footerActions,
|
||||
rotation,
|
||||
}: {
|
||||
data: WallData;
|
||||
idle: boolean;
|
||||
footerActions: ReactNode;
|
||||
/** How the pages rotate (seconds each, null for the overview alone) and how to change it; absent on a board that does not rotate. */
|
||||
rotation?: { seconds: number | null; onChange: (seconds: number | null) => void };
|
||||
}) {
|
||||
const now = useClock();
|
||||
useWakeLock();
|
||||
|
||||
// The pages: the overview, what needs attention (while something does), and one for each group of integrations.
|
||||
const rotating = !!rotation && rotation.seconds !== null;
|
||||
const pages = wallPages(data);
|
||||
const pagesKey = pages.map((p) => p.id).join(",");
|
||||
const [pageId, setPageId] = useState("overview");
|
||||
const [paused, setPaused] = useState(false);
|
||||
const page = rotating ? pageOrOverview(pages, pageId) : pages[0];
|
||||
const seconds = rotation?.seconds ?? null;
|
||||
useEffect(() => {
|
||||
if (!rotating || paused || pages.length < 2 || seconds === null) return;
|
||||
const t = setTimeout(() => setPageId(stepPage(pages, page.id, 1).id), seconds * 1000);
|
||||
return () => clearTimeout(t);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [rotating, paused, seconds, page.id, pagesKey]);
|
||||
// The arrow keys step through the pages by hand (and start the wait again).
|
||||
useEffect(() => {
|
||||
if (!rotating) return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
const el = e.target as HTMLElement | null;
|
||||
if (el && (el.tagName === "SELECT" || el.tagName === "INPUT")) return;
|
||||
if (e.key === "ArrowRight") setPageId(stepPage(pages, page.id, 1).id);
|
||||
else if (e.key === "ArrowLeft") setPageId(stepPage(pages, page.id, -1).id);
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [rotating, page.id, pagesKey]);
|
||||
|
||||
const { level } = data;
|
||||
const offline = data.servers ? data.servers.total - data.servers.online : 0;
|
||||
const alertCount = data.alerts ? data.alerts.critical + data.alerts.warning : 0;
|
||||
@@ -161,7 +202,10 @@ export default function WallView({ data, idle, footerActions }: { data: WallData
|
||||
))}
|
||||
</section>
|
||||
|
||||
{(data.groups ?? []).length > 0 && (
|
||||
{page.kind === "alerts" && <AlertsPage data={data} now={now} />}
|
||||
{page.kind === "group" && <GroupPage data={data} groupId={page.groupId ?? ""} label={page.label} />}
|
||||
|
||||
{page.kind === "overview" && (data.groups ?? []).length > 0 && (
|
||||
<section className="wall-groups" aria-label="By area">
|
||||
{(data.groups ?? []).map((g) => {
|
||||
const alerts = g.alerts.critical + g.alerts.warning;
|
||||
@@ -177,7 +221,7 @@ export default function WallView({ data, idle, footerActions }: { data: WallData
|
||||
</section>
|
||||
)}
|
||||
|
||||
{showsDetail ? (
|
||||
{page.kind !== "overview" ? null : showsDetail ? (
|
||||
<section className="wall-columns">
|
||||
<div>
|
||||
{data.problems && (
|
||||
@@ -243,9 +287,116 @@ export default function WallView({ data, idle, footerActions }: { data: WallData
|
||||
<footer className="wall-footer">
|
||||
<span>
|
||||
{data.updatedAt ? `Updated ${formatTime(data.updatedAt)}` : "Loading…"} · refreshes every {REFRESH_MS / 1000} s
|
||||
{rotating && pages.length > 1 && (
|
||||
<span className="wall-pager" aria-label={`Page ${pages.findIndex((p) => p.id === page.id) + 1} of ${pages.length}: ${page.label}`}>
|
||||
{" "}
|
||||
· {page.label}{" "}
|
||||
{pages.map((p) => (
|
||||
<span key={p.id} aria-hidden="true" className={p.id === page.id ? "wall-pager-on" : ""}>
|
||||
{p.id === page.id ? "●" : "○"}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="wall-footer-actions">
|
||||
{rotation && pages.length > 1 && (
|
||||
<>
|
||||
<label className="wall-rotate">
|
||||
Rotate{" "}
|
||||
<select
|
||||
aria-label="Rotate through the pages every"
|
||||
value={rotation.seconds === null ? "off" : String(rotation.seconds)}
|
||||
onChange={(e) => {
|
||||
setPaused(false);
|
||||
setPageId("overview");
|
||||
rotation.onChange(e.target.value === "off" ? null : Number(e.target.value));
|
||||
}}
|
||||
>
|
||||
<option value="off">off</option>
|
||||
{[...new Set([...ROTATE_CHOICES, ...(rotation.seconds !== null ? [rotation.seconds] : [])])]
|
||||
.sort((a, b) => a - b)
|
||||
.map((s) => (
|
||||
<option key={s} value={s}>
|
||||
every {s} s
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{rotating && pages.length > 1 && (
|
||||
<button type="button" className="wall-link" onClick={() => setPaused((p) => !p)} aria-pressed={paused}>
|
||||
{paused ? "Resume" : "Pause"}
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{footerActions}
|
||||
</span>
|
||||
<span className="wall-footer-actions">{footerActions}</span>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** What needs attention, in the whole screen's type: the open alerts, and what is in maintenance. */
|
||||
function AlertsPage({ data, now }: { data: WallData; now: Date }) {
|
||||
const problems = data.problems ?? [];
|
||||
const alertCount = data.alerts ? data.alerts.critical + data.alerts.warning : problems.length;
|
||||
const shown = problems.slice(0, 12);
|
||||
return (
|
||||
<section className="wall-page" aria-label="Needs attention">
|
||||
<h2 className="wall-heading">Needs attention</h2>
|
||||
<ul className="wall-list wall-list-cols">
|
||||
{shown.map((a) => (
|
||||
<li key={a.id} className={a.severity === "critical" ? "wall-bad" : "wall-warn"}>
|
||||
<span aria-hidden="true">{a.severity === "critical" ? "✕" : "▲"}</span> <span className="visually-hidden">{a.severity}: </span>
|
||||
{a.message}
|
||||
</li>
|
||||
))}
|
||||
{alertCount > shown.length && <li className="wall-more">and {alertCount - shown.length} more</li>}
|
||||
</ul>
|
||||
{data.windows && data.windows.length > 0 && (
|
||||
<>
|
||||
<h2 className="wall-heading mt-4">In maintenance</h2>
|
||||
<ul className="wall-list wall-list-small wall-list-cols">
|
||||
{data.windows.slice(0, 8).map((w) => (
|
||||
<li key={w.id}>
|
||||
{w.name} <span className="wall-dim">· {formatRemaining(w.endsAt, now.getTime())} left</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
/** One group of integrations (Infrastructure, Apps …): how it is, and each of them with its status. */
|
||||
function GroupPage({ data, groupId, label }: { data: WallData; groupId: string; label: string }) {
|
||||
const members = groupMembers(data.integrations ?? [], groupId);
|
||||
const summary = (data.groups ?? []).find((g) => g.id === groupId);
|
||||
const alerts = summary ? summary.alerts.critical + summary.alerts.warning : 0;
|
||||
const failing = members.filter((m) => m.status === "failing").length;
|
||||
const level = failing > 0 || (summary?.alerts.critical ?? 0) > 0 ? "bad" : alerts > 0 ? "warn" : "ok";
|
||||
return (
|
||||
<section className="wall-page" aria-label={label}>
|
||||
<h2 className="wall-heading">
|
||||
{label}{" "}
|
||||
<span className={`wall-group-${level}`}>
|
||||
<span aria-hidden="true">{level === "bad" ? "✕" : level === "warn" ? "▲" : "✓"}</span>{" "}
|
||||
{failing > 0 ? `${failing} of ${members.length} failing` : `${members.length} connected`}
|
||||
{alerts > 0 ? ` · ${alerts} ${alerts === 1 ? "alert" : "alerts"}` : ""}
|
||||
</span>
|
||||
</h2>
|
||||
<ul className="wall-list wall-list-cols">
|
||||
{members.map((i) => (
|
||||
<li key={i.id} className={i.status === "failing" ? "wall-bad" : i.status === "ok" ? "wall-good" : "wall-dim"}>
|
||||
<span aria-hidden="true">{i.status === "failing" ? "✕" : i.status === "ok" ? "✓" : "·"}</span> {i.name}{" "}
|
||||
<span className="wall-dim">
|
||||
{TYPE_LABELS[i.type] ?? i.type} — {i.status === "failing" ? "failing" : i.status === "ok" ? "working" : "not checked yet"}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user