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:
2026-10-29 06:53:54 +02:00
co-authored by Claude Opus 5.5
parent 0ffbb13a1f
commit 4c066e67d9
26 changed files with 460 additions and 147 deletions
@@ -10,50 +10,6 @@ import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "@
import { errorMessage } from "@/lib/utils";
import { BackLink } from "@/components/shared/BackLink";
const ACTIONS = [
"refund_created",
"donation_assigned",
"donation_unassigned",
"registration_created_manual",
"registration_cancelled",
"event_created",
"event_updated",
"event_deleted",
"settings_updated",
"coupon_created",
"coupon_updated",
"coupon_disabled",
"coupon_applied_manual",
"bundle_created",
"bundle_updated",
"bundle_deleted",
"consent_override",
"consent_rerequested",
"medical_list_viewed",
"scan_lock_acquired",
"scan_lock_released",
"scan_lock_force_released",
"offline_sync",
"ticket_transferred",
"impersonation_started",
"impersonation_ended",
"yoco_config_updated",
"yoco_webhook_registered",
"yoco_webhook_deleted",
"data_request_completed",
"data_request_rejected",
"user_anonymised",
"privacy_notice_published",
"operator_created",
"operator_updated",
"operator_deleted",
"retention_policies_updated",
"retention_run",
"breach_recorded",
"breach_updated",
"hub_connected",
] as const;
const ACTION_LABELS: Record<string, string> = {
refund_created: "Refund created",
donation_assigned: "Donation assigned",
@@ -122,8 +78,23 @@ const ACTION_LABELS: Record<string, string> = {
series_deleted: "Event series deleted",
season_pass_changed: "Season pass created, changed or deleted",
registrations_bulk: "Bulk action on registrations",
attendance_marked: "Attendance marked",
attendance_unmarked: "Attendance unmarked",
certificate_issued: "Certificate issued",
certificate_revoked: "Certificate revoked",
event_sessions_changed: "Event sessions changed",
job_run_manual: "Background job run by hand",
payfast_config_updated: "PayFast settings changed",
payment_providers_updated: "Payment providers changed",
webhook_endpoint_changed: "Webhook added, changed or deleted",
};
// Every action that can be logged (keep in step with AdminAuditAction in schema.prisma),
// sorted by label for the filter.
const ACTION_OPTIONS = Object.entries(ACTION_LABELS).sort((x, y) => x[1].localeCompare(y[1]));
const ROLES = ["admin", "supervisor", "staff"] as const;
interface AuditLogEntry {
id: string;
actorId: string | null;
@@ -212,16 +183,32 @@ export default function AdminAuditLogPage() {
const totalPages = Math.max(1, Math.ceil(total / pageSize));
const [actionFilter, setActionFilter] = useState<string>("");
const [roleFilter, setRoleFilter] = useState<string>("");
const [searchInput, setSearchInput] = useState<string>("");
const [search, setSearch] = useState<string>("");
const [fromFilter, setFromFilter] = useState<string>("");
const [toFilter, setToFilter] = useState<string>("");
const buildQuery = useCallback((p: number) => {
const qs = new URLSearchParams({ page: String(p), limit: String(pageSize) });
if (actionFilter) qs.set("action", actionFilter);
if (roleFilter) qs.set("role", roleFilter);
if (search) qs.set("search", search);
if (fromFilter) qs.set("from", fromFilter);
if (toFilter) qs.set("to", toFilter);
return `/api/admin/audit-log?${qs.toString()}`;
}, [actionFilter, fromFilter, toFilter]);
}, [actionFilter, roleFilter, search, fromFilter, toFilter]);
// Search as you type, once typing pauses.
useEffect(() => {
const t = setTimeout(() => setSearch(searchInput.trim()), 350);
return () => clearTimeout(t);
}, [searchInput]);
const filtered = !!(actionFilter || roleFilter || search || fromFilter || toFilter);
const clearFilters = () => {
setActionFilter(""); setRoleFilter(""); setSearchInput(""); setSearch(""); setFromFilter(""); setToFilter("");
};
const load = useCallback(async (p = 1) => {
if (!token) return;
@@ -251,7 +238,7 @@ export default function AdminAuditLogPage() {
<div>
<BackLink href="/dashboard/admin" />
<h1 className="text-2xl font-semibold text-gray-900 mt-0.5">Admin Audit Log</h1>
<p className="text-sm text-gray-500">{total} action{total !== 1 ? "s" : ""} recorded</p>
<p className="text-sm text-gray-500">{total} action{total !== 1 ? "s" : ""} {filtered ? "match the filters" : "recorded"}</p>
</div>
</div>
@@ -262,25 +249,48 @@ export default function AdminAuditLogPage() {
)}
{isAdmin && token && <ImpersonationSessions token={token} />}
{error && <div className="mb-3 p-3 border rounded bg-red-50 text-red-800 text-sm">{error}</div>}
{error && <div role="alert" className="mb-3 p-3 border rounded bg-red-50 text-red-800 text-sm">{error}</div>}
<div className="border rounded-xl p-4 bg-white shadow-sm">
<div className="flex flex-wrap items-end gap-3 mb-4">
<div className="flex-1 min-w-[14rem]">
<label htmlFor="audit-search" className="block text-xs text-gray-600 mb-1">Search</label>
<input
id="audit-search"
type="search"
className="w-full border rounded px-2 py-1.5 text-sm"
placeholder="Person, target (e.g. Event or #id) or IP"
value={searchInput}
onChange={e => setSearchInput(e.target.value)}
/>
</div>
<div>
<label className="block text-xs text-gray-600 mb-1">Action</label>
<select className="border rounded px-2 py-1.5 text-sm" value={actionFilter} onChange={e => setActionFilter(e.target.value)}>
<label htmlFor="audit-action" className="block text-xs text-gray-600 mb-1">Action</label>
<select id="audit-action" className="border rounded px-2 py-1.5 text-sm max-w-[16rem]" value={actionFilter} onChange={e => setActionFilter(e.target.value)}>
<option value="">All actions</option>
{ACTIONS.map(a => <option key={a} value={a}>{ACTION_LABELS[a]}</option>)}
{ACTION_OPTIONS.map(([a, label]) => <option key={a} value={a}>{label}</option>)}
</select>
</div>
<div>
<label className="block text-xs text-gray-600 mb-1">From</label>
<input type="date" className="border rounded px-2 py-1.5 text-sm" value={fromFilter} onChange={e => setFromFilter(e.target.value)} />
<label htmlFor="audit-role" className="block text-xs text-gray-600 mb-1">Role</label>
<select id="audit-role" className="border rounded px-2 py-1.5 text-sm" value={roleFilter} onChange={e => setRoleFilter(e.target.value)}>
<option value="">Any role</option>
{ROLES.map(r => <option key={r} value={r} className="capitalize">{r[0].toUpperCase() + r.slice(1)}</option>)}
</select>
</div>
<div>
<label className="block text-xs text-gray-600 mb-1">To</label>
<input type="date" className="border rounded px-2 py-1.5 text-sm" value={toFilter} onChange={e => setToFilter(e.target.value)} />
<label htmlFor="audit-from" className="block text-xs text-gray-600 mb-1">From</label>
<input id="audit-from" type="date" className="border rounded px-2 py-1.5 text-sm" value={fromFilter} onChange={e => setFromFilter(e.target.value)} />
</div>
<div>
<label htmlFor="audit-to" className="block text-xs text-gray-600 mb-1">To</label>
<input id="audit-to" type="date" className="border rounded px-2 py-1.5 text-sm" value={toFilter} min={fromFilter || undefined} onChange={e => setToFilter(e.target.value)} />
</div>
{filtered && (
<button className="text-sm px-2 py-1.5 rounded text-brand-700 hover:bg-brand-50" onClick={clearFilters}>
Clear filters
</button>
)}
<button className="text-sm px-2 py-1.5 rounded bg-gray-100 hover:bg-gray-200" onClick={() => load(page)} disabled={fetching}>
{fetching ? "Refreshing…" : "Refresh"}
</button>
@@ -307,9 +317,9 @@ export default function AdminAuditLogPage() {
<div className="text-xs text-gray-500">{e.actor.email}</div>
</>
) : (
<span className="text-gray-400 italic">Deleted user</span>
<span className="text-gray-500 italic">Deleted user</span>
)}
<div className="text-xs text-gray-400 capitalize">{e.actorRole}</div>
<div className="text-xs text-gray-500 capitalize">{e.actorRole}</div>
</TableCell>
<TableCell>{ACTION_LABELS[e.action] || e.action}</TableCell>
<TableCell className="text-xs text-gray-600">{e.targetType}{e.targetId ? ` #${e.targetId.slice(0, 8)}` : ""}</TableCell>
@@ -323,7 +333,7 @@ export default function AdminAuditLogPage() {
)}
{fetching && (
<TableRow>
<TableCell colSpan={5} className="text-gray-400">Loading…</TableCell>
<TableCell colSpan={5} className="text-gray-500">Loading…</TableCell>
</TableRow>
)}
</TableBody>
@@ -331,7 +341,7 @@ export default function AdminAuditLogPage() {
{totalPages > 1 && (
<div className="flex items-center justify-between mt-4 text-sm">
<span className="text-gray-500">Page {page} of {totalPages}</span>
<span className="text-gray-500">{(page - 1) * pageSize + 1}–{Math.min(page * pageSize, total)} of {total} · page {page} of {totalPages}</span>
<div className="flex gap-1">
<button
className="px-2 py-1 rounded bg-gray-100 hover:bg-gray-200 disabled:opacity-40"