- Runbooks: notes per server/integration, shown next to matching alerts - Backup coverage page across Proxmox and PBS, with a digest section - Hardware inventory with warranty, power and running cost - Authentik group to role mapping with preview and safeguards - /metrics (bearer token) and signed outgoing event webhooks - Docs: README, DATABASE, NOTIFICATIONS, ROLES and new API.md Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { useEffect, useSyncExternalStore } from "react";
|
|
import { api, type RunbookSummary } from "../api/client";
|
|
|
|
// The list of runbook titles, by what they are about — shared by every page that shows a "runbook" button, fetched once, and fetched
|
|
// again whenever one is added, changed or removed (RUNBOOKS_CHANGED).
|
|
export const RUNBOOKS_CHANGED = "runbooks-changed";
|
|
|
|
let items: RunbookSummary[] | null = null;
|
|
let loading = false;
|
|
const listeners = new Set<() => void>();
|
|
|
|
function load(force = false): void {
|
|
if (loading || (items !== null && !force)) return;
|
|
loading = true;
|
|
api.runbooks
|
|
.summary()
|
|
.then((res) => {
|
|
items = res.runbooks;
|
|
listeners.forEach((l) => l());
|
|
})
|
|
.catch(() => {
|
|
// Only a convenience on top of the pages: without it they simply show no runbook buttons.
|
|
})
|
|
.finally(() => {
|
|
loading = false;
|
|
});
|
|
}
|
|
|
|
if (typeof window !== "undefined") window.addEventListener(RUNBOOKS_CHANGED, () => load(true));
|
|
|
|
function subscribe(listener: () => void): () => void {
|
|
listeners.add(listener);
|
|
return () => {
|
|
listeners.delete(listener);
|
|
};
|
|
}
|
|
|
|
/** Every runbook's title and what it is for; null until loaded. */
|
|
export function useRunbookSummary(): RunbookSummary[] | null {
|
|
useEffect(() => load(), []);
|
|
return useSyncExternalStore(subscribe, () => items);
|
|
}
|