Add a notification history

Every notification is written down with how it went through each channel
(or why it was not sent: held for quiet hours, a routing rule said nobody, no
channel on). Records -> Notifications lists them with a filter, a search and
Send again. Errors are cleaned of every secret in the settings; kept 30 days.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-10 19:18:08 +01:00
1 parent 5c6ccc0a4b
commit 9126200295
18 files changed
+9886 -34

No files matched your search

+176
View File
@@ -0,0 +1,176 @@
import { useEffect, useState } from "react";
import { Link, useSearchParams } from "react-router-dom";
import { api, type NotificationEntry } from "../api/client";
import EmptyState from "../components/EmptyState";
import { ErrorNotice } from "../components/Notice";
import { BlockSkeleton } from "../components/Skeleton";
import TimeAgo from "../components/TimeAgo";
import { formatDateTime } from "../utils/date";
import { readableError } from "../utils/errors";
import { channelName, isLogStatus, STATUS_BADGE, STATUS_HINT, STATUS_LABEL, STATUS_ORDER, type LogStatus } from "../utils/notificationLog";
import { toast } from "../utils/toast";
/**
* What was sent: every notification, newest first, with how it went through each channel — or why it did not: held for quiet hours, a routing rule said nobody, no channel to send it to.
* "Send again" sends it once more to every channel that is on. Kept 30 days.
*/
export default function NotificationHistory() {
const [params, setParams] = useSearchParams();
const status = isLogStatus(params.get("status") ?? "") ? (params.get("status") as LogStatus) : "";
const q = params.get("q") ?? "";
const [text, setText] = useState(q);
const [entries, setEntries] = useState<NotificationEntry[] | null>(null);
const [error, setError] = useState<string | null>(null);
const [resending, setResending] = useState<number | null>(null);
const [tick, setTick] = useState(0);
const setParam = (key: string, value: string | null) =>
setParams(
(prev) => {
const next = new URLSearchParams(prev);
if (value) next.set(key, value);
else next.delete(key);
return next;
},
{ replace: true },
);
// What is searched for follows what is typed, a moment after it stops.
useEffect(() => {
const t = setTimeout(() => setParam("q", text.trim() || null), 300);
return () => clearTimeout(t);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [text]);
useEffect(() => {
let alive = true;
api.notificationLog
.list({ status, q })
.then((res) => {
if (!alive) return;
setEntries(res.entries);
setError(null);
})
.catch((err) => alive && setError(readableError(err)));
return () => {
alive = false;
};
}, [status, q, tick]);
async function resend(e: NotificationEntry) {
setResending(e.id);
try {
await api.notificationLog.resend(e.id);
toast.success("Sent again to every channel that is on.");
setTick((n) => n + 1);
} catch (err) {
toast.error(readableError(err));
} finally {
setResending(null);
}
}
const failing = entries?.filter((e) => e.status === "failed" || e.status === "partly").length ?? 0;
return (
<>
<div className="d-flex align-items-center mb-1">
<h2 className="page-title mb-0">Notification history</h2>
</div>
<p className="text-secondary">
What was sent, to which channel, and whether it got through — or why it was not sent. Kept 30 days. The channels are set up under <Link to="/settings/notifications">Settings → Notifications</Link>.
</p>
<div className="row g-2 mb-3">
<div className="col-sm-4 col-md-3">
<select className="form-select" aria-label="Show" value={status} onChange={(e) => setParam("status", e.target.value || null)}>
<option value="">Everything</option>
{STATUS_ORDER.map((s) => (
<option key={s} value={s}>
{STATUS_LABEL[s]}
</option>
))}
</select>
</div>
<div className="col-sm-8 col-md-5">
<input className="form-control" type="search" aria-label="Search the history" placeholder="Search the title or the message" value={text} onChange={(e) => setText(e.target.value)} />
</div>
</div>
<ErrorNotice error={error} />
{!entries && !error && <BlockSkeleton lines={5} />}
{entries && entries.length === 0 && (
<div className="card">
<div className="card-body">
<EmptyState title={status || q ? "Nothing matches" : "Nothing has been sent yet"} hint={status || q ? "Try another filter." : "Every notification is listed here from now on, with how each channel took it."} />
</div>
</div>
)}
{entries && entries.length > 0 && (
<div className="card">
<div className="card-header">
<h3 className="card-title">
{entries.length} notification{entries.length === 1 ? "" : "s"}
{failing > 0 && <span className="text-red fw-normal ms-2">{failing} did not get through everywhere</span>}
</h3>
</div>
<div className="table-responsive">
<table className="table table-vcenter card-table">
<thead>
<tr>
<th>When</th>
<th>Notification</th>
<th>How it went</th>
<th className="w-1">Actions</th>
</tr>
</thead>
<tbody>
{entries.map((e) => {
const known = isLogStatus(e.status);
return (
<tr key={e.id}>
<td className="text-nowrap">
<span title={formatDateTime(new Date(e.at))}>
<TimeAgo value={e.at} />
</span>
</td>
<td style={{ maxWidth: 420 }}>
<div className="fw-bold text-break">{e.title}</div>
{e.resentOf !== null && <div className="text-secondary small">sent again from an earlier one</div>}
<details className="small">
<summary className="text-secondary">Show what it said</summary>
<pre className="mb-0 text-break" style={{ whiteSpace: "pre-wrap", maxHeight: 220, overflow: "auto" }}>
{e.message}
</pre>
</details>
</td>
<td>
<span className={`badge ${known ? STATUS_BADGE[e.status as LogStatus] : "bg-secondary-lt"}`} title={known ? STATUS_HINT[e.status as LogStatus] : undefined}>
{known ? STATUS_LABEL[e.status as LogStatus] : e.status}
</span>
{e.note && <div className="text-secondary small">{e.note}</div>}
{e.results.length > 0 && (
<ul className="list-unstyled small mb-0 mt-1">
{e.results.map((r, i) => (
<li key={i} className={r.ok ? "text-secondary" : "text-red"}>
<span aria-hidden="true">{r.ok ? "✓" : "✕"}</span> {channelName(r.channel)}
{!r.ok && r.error ? <span className="text-break"> — {r.error}</span> : null}
</li>
))}
</ul>
)}
</td>
<td>
<button className="btn btn-sm" disabled={resending === e.id} onClick={() => void resend(e)} title="Send it once more to every channel that is on">
{resending === e.id ? "Sending…" : e.status === "held" ? "Send now" : "Send again"}
</button>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
)}
</>
);
}
@@ -1,6 +1,6 @@
import AwayCard from "./AwayCard";
import { useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
import { useSearchParams } from "react-router-dom";
import { Link, useSearchParams } from "react-router-dom";
import AlertActionsCard from "./AlertActionsCard";
import {
api,
@@ -546,7 +546,12 @@ export default function NotificationSettings() {
<>
<div className="settings-savebar">
<div className="d-flex flex-wrap align-items-center justify-content-between gap-2">
<h3 className="mb-0">Notifications</h3>
<h3 className="mb-0">
Notifications
<Link className="ms-3 fs-5 fw-normal" to="/notification-history">
See what was sent
</Link>
</h3>
<div className="d-flex align-items-center gap-2">
{saveError && <span className="text-danger small">{saveError}</span>}
{saved && <span className="text-success small">✓ Settings saved</span>}