Skip to content

Adopt nuqs for audit-log-screen filter/pagination state #237

Description

@stephane-segning

Summary

admin/app/audit-log/audit-log-screen.tsx hand-rolls its filter and
pagination state with plain useState (model, actorId, offset), even
though nuqs (2.9.5) is already a dependency and already used for exactly
this purpose — URL-persisted, bookmarkable filter state — in
messages-screen.tsx, jobs-screen.tsx, and webhooks-screen.tsx. This
screen appears to have simply been missed when those three adopted it.

Source of truth: docs/design/frontend-package-audit.md ("nuqs for
audit-log-screen.tsx — adopt" section), from the frontend package audit
requested by the maintainer.

Scope

In admin/app/audit-log/audit-log-screen.tsx, replace:

const [model, setModel] = useState("");
const [actorId, setActorId] = useState("");
const [offset, setOffset] = useState(0);

with useQueryStates (nuqs), matching the pattern already established in
admin/app/jobs/jobs-screen.tsx (parseAsString/parseAsStringEnum for the
filters; the offset can use parseAsInteger). Nothing else about the screen
changes — this is a state-management substitution, not a UX change, though
the resulting URL-shareable filter state is a real, incidental improvement
(an operator can now bookmark or share a specific audit-log filter view, the
same way they already can for messages/jobs/webhooks).

Small and mechanical: roughly 15–20 lines of URL-sync boilerplate removed,
replaced by the existing nuqs pattern already proven three times over in
this codebase.

Properties that must survive this change

  • Pagination (offset) resets to 0 when a filter changes, matching the
    current behavior — check the existing jobs-screen.tsx pattern for how
    it handles this (its filter change handlers explicitly reset paging
    state) and replicate it here rather than assuming nuqs does it for free.
  • The screen's existing hasFilters/"clear filters" affordance (if present)
    keeps working against the new nuqs-backed state.

Verification

  • pnpm --filter admin typecheck stays green.
  • Manually exercise: setting a filter updates the URL query string; a
    bookmarked/shared URL with ?model=...&actorId=... reproduces the same
    filtered view on load; changing a filter resets offset to 0.

AI Usage Declaration

This issue was filed by an AI agent (Claude) performing a maintainer-
requested audit of packages/* for hand-rolled machinery a well-maintained
library could replace. The scope was derived by reading
audit-log-screen.tsx and comparing it directly against the already-adopted
nuqs pattern in jobs-screen.tsx/messages-screen.tsx/webhooks-screen.tsx,
not inferred. A human should confirm the scope above and verify the manual
checks before merging.

  • Human has reviewed the scope above
  • Human confirms the URL-state behavior was verified live before merge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions