Dashboard status strip, "Not set up yet" list, sidebar badges and user menu
The dashboard opens with one line saying whether anything needs attention (from the same alert report as the Alerts page) and never claims "all clear" when some checks couldn't run. Widgets with nothing configured are listed once under "Not set up yet" instead of one grey card each. The sidebar shows the active alert count and open maintenance windows next to their pages (and on a closed group), and the foot of the sidebar is one user menu holding theme, privacy and sign-out. One shared alert poll serves the strip and the badge. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aab2f8cb4a
commit
7d56ad18b7
5 files changed
+369
-22
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import { useSyncExternalStore } from "react";
|
||||
import { api, type AlertsReport } from "../api/client";
|
||||
|
||||
/**
|
||||
* The current alert report, shared by everything on the page that shows it (the sidebar badge and the dashboard strip), so
|
||||
* one request every minute serves them all. The server keeps the result for a minute as well, so this costs no extra checks.
|
||||
*/
|
||||
interface State {
|
||||
report: AlertsReport | null;
|
||||
/** The last attempt failed (the previous report, if any, is kept). */
|
||||
failed: boolean;
|
||||
}
|
||||
|
||||
const POLL_MS = 60_000;
|
||||
|
||||
let state: State = { report: null, failed: false };
|
||||
const listeners = new Set<() => void>();
|
||||
let timer: ReturnType<typeof setInterval> | null = null;
|
||||
let inFlight = false;
|
||||
|
||||
function set(next: State) {
|
||||
state = next;
|
||||
for (const l of listeners) l();
|
||||
}
|
||||
|
||||
async function refresh(): Promise<void> {
|
||||
if (inFlight) return;
|
||||
inFlight = true;
|
||||
try {
|
||||
set({ report: await api.alerts.list(), failed: false });
|
||||
} catch {
|
||||
set({ report: state.report, failed: true });
|
||||
} finally {
|
||||
inFlight = false;
|
||||
}
|
||||
}
|
||||
|
||||
function subscribe(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
if (listeners.size === 1) {
|
||||
void refresh();
|
||||
timer = setInterval(() => void refresh(), POLL_MS);
|
||||
}
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
if (listeners.size === 0 && timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function useAlertsReport(): State & { reload: () => void } {
|
||||
const s = useSyncExternalStore(subscribe, () => state);
|
||||
return { ...s, reload: () => void refresh() };
|
||||
}
|
||||
|
||||
/** What the sidebar shows next to Alerts: how many problems are active, coloured by the worst one. Silenced and informational ones don't count. */
|
||||
export function alertBadge(report: AlertsReport | null): { count: number; level: "critical" | "warning" } | null {
|
||||
if (!report) return null;
|
||||
const count = report.counts.critical + report.counts.warning;
|
||||
if (count === 0) return null;
|
||||
return { count, level: report.counts.critical > 0 ? "critical" : "warning" };
|
||||
}
|
||||
Reference in new issue
Block a user