Pagination and search on long lists (1.50.1)
Audit log: search (person, target, IP), role filter, every action in the filter, inclusive To date. Data requests: search and paging (was cut at 200). Webhook deliveries: status filter and Load older. Supervisor Payments loads only what it needs (unpaid registrations, recent/today/donation payments, a person's own for refunds) instead of everything. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
@@ -20,6 +20,9 @@ type ListResponse = { eventTypes: EventType[]; keepDays: number; endpoints: Endp
|
||||
type Draft = { id?: string; name: string; url: string; events: string[] };
|
||||
|
||||
const when = (d: string | null) => (d ? new Date(d).toLocaleString("en-GB", { day: "numeric", month: "short", hour: "2-digit", minute: "2-digit" }) : "—");
|
||||
// Deliveries shown at a time in the log ("Load older" fetches the next lot).
|
||||
const PAGE = 50;
|
||||
|
||||
const STATUS: Record<string, string> = {
|
||||
succeeded: "bg-green-50 text-green-800", failed: "bg-red-50 text-red-700", retrying: "bg-amber-50 text-amber-800",
|
||||
pending: "bg-gray-100 text-gray-600", sending: "bg-blue-50 text-blue-700",
|
||||
@@ -50,21 +53,46 @@ function Deliveries({ endpointId, token }: { endpointId: string; token: string }
|
||||
const [rows, setRows] = useState<Delivery[] | null>(null);
|
||||
const [open, setOpen] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
const [status, setStatus] = useState("");
|
||||
const [more, setMore] = useState(false);
|
||||
const fetchPage = useCallback((before?: string) => {
|
||||
const qs = new URLSearchParams({ limit: String(PAGE) });
|
||||
if (status) qs.set("status", status);
|
||||
if (before) qs.set("before", before);
|
||||
return apiFetch<Delivery[]>(`/api/outbound-webhooks/${endpointId}/deliveries?${qs.toString()}`, { authToken: token }).catch(() => [] as Delivery[]);
|
||||
}, [endpointId, token, status]);
|
||||
const load = useCallback(async () => {
|
||||
setRows(await apiFetch<Delivery[]>(`/api/outbound-webhooks/${endpointId}/deliveries`, { authToken: token }).catch(() => []));
|
||||
}, [endpointId, token]);
|
||||
const page = await fetchPage();
|
||||
setRows(page);
|
||||
setMore(page.length === PAGE);
|
||||
}, [fetchPage]);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
const loadOlder = async () => {
|
||||
if (!rows?.length) return;
|
||||
const page = await fetchPage(rows[rows.length - 1].createdAt);
|
||||
setRows([...rows, ...page]);
|
||||
setMore(page.length === PAGE);
|
||||
};
|
||||
const resend = async (id: string) => {
|
||||
setBusy(id);
|
||||
await apiFetch(`/api/outbound-webhooks/deliveries/${id}/resend`, { method: "POST", authToken: token }).catch(() => {});
|
||||
setBusy(null);
|
||||
load();
|
||||
};
|
||||
if (!rows) return <p className="text-xs text-gray-400">Loading…</p>;
|
||||
if (!rows.length) return <p className="text-xs text-gray-500">Nothing sent yet.</p>;
|
||||
if (!rows) return <p className="text-xs text-gray-500">Loading…</p>;
|
||||
if (!rows.length && !status) return <p className="text-xs text-gray-500">Nothing sent yet.</p>;
|
||||
return (
|
||||
<div className="space-y-1" data-testid="webhook-deliveries">
|
||||
<div className="flex justify-end"><button type="button" onClick={load} className="inline-flex items-center gap-1 text-xs text-gray-600 hover:text-gray-900"><RefreshCw className="w-3 h-3" /> Refresh</button></div>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<select aria-label="Show deliveries" className="border rounded px-2 py-1 text-xs" value={status} onChange={e => setStatus(e.target.value)}>
|
||||
<option value="">All deliveries</option>
|
||||
<option value="failed">Failed</option>
|
||||
<option value="retrying">Retrying</option>
|
||||
<option value="succeeded">Succeeded</option>
|
||||
</select>
|
||||
<button type="button" onClick={load} className="inline-flex items-center gap-1 text-xs text-gray-600 hover:text-gray-900"><RefreshCw className="w-3 h-3" aria-hidden="true" /> Refresh</button>
|
||||
</div>
|
||||
{!rows.length && <p className="text-xs text-gray-500">None with this status.</p>}
|
||||
<ul className="divide-y border rounded-lg bg-white">
|
||||
{rows.map(d => (
|
||||
<li key={d.id} className="text-xs" data-testid="webhook-delivery">
|
||||
@@ -89,6 +117,11 @@ function Deliveries({ endpointId, token }: { endpointId: string; token: string }
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{more && (
|
||||
<div className="flex justify-center">
|
||||
<button type="button" onClick={loadOlder} className="text-xs px-3 py-1 rounded border bg-white hover:bg-gray-50">Load older</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user