import { Link } from "react-router-dom";
import { IconAlertTriangle, IconCircleCheck, IconInfoCircle } from "@tabler/icons-react";
import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport";
const SEVERITY_ORDER = { critical: 0, warning: 1, info: 2 } as const;
/** One line at the top of the dashboard: is anything wrong right now? Reads the same alert report as the Alerts page. */
export default function StatusStrip() {
const { report, failed, reload } = useAlertsReport();
if (!report) {
return (
{failed ? "Couldn't load the alert status." : "Checking status…"}
{failed && (
)}
);
}
const badge = alertBadge(report);
const active = report.alerts
.filter((a) => !a.silenced && a.severity !== "info")
.sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]);
const silenced = report.counts.silenced;
const grouped = report.counts.grouped ?? 0;
const blind = report.couldntCheck.length;
const notes: string[] = [];
if (silenced > 0) notes.push(`${silenced} silenced by maintenance`);
if (grouped > 0) notes.push(`${grouped} more explained by a server that is down`);
if (blind > 0 && badge) notes.push(`${blind} check${blind === 1 ? "" : "s"} couldn't run`);
if (!badge) {
// Nothing is wrong that we can see — but if some checks couldn't run, "all clear" would claim more than is known.
const unsure = blind > 0;
return (
{unsure ? : }
{unsure ? "No active alerts, but some checks couldn't run." : "All clear."}{" "}
{unsure ? (
{report.couldntCheck.map((c) => c.name).join(", ")} — see Alerts for what that leaves unchecked.
) : (
No active alerts.
)}
{silenced > 0 && {silenced} silenced by maintenance.}
{grouped > 0 && {grouped} more explained by a server that is down.}