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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useCallback } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { rotateSeconds } from "../utils/wallPages";
|
||||
|
||||
const KEY = "wall.rotate";
|
||||
|
||||
function stored(): string | null {
|
||||
try {
|
||||
return localStorage.getItem(KEY);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How the wall display rotates: how many seconds each page stays, or null for the overview alone. It lives in the address (`?rotate=30`),
|
||||
* so a TV's bookmark carries it, and this browser remembers the last choice made on the board itself.
|
||||
*/
|
||||
export function useWallRotation() {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const seconds = rotateSeconds(params.get("rotate"), stored());
|
||||
const setSeconds = useCallback(
|
||||
(next: number | null) => {
|
||||
try {
|
||||
localStorage.setItem(KEY, next === null ? "off" : String(next));
|
||||
} catch {
|
||||
/* a private window: the address alone carries it */
|
||||
}
|
||||
setParams(
|
||||
(prev) => {
|
||||
const p = new URLSearchParams(prev);
|
||||
p.set("rotate", next === null ? "off" : String(next));
|
||||
return p;
|
||||
},
|
||||
{ replace: true },
|
||||
);
|
||||
},
|
||||
[setParams],
|
||||
);
|
||||
return { seconds, setSeconds };
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { useParams } from "react-router-dom";
|
||||
import { api, type PublicWall } from "../api/client";
|
||||
import WallView, { REFRESH_MS, wallHeadline, type WallData } from "../components/WallView";
|
||||
import { setDateTimeSettings } from "../utils/date";
|
||||
import { useWallRotation } from "../hooks/useWallRotation";
|
||||
|
||||
/**
|
||||
* The wall display behind a share link: the same board, read-only and without signing in. The address carries the secret, and the
|
||||
@@ -15,6 +16,7 @@ export default function SharedWall() {
|
||||
const [state, setState] = useState<"loading" | "ok" | "dead" | "unreachable">("loading");
|
||||
const [updatedAt, setUpdatedAt] = useState<Date | null>(null);
|
||||
const [idle, setIdle] = useState(false);
|
||||
const rotation = useWallRotation();
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
@@ -101,6 +103,7 @@ export default function SharedWall() {
|
||||
<WallView
|
||||
data={data}
|
||||
idle={idle}
|
||||
rotation={{ seconds: rotation.seconds, onChange: rotation.setSeconds }}
|
||||
footerActions={
|
||||
<button type="button" className="wall-link" onClick={() => void document.documentElement.requestFullscreen?.().catch(() => {})}>
|
||||
Full screen
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Link, useNavigate } from "react-router-dom";
|
||||
import { api, type IntegrationSummary, type MaintenanceWindow, type ServerSummary, type WallGroup, type WallTile } from "../api/client";
|
||||
import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport";
|
||||
import { useEnvironment } from "../utils/environment";
|
||||
import { useWallRotation } from "../hooks/useWallRotation";
|
||||
import WallView, { REFRESH_MS, wallHeadline, type WallData } from "../components/WallView";
|
||||
|
||||
/**
|
||||
@@ -19,6 +20,7 @@ export default function Wall() {
|
||||
const [extras, setExtras] = useState<{ tiles: WallTile[]; groups: WallGroup[] } | null>(null);
|
||||
const [updatedAt, setUpdatedAt] = useState<Date | null>(null);
|
||||
const [idle, setIdle] = useState(false);
|
||||
const rotation = useWallRotation();
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
@@ -91,6 +93,7 @@ export default function Wall() {
|
||||
<WallView
|
||||
data={data}
|
||||
idle={idle}
|
||||
rotation={{ seconds: rotation.seconds, onChange: rotation.setSeconds }}
|
||||
footerActions={
|
||||
<>
|
||||
<button type="button" className="wall-link" onClick={() => void document.documentElement.requestFullscreen?.().catch(() => {})}>
|
||||
|
||||
@@ -963,6 +963,35 @@ main:focus {
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.wall-list-cols {
|
||||
columns: 2 22em;
|
||||
column-gap: clamp(1rem, 3vw, 3rem);
|
||||
}
|
||||
|
||||
.wall-list-cols li {
|
||||
break-inside: avoid;
|
||||
}
|
||||
|
||||
.wall-rotate select {
|
||||
padding: 0 0.25rem;
|
||||
color: inherit;
|
||||
background: transparent;
|
||||
border: 1px solid rgb(255 255 255 / 0.3);
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.wall-rotate option {
|
||||
color: #0b1220;
|
||||
}
|
||||
|
||||
.wall-pager {
|
||||
letter-spacing: 0.15em;
|
||||
}
|
||||
|
||||
.wall-pager-on {
|
||||
color: #e6edf7;
|
||||
}
|
||||
|
||||
.wall-link {
|
||||
padding: 0 0.5rem;
|
||||
color: inherit;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import type { IntegrationType } from "../api/client";
|
||||
import { groupOfType, TYPE_GROUPS } from "./integrationTypes";
|
||||
|
||||
/** One screen of the rotating wall display: the overview, the list of what needs attention, or one group of integrations. */
|
||||
export interface WallPage {
|
||||
id: string;
|
||||
/** What the footer calls it. */
|
||||
label: string;
|
||||
kind: "overview" | "alerts" | "group";
|
||||
groupId?: string;
|
||||
}
|
||||
|
||||
export interface WallPagesInput {
|
||||
/** Null on a board that shows numbers only (it has no names to put on a page). */
|
||||
problems: unknown[] | null;
|
||||
integrations: { type: string }[] | null;
|
||||
}
|
||||
|
||||
/** The longest and shortest a page may stay, in seconds. */
|
||||
export const ROTATE_MIN = 10;
|
||||
export const ROTATE_MAX = 600;
|
||||
export const ROTATE_DEFAULT = 30;
|
||||
|
||||
/** The choices the footer offers; an address may ask for any number in range. */
|
||||
export const ROTATE_CHOICES = [15, 30, 60, 120];
|
||||
|
||||
/**
|
||||
* Pure: the pages a board can rotate through, from what it has to show — always the overview first; then what needs attention (only
|
||||
* while something does); then one page for each group of integrations that has any, in the order of the menu. A board that shows numbers
|
||||
* only has just the overview, since there is nothing by name to put on another page.
|
||||
*/
|
||||
export function wallPages(d: WallPagesInput): WallPage[] {
|
||||
const pages: WallPage[] = [{ id: "overview", label: "Overview", kind: "overview" }];
|
||||
if (d.problems && d.problems.length > 0) pages.push({ id: "alerts", label: "Needs attention", kind: "alerts" });
|
||||
if (d.integrations) {
|
||||
const present = new Set(d.integrations.map((i) => groupOfType(i.type as IntegrationType).id));
|
||||
const order = [...TYPE_GROUPS.map((g) => ({ id: g.id, label: g.label })), { id: "other", label: "Other" }];
|
||||
for (const g of order) if (present.has(g.id)) pages.push({ id: `group:${g.id}`, label: g.label, kind: "group", groupId: g.id });
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
/** Pure: the page `step` places on from the current one (wrapping round); a page that is gone (its alerts cleared) sends it to the overview. */
|
||||
export function stepPage(pages: WallPage[], currentId: string, step: number): WallPage {
|
||||
const at = pages.findIndex((p) => p.id === currentId);
|
||||
if (at < 0) return pages[0];
|
||||
return pages[(((at + step) % pages.length) + pages.length) % pages.length];
|
||||
}
|
||||
|
||||
/** Pure: whether the page still exists in the list — a page whose reason went away is replaced by the overview. */
|
||||
export function pageOrOverview(pages: WallPage[], currentId: string): WallPage {
|
||||
return pages.find((p) => p.id === currentId) ?? pages[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pure: how long each page stays, in seconds, or null for no rotation. The address wins (`?rotate=45`; `?rotate=on` for the default; `?rotate=off`),
|
||||
* then what this browser last chose, else no rotation. A number out of range is brought into it; anything else means off.
|
||||
*/
|
||||
export function rotateSeconds(param: string | null, stored: string | null): number | null {
|
||||
const read = (v: string | null): number | null | undefined => {
|
||||
if (v === null || v === "") return undefined;
|
||||
const t = v.trim().toLowerCase();
|
||||
if (t === "on" || t === "true" || t === "1") return ROTATE_DEFAULT;
|
||||
if (t === "off" || t === "false" || t === "0") return null;
|
||||
if (!/^\d{1,5}$/.test(t)) return null;
|
||||
return Math.min(ROTATE_MAX, Math.max(ROTATE_MIN, Number(t)));
|
||||
};
|
||||
const fromAddress = read(param);
|
||||
if (fromAddress !== undefined) return fromAddress;
|
||||
return read(stored) ?? null;
|
||||
}
|
||||
|
||||
/** Pure: a group's integrations for its page — the failing ones first, then by name. */
|
||||
export function groupMembers<T extends { type: string; name: string; status: string }>(integrations: T[], groupId: string): T[] {
|
||||
return integrations
|
||||
.filter((i) => groupOfType(i.type as IntegrationType).id === groupId)
|
||||
.sort((a, b) => Number(b.status === "failing") - Number(a.status === "failing") || a.name.localeCompare(b.name));
|
||||
}
|
||||
Reference in new issue
Block a user