UniFi: the controller's client list is matched to servers by IP address, so a server is connected through a switch or access point (and port). That is a dependency made by itself, shown on the server page, the Network devices page and the Connections map. IP Addresses can sync the devices' addresses. A server's page is split into Overview, Health, Network, History, Tasks and Settings, by ?view=; alerts link to the section they are about. My work lists what has your name on it: alerts you have, maintenance you started (extend, end with undo) and update runs you started, with a badge. Settings has a search box (and the command palette lists every setting). Removing a dependency, admin link, runbook, hand-made IP address, port opening or restore test is undone from the message instead of asked about first. Two backup tests used a fixed date and failed as days passed; they follow the real clock now. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
242 lines
10 KiB
TypeScript
242 lines
10 KiB
TypeScript
import { useState } from "react";
|
|
import { Link } from "react-router-dom";
|
|
import { api, type AlertItem, type CurrentUser, type MyWork } from "../api/client";
|
|
import AckDrawer from "../components/AckDrawer";
|
|
import EmptyState from "../components/EmptyState";
|
|
import { BlockSkeleton } from "../components/Skeleton";
|
|
import TimeAgo from "../components/TimeAgo";
|
|
import { useAlertsReport } from "../hooks/useAlertsReport";
|
|
import { useMyWork } from "../hooks/useMyWork";
|
|
import { formatRemaining } from "../utils/duration";
|
|
import { readableError } from "../utils/errors";
|
|
import { toast } from "../utils/toast";
|
|
|
|
const SEVERITY: Record<string, string> = { critical: "bg-red-lt text-red", warning: "bg-yellow-lt text-yellow", info: "bg-blue-lt text-blue" };
|
|
|
|
type Win = MyWork["windows"][number];
|
|
|
|
/**
|
|
* Everything with your name on it, in one place: the alerts you have taken or been handed, the acknowledgements about to run out, the maintenance you started that
|
|
* is about to end, and the update runs you are following. What is about to run out is marked, and comes first.
|
|
*/
|
|
export default function MyWorkPage({ user }: { user: CurrentUser }) {
|
|
const { work, reload } = useMyWork();
|
|
const { report, reload: reloadAlerts } = useAlertsReport();
|
|
const [acking, setAcking] = useState<AlertItem | null>(null);
|
|
const [busy, setBusy] = useState<number | null>(null);
|
|
|
|
const alertById = new Map((report?.alerts ?? []).map((a) => [a.id, a]));
|
|
|
|
function changed() {
|
|
reload();
|
|
reloadAlerts();
|
|
window.dispatchEvent(new Event("maintenance-changed"));
|
|
}
|
|
|
|
/** Minutes from now that a window should last to end `extra` minutes later than it does now (the server restarts the clock from now). */
|
|
const minutesFor = (w: Win, extra: number) => Math.min(7 * 24 * 60, Math.max(5, Math.ceil((Date.parse(w.endsAt) - Date.now()) / 60_000)) + extra);
|
|
|
|
async function extend(w: Win, extra: number, words: string) {
|
|
setBusy(w.id);
|
|
try {
|
|
await api.maintenance.start({ targetType: w.targetType as never, targetId: w.targetId, minutes: minutesFor(w, extra), reason: w.reason ?? undefined });
|
|
toast.success(`${w.targetName}: ${words} more.`);
|
|
changed();
|
|
} catch (err) {
|
|
toast.error(readableError(err));
|
|
} finally {
|
|
setBusy(null);
|
|
}
|
|
}
|
|
|
|
async function end(w: Win) {
|
|
setBusy(w.id);
|
|
try {
|
|
await api.maintenance.end(w.id);
|
|
toast.success(`Maintenance on ${w.targetName} ended.`, {
|
|
label: "Undo",
|
|
onClick: async () => {
|
|
try {
|
|
await api.maintenance.start({ targetType: w.targetType as never, targetId: w.targetId, minutes: minutesFor(w, 0), reason: w.reason ?? undefined });
|
|
toast.info("Put back.");
|
|
} catch (err) {
|
|
toast.error(readableError(err));
|
|
} finally {
|
|
changed();
|
|
}
|
|
},
|
|
});
|
|
changed();
|
|
} catch (err) {
|
|
toast.error(readableError(err));
|
|
} finally {
|
|
setBusy(null);
|
|
}
|
|
}
|
|
|
|
const nothing = work !== null && work.alerts.length === 0 && work.windows.length === 0 && work.updateRuns.length === 0;
|
|
|
|
return (
|
|
<>
|
|
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
|
|
<h2 className="page-title mb-0">My work</h2>
|
|
</div>
|
|
<div className="text-secondary mb-3">
|
|
What has your name on it: alerts you acknowledged or were handed, maintenance you started and update runs you started. Whatever is about to run out is marked, and listed first.
|
|
</div>
|
|
|
|
{work === null && <BlockSkeleton lines={4} />}
|
|
|
|
{nothing && (
|
|
<div className="card">
|
|
<EmptyState title="Nothing on your plate" hint="When you acknowledge an alert, are handed one, put something under maintenance or start an update run, it is listed here until it is done." />
|
|
</div>
|
|
)}
|
|
|
|
{work && work.alerts.length > 0 && (
|
|
<div className="card mb-3">
|
|
<div className="card-header">
|
|
<h3 className="card-title">Alerts you have</h3>
|
|
</div>
|
|
<div className="table-responsive">
|
|
<table className="table table-vcenter card-table table-stack">
|
|
<tbody>
|
|
{work.alerts.map((a) => {
|
|
const full = alertById.get(a.alertId);
|
|
return (
|
|
<tr key={a.alertId}>
|
|
<td className="w-1">
|
|
<span className={`badge ${SEVERITY[a.severity] ?? ""}`}>{a.severity}</span>
|
|
</td>
|
|
<td className="stack-wide">
|
|
{a.link ? <Link to={a.link}>{a.message}</Link> : a.message}
|
|
<div className="small text-secondary">
|
|
{a.role === "handed" ? (a.ackedBy === (user.name ?? user.email ?? user.sub) ? "You took it" : `Handed to you by ${a.ackedBy}`) : "You acknowledged it"}
|
|
{a.note ? ` — ${a.note}` : ""}
|
|
</div>
|
|
</td>
|
|
<td className="stack-label text-nowrap" data-label="Lasts">
|
|
{a.until ? (
|
|
<span className={a.endsSoon ? "text-yellow" : "text-secondary"} title="When the acknowledgement runs out and the alert counts as nobody's again">
|
|
{a.endsSoon ? "Runs out " : "Until "}
|
|
<TimeAgo value={a.until} />
|
|
</span>
|
|
) : (
|
|
<span className="text-secondary">until the alert is gone</span>
|
|
)}
|
|
</td>
|
|
<td className="stack-wide text-nowrap">
|
|
<div className="btn-list flex-nowrap">
|
|
{full && (
|
|
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={() => setAcking(full)}>
|
|
Change…
|
|
</button>
|
|
)}
|
|
<Link to="/alerts" className="btn btn-sm btn-outline-secondary">
|
|
Alerts
|
|
</Link>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{work && work.windows.length > 0 && (
|
|
<div className="card mb-3">
|
|
<div className="card-header">
|
|
<h3 className="card-title">Maintenance you started</h3>
|
|
<div className="card-actions">
|
|
<Link to="/maintenance" className="small">
|
|
Maintenance
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
<div className="table-responsive">
|
|
<table className="table table-vcenter card-table table-stack">
|
|
<tbody>
|
|
{work.windows.map((w) => (
|
|
<tr key={w.id}>
|
|
<td className="stack-wide">
|
|
<strong>{w.targetName}</strong> <span className="text-secondary small">{w.targetKind}</span>
|
|
{w.reason && <div className="small text-secondary">{w.reason}</div>}
|
|
</td>
|
|
<td className="stack-label text-nowrap" data-label="Ends">
|
|
<span className={w.endsSoon ? "text-yellow" : "text-secondary"}>
|
|
Ends in {formatRemaining(w.endsAt)}
|
|
</span>
|
|
</td>
|
|
<td className="stack-wide text-nowrap">
|
|
<div className="btn-list flex-nowrap">
|
|
<button type="button" className="btn btn-sm btn-outline-secondary" disabled={busy === w.id} onClick={() => void extend(w, 60, "1 hour")}>
|
|
+1 h
|
|
</button>
|
|
<button type="button" className="btn btn-sm btn-outline-secondary" disabled={busy === w.id} onClick={() => void extend(w, 240, "4 hours")}>
|
|
+4 h
|
|
</button>
|
|
<button type="button" className="btn btn-sm btn-outline-danger" disabled={busy === w.id} onClick={() => void end(w)}>
|
|
End now
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{work && work.updateRuns.length > 0 && (
|
|
<div className="card mb-3">
|
|
<div className="card-header">
|
|
<h3 className="card-title">Update runs you started</h3>
|
|
<div className="card-actions">
|
|
<Link to="/updates" className="small">
|
|
Updates
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
<div className="table-responsive">
|
|
<table className="table table-vcenter card-table table-stack">
|
|
<tbody>
|
|
{work.updateRuns.map((r) => (
|
|
<tr key={r.id}>
|
|
<td className="stack-wide">
|
|
<Link to={`/servers/${r.serverId}`}>{r.serverName}</Link> <span className="text-secondary small">{r.templateName}</span>
|
|
{r.message && !r.running && <div className="small text-secondary">{r.message}</div>}
|
|
</td>
|
|
<td className="stack-label" data-label="State">
|
|
{r.running ? (
|
|
<span className="badge bg-blue-lt text-blue">Running</span>
|
|
) : r.status === "done" ? (
|
|
<span className="badge bg-green-lt text-green">Done</span>
|
|
) : (
|
|
<span className="badge bg-red-lt text-red">{r.status}</span>
|
|
)}
|
|
{!r.running && r.updatesBefore !== null && r.updatesAfter !== null && (
|
|
<span className="text-secondary small ms-2">
|
|
{r.updatesBefore} → {r.updatesAfter} waiting{r.rebootRequired ? ", restart needed" : ""}
|
|
</span>
|
|
)}
|
|
</td>
|
|
<td className="stack-label text-nowrap" data-label="Started">
|
|
<TimeAgo value={r.startedAt} />
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{acking && <AckDrawer alert={acking} me={user} onClose={() => setAcking(null)} onSaved={changed} />}
|
|
</>
|
|
);
|
|
}
|