- Table search, status, tag and sort live in the address; Save view pins one as a favourite. - Dashboard cards can be moved and hidden per user (users.dashboard_layout, migration 0022). - Compare two to four servers' load, memory or disk on one chart. - j/k move through table rows that open a detail panel. - Share links open a read-only wall without signing in, numbers only or with names (share_links, migration 0023); the wall is split into a shared view over two data sources. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
102 lines
4.4 KiB
TypeScript
102 lines
4.4 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { Link, useNavigate } from "react-router-dom";
|
|
import { api, type IntegrationSummary, type MaintenanceWindow, type ServerSummary } from "../api/client";
|
|
import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport";
|
|
import { useEnvironment } from "../utils/environment";
|
|
import WallView, { REFRESH_MS, wallHeadline, type WallData } from "../components/WallView";
|
|
|
|
/**
|
|
* A full-screen status board for a spare monitor or tablet: how things are, in type big enough to read across a room, refreshing
|
|
* by itself. Nothing on it can be clicked into, so it can be left alone; Esc (or the corner link) goes back to the app.
|
|
*/
|
|
export default function Wall() {
|
|
const navigate = useNavigate();
|
|
const environment = useEnvironment();
|
|
const { report, failed, reload } = useAlertsReport();
|
|
const [servers, setServers] = useState<ServerSummary | null>(null);
|
|
const [integrations, setIntegrations] = useState<IntegrationSummary[] | null>(null);
|
|
const [windows, setWindows] = useState<MaintenanceWindow[]>([]);
|
|
const [updatedAt, setUpdatedAt] = useState<Date | null>(null);
|
|
const [idle, setIdle] = useState(false);
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
const load = () => {
|
|
reload();
|
|
Promise.allSettled([api.servers.summary(), api.integrations.list(), api.maintenance.list()]).then(([s, i, m]) => {
|
|
if (!alive) return;
|
|
if (s.status === "fulfilled") setServers(s.value);
|
|
if (i.status === "fulfilled") setIntegrations(i.value.integrations);
|
|
if (m.status === "fulfilled") setWindows(m.value.windows);
|
|
setUpdatedAt(new Date());
|
|
});
|
|
};
|
|
load();
|
|
const t = setInterval(load, REFRESH_MS);
|
|
return () => {
|
|
alive = false;
|
|
clearInterval(t);
|
|
};
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
// Esc leaves; the pointer hides itself when nobody is using it.
|
|
useEffect(() => {
|
|
const onKey = (e: KeyboardEvent) => e.key === "Escape" && !document.fullscreenElement && navigate("/");
|
|
let timer: ReturnType<typeof setTimeout>;
|
|
const onMove = () => {
|
|
setIdle(false);
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => setIdle(true), 5000);
|
|
};
|
|
onMove();
|
|
window.addEventListener("keydown", onKey);
|
|
window.addEventListener("mousemove", onMove);
|
|
return () => {
|
|
window.removeEventListener("keydown", onKey);
|
|
window.removeEventListener("mousemove", onMove);
|
|
clearTimeout(timer);
|
|
};
|
|
}, [navigate]);
|
|
|
|
const badge = alertBadge(report);
|
|
const blind = report?.couldntCheck.length ?? 0;
|
|
const level: WallData["level"] = !report ? "unsure" : badge ? badge.level : blind > 0 ? "unsure" : "ok";
|
|
const active = (report?.alerts ?? []).filter((a) => !a.silenced && a.severity !== "info").sort((a, b) => (a.severity === b.severity ? 0 : a.severity === "critical" ? -1 : 1));
|
|
const failing = (integrations ?? []).filter((i) => i.enabled && i.health?.status === "failing");
|
|
|
|
const data: WallData = {
|
|
level,
|
|
headline: wallHeadline(level, badge?.count ?? 0, { loaded: !!report, failed }),
|
|
servers: servers ? { online: servers.online, total: servers.online + servers.offline.length } : null,
|
|
alerts: report ? { critical: report.counts.critical, warning: report.counts.warning } : null,
|
|
maintenance: windows.length,
|
|
integrationsFailing: integrations ? failing.length : null,
|
|
problems: active.map((a) => ({ id: a.id, severity: a.severity as "critical" | "warning", message: a.message })),
|
|
windows: windows.map((w) => ({ id: w.id, name: w.targetName, endsAt: w.endsAt })),
|
|
integrations: (integrations ?? [])
|
|
.filter((i) => i.enabled)
|
|
.sort((a, b) => Number(b.health?.status === "failing") - Number(a.health?.status === "failing") || a.name.localeCompare(b.name))
|
|
.map((i) => ({ id: i.id, name: i.name, type: i.type, status: i.health?.status === "failing" ? "failing" : i.health?.status === "ok" ? "ok" : "unknown" })),
|
|
environmentName: environment?.name || null,
|
|
updatedAt,
|
|
};
|
|
|
|
return (
|
|
<WallView
|
|
data={data}
|
|
idle={idle}
|
|
footerActions={
|
|
<>
|
|
<button type="button" className="wall-link" onClick={() => void document.documentElement.requestFullscreen?.().catch(() => {})}>
|
|
Full screen
|
|
</button>
|
|
<Link to="/" className="wall-link">
|
|
Exit (Esc)
|
|
</Link>
|
|
</>
|
|
}
|
|
/>
|
|
);
|
|
}
|