A disk that is on course to be full within 14 days (setting: 0 turns it off) is flagged on the Alerts page and dashboard, from the server's own history: needs three days of steady growth, skips erratic disks and ones the ordinary disk alert covers. Skeleton placeholders replace "Fetching status…" and "Loading…". Alerts that a maintenance window can silence get a Silence button (1, 4 or 24 hours) that starts one, and the alert list is refreshed at once when a window starts or ends. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
70 lines
2.5 KiB
TypeScript
70 lines
2.5 KiB
TypeScript
import { useState } from "react";
|
|
import { api, type AlertItem } from "../api/client";
|
|
import { readableError } from "../utils/errors";
|
|
import { toast } from "../utils/toast";
|
|
|
|
const CHOICES = [
|
|
{ minutes: 60, label: "1 h", words: "1 hour" },
|
|
{ minutes: 240, label: "4 h", words: "4 hours" },
|
|
{ minutes: 1440, label: "24 h", words: "24 hours" },
|
|
];
|
|
|
|
/**
|
|
* "Silence" on an alert: pick how long, and a maintenance window goes on whatever the alert is about. That silences everything
|
|
* about that server or integration, not just this one alert — which is what a maintenance window is — so it says so, and the
|
|
* Maintenance page is where to end it early. The choices open in place, so nothing is clipped by the table around it.
|
|
*/
|
|
export default function SilenceButton({ alert, onDone }: { alert: AlertItem; onDone: () => void }) {
|
|
const [choosing, setChoosing] = useState(false);
|
|
const [busy, setBusy] = useState(false);
|
|
const target = alert.target;
|
|
if (!target || alert.silenced) return null;
|
|
|
|
async function silence(minutes: number, words: string) {
|
|
if (!target) return;
|
|
setBusy(true);
|
|
try {
|
|
await api.maintenance.start({
|
|
targetType: target.type,
|
|
targetId: target.id,
|
|
minutes,
|
|
reason: `Silenced from the Alerts page: ${alert.message}`.slice(0, 200),
|
|
});
|
|
toast.success(`${target.name} is silenced for ${words} — every alert about it. End it early under Maintenance.`);
|
|
// The sidebar badge and the maintenance banner listen for this.
|
|
window.dispatchEvent(new Event("maintenance-changed"));
|
|
setChoosing(false);
|
|
onDone();
|
|
} catch (err) {
|
|
toast.error(readableError(err));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
if (!choosing) {
|
|
return (
|
|
<button
|
|
type="button"
|
|
className="btn btn-sm btn-outline-secondary"
|
|
title={`Silence all alerts about ${target.name} for a while`}
|
|
onClick={() => setChoosing(true)}
|
|
>
|
|
Silence
|
|
</button>
|
|
);
|
|
}
|
|
return (
|
|
<div className="btn-group btn-group-sm" role="group" aria-label={`Silence ${target.name} for`}>
|
|
{CHOICES.map((c) => (
|
|
<button key={c.minutes} type="button" className="btn" disabled={busy} onClick={() => silence(c.minutes, c.words)} title={`Silence ${target.name} for ${c.words}`}>
|
|
{c.label}
|
|
</button>
|
|
))}
|
|
<button type="button" className="btn" disabled={busy} onClick={() => setChoosing(false)} aria-label="Cancel">
|
|
✕
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|