- Jobs: Succeeded/Cancelled filters, product, type and church search, paged on the server; audit log and alerts paged on the server with search; every other list paged. - Updates: one product at a time with its own releases; an Events update pins the church's Accounts (or updates it when the release needs it, or installs it first); fixes the requirement check comparing an object. - A status job adds installs found on a server and ties them to their registration; unlinked registered sites trigger one (daily); heartbeats tie install records too; the install page shows its registration. 13 new tests (209). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
3.0 KiB
TypeScript
51 lines
3.0 KiB
TypeScript
"use client";
|
|
|
|
import React, { useEffect, useState } from "react";
|
|
import Link from "next/link";
|
|
import { ago, fmtDate } from "@/lib/format";
|
|
import { useServerPaged } from "@/lib/paging";
|
|
import type { InstallEvent } from "@/lib/types";
|
|
import { Badge, Loading, PageTitle, Pager, SearchInput } from "@/components/ui";
|
|
|
|
/** Open alerts, and the history of everything that happened to installs, a page at a time (Hub 2.6.0: paged on the server). */
|
|
export default function AlertsPage() {
|
|
const [openOnly, setOpenOnly] = useState(true);
|
|
const [query, setQuery] = useState("");
|
|
const [q, setQ] = useState("");
|
|
useEffect(() => { const t = setTimeout(() => setQ(query.trim()), 300); return () => clearTimeout(t); }, [query]);
|
|
const paged = useServerPaged<InstallEvent>("/api/admin/events", { open: openOnly ? "true" : "", q }, r => r.events as InstallEvent[]);
|
|
const events = paged.rows;
|
|
const error = paged.error;
|
|
|
|
return (
|
|
<>
|
|
<PageTitle title="Alerts" subtitle="Checked every 5 minutes. New warnings and critical alerts are emailed once (Settings → Alerts → Alert email)." />
|
|
<div className="mb-4 flex flex-wrap gap-2">
|
|
<button className={openOnly ? "btn-primary" : "btn-secondary"} onClick={() => setOpenOnly(true)}>Open</button>
|
|
<button className={!openOnly ? "btn-primary" : "btn-secondary"} onClick={() => setOpenOnly(false)}>Everything</button>
|
|
<SearchInput className="w-full sm:ml-auto sm:w-72" value={query} onChange={setQuery} placeholder="Search alerts or install" />
|
|
</div>
|
|
{error && <p className="text-sm text-red-700">{error}</p>}
|
|
{!events ? <Loading /> : events.length === 0 && !q ? <p className="text-sm text-slate-500">{openOnly ? "No open alerts. 🎉" : "Nothing yet."}</p> : (
|
|
<div className="card overflow-x-auto p-0">
|
|
<table className="w-full text-sm">
|
|
<thead className="bg-slate-50 text-left text-xs text-slate-500"><tr><th className="p-3">When</th><th className="p-3">Install</th><th className="p-3">What</th><th className="p-3">State</th></tr></thead>
|
|
<tbody>
|
|
{events.length === 0 && <tr><td colSpan={4} className="p-3 text-slate-500">No alerts match.</td></tr>}
|
|
{events.map(e => (
|
|
<tr key={e.id} className="border-t align-top">
|
|
<td className="p-3 whitespace-nowrap text-xs text-slate-500">{fmtDate(e.createdAt)}</td>
|
|
<td className="p-3">{e.install ? <Link href={`/installs/${e.install.id}`} className="text-indigo-700 hover:underline">{e.install.name}</Link> : "—"}</td>
|
|
<td className="p-3"><Badge value={e.level} /> <span className="ml-1">{e.message}</span></td>
|
|
<td className="p-3 text-xs text-slate-500">{e.level === "info" ? "" : e.resolvedAt ? `resolved ${ago(e.resolvedAt)}` : "open"}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
<Pager page={paged.page} pages={paged.pages} setPage={paged.setPage} total={paged.total} pageSize={paged.pageSize} />
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|