Skip to content

[dev] [Marfuen] mariano/admin-audit-pagination#3480

Merged
Marfuen merged 6 commits into
mainfrom
mariano/admin-audit-pagination
Jul 22, 2026
Merged

[dev] [Marfuen] mariano/admin-audit-pagination#3480
Marfuen merged 6 commits into
mainfrom
mariano/admin-audit-pagination

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This is an automated pull request to merge mariano/admin-audit-pagination into dev.
It was created by the [Auto Pull Request] action.


Summary by cubic

Adds offset pagination to admin org and vendor activity so you can browse beyond the first window with stable ordering, a smarter pager, and safe bounds on deep paging.

  • New Features

    • API: Admin getAuditLogs and /v1/audit-logs accept offset and return { data, total } with a stable sort (timestamp then id). Admin default/max take is 100/200; shared endpoint is 50/100; count uses identical filters.
    • App: New useOffsetAuditLogs core; useAdminAuditLogs/usePaginatedAuditLogs load 100-row batches. RecentAuditLogs supports server pagination (total, hasMore, onLoadMore, isLoadingMore), keeps the next arrow enabled from the server total, auto-loads at batch boundaries, and shows a loading spinner. Updated OrganizationDetail and vendor activity to use the paginated hooks.
    • Tests: Added hook and pager tests (accumulate/dedupe/hasMore/filter-reset, smart next arrow, auto fetch, legacy mode). Expanded controller/service specs for offset/total/count.
    • Docs: Regenerated openapi.json to add the offset query param on GET /v1/audit-logs.
  • Bug Fixes

    • Prevent skipping a batch on failed load-more: loadMore advances only after the current fetch settles successfully.
    • Cap offset at MAX_AUDIT_LOG_OFFSET (100k) and cap the reported total to the reachable window so the pager stops correctly and avoids unbounded scans.

Written for commit c6fd74a. Summary will update on new commits.

Review in cubic

The platform-admin "Recent Activity" panel hard-capped at 100 records with
no way to see older history. Add offset pagination end-to-end:

- API: `getAuditLogs` accepts `offset`, returns `{ data, total }` (parallel
  count), raises the `take` ceiling to 200, and adds a stable `id` secondary
  sort so offset paging is deterministic across batches.
- App: `useAdminAuditLogs` accumulates 100-row batches by offset and derives
  `hasMore` from the server total.
- `RecentAuditLogs` gains optional server-pagination props: the › arrow stays
  enabled until the genuine last page (ceil(total / pageSize)) and the next
  batch is fetched automatically when paging past the loaded window — so the
  arrow is only enabled when there's actually more to load.

Adds RecentAuditLogs pager tests (smart next-arrow from server total,
load-more at the batch boundary, legacy backward-compat) and extends the
admin-organizations service spec for offset/take/total.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Jul 22, 2026 7:27pm
comp-framework-editor Ready Ready Preview, Comment Jul 22, 2026 7:27pm
portal Ready Ready Preview, Comment Jul 22, 2026 7:27pm

Request Review

…y visible

The vendor detail "Recent Activity" panel fetched /v1/audit-logs with no
offset and no total, so it only ever showed the newest 50 combined vendor +
task-item events. On a busy vendor, older `vendor` events (e.g. an assignee
change) fell off with no way to page to them — they were logged, just
unreachable in the UI.

- API: `/v1/audit-logs` now accepts `offset`, returns `{ data, total }`
  (parallel count), and adds a stable `id` secondary sort so offset paging is
  deterministic. `take` semantics unchanged (default 50, max 100). Purely
  additive — the existing non-paginated `useAuditLogs` consumers are unaffected.
- App: extract the offset-accumulate machinery into a shared
  `useOffsetAuditLogs` core (used by the admin pager too, now a thin wrapper)
  and add `usePaginatedAuditLogs` for entity-scoped views. The core resets its
  window when the filter identity changes (e.g. a vendor's task-item ids load).
- Vendor activity section wires the paginated hook into RecentAuditLogs' server
  pager (load-more + smart next arrow).

Tests: audit-log controller spec covers offset/total/count; useOffsetAuditLogs
spec covers accumulate/dedupe/hasMore/filter-reset.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Confidence score: 5/5

  • Safe to merge after the addressed issues were fixed.

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/api/src/admin-organizations/admin-organizations.service.ts Outdated
Comment thread apps/api/src/admin-organizations/admin-organizations.controller.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/api/src/audit/audit-log.controller.ts
Comment thread apps/api/src/audit/audit-log.controller.ts
- P1: offset pager no longer skips a batch on a failed load-more. `loadMore`
  only advances once the current batch has settled successfully; while it's
  loading or errored (SWR retries the same offset) it's a no-op, so no rows are
  dropped from the pager. Covered by a new hook test.
- Cap `offset` on both audit-log endpoints (shared /v1/audit-logs and the admin
  org endpoint) at MAX_AUDIT_LOG_OFFSET (100k) so an unbounded ?offset= can't
  force arbitrarily large table scans. Constant lives in a dependency-free
  module so it doesn't drag Prisma enums into unit-test module graphs.
- Add the missing admin-controller test for the offset param and cap tests for
  both endpoints.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Picks up the new `offset` query param on GET /v1/audit-logs so the generated
MCP `get-audit-logs` client can page past the first batch. Addresses the last
open cubic finding on #3480.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mintlify

mintlify Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
CompAI 🟢 Ready View Preview Jul 22, 2026, 4:11 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 12 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread apps/app/src/hooks/use-offset-audit-logs.ts
@mintlify

mintlify Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
CompAI 🟡 Building Jul 22, 2026, 4:11 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

Follow-up to the offset cap: the endpoints returned the true row count while
clamping any offset past MAX_AUDIT_LOG_OFFSET to the same page. Past the cap the
client's `hasMore = logs.length < total` stayed true, so the pager looped
load-more over pages that could never be filled.

Report `min(count, MAX_AUDIT_LOG_OFFSET)` from both audit-log endpoints so
`hasMore` and the pager's page count stop at the accessible boundary. No client
change needed. Covered by cap-total tests on both specs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Marfuen
Marfuen merged commit 3f7a89a into main Jul 22, 2026
11 checks passed
@Marfuen
Marfuen deleted the mariano/admin-audit-pagination branch July 22, 2026 19:31
@linear

linear Bot commented Jul 22, 2026

Copy link
Copy Markdown

ENG-253

@claudfuen

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.107.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants