Skip to content

[codex] add audit log filters and CSV export#33

Merged
tianzhou merged 4 commits into
mainfrom
feat/audit-log-filters-export
Jun 26, 2026
Merged

[codex] add audit log filters and CSV export#33
tianzhou merged 4 commits into
mainfrom
feat/audit-log-filters-export

Conversation

@tianzhou

Copy link
Copy Markdown
Contributor

Summary

  • Add shared audit-log filtering for both Connection and System tabs: search, action, source, status, and date range.
  • Add CSV export for the currently filtered audit rows.
  • Increase audit-log page fetches from 100 to 1000 rows so client-side filtering/export covers a more useful window.
  • Loosen the existing CSV helper type so non-query exports can reuse it with named columns.

Validation

  • pnpm build
  • pnpm test tests/audit.test.ts
  • pnpm exec eslint src/pages/AuditLog.tsx src/lib/export-csv.ts src/hooks/useQuery.ts
  • curl -s -o /tmp/pgconsole-audit.html -w "%{http_code}" http://localhost:5173/audit-log -> 200 with local dev server

Note: pnpm lint -- src/pages/AuditLog.tsx src/lib/export-csv.ts invokes the package script as eslint . -- ..., so it still scans the full repo and fails on existing unrelated lint debt. Direct ESLint on touched files passes.

Copilot AI review requested due to automatic review settings June 26, 2026 07:35
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
pgconsole Ready Ready Preview, Comment Jun 26, 2026 8:08am

Copilot AI 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.

Pull request overview

Adds shared client-side filtering and CSV export capabilities to the Audit Log UI (both Connection and System tabs), and increases the fetched audit window so filtering/export is more useful in practice.

Changes:

  • Introduces a reusable audit filter bar (search/action/source/status/date range) and applies it to both audit-log tabs.
  • Adds CSV export for the currently filtered audit entries.
  • Increases audit-log fetch limits from 100 → 1000 and loosens the CSV helper’s column type to accept name-only metadata.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/pages/AuditLog.tsx Adds shared filter UI, filtering logic, and CSV export for connection + system audit entries.
src/lib/export-csv.ts Loosens column metadata typing to support non-query exports with named columns.
src/hooks/useQuery.ts Raises audit-log query limits to 1000 via a shared constant.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pages/AuditLog.tsx Outdated
Comment on lines +195 to +203
<Label>Action</Label>
<Select
value={filters.action}
onValueChange={(action) => onFiltersChange({ ...filters, action: action ?? 'all' })}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in dedc4b0 by adding matching label/trigger ids for the Action, Source, and Status selects. Validated with pnpm build, pnpm test tests/audit.test.ts, and pnpm exec eslint src/pages/AuditLog.tsx src/lib/export-csv.ts src/hooks/useQuery.ts.

Comment thread src/pages/AuditLog.tsx Outdated
Comment on lines +212 to +220
<Label>Source</Label>
<Select
value={filters.source}
onValueChange={(source) => onFiltersChange({ ...filters, source: source ?? 'all' })}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in dedc4b0 by adding matching label/trigger ids for the Action, Source, and Status selects. Validated with pnpm build, pnpm test tests/audit.test.ts, and pnpm exec eslint src/pages/AuditLog.tsx src/lib/export-csv.ts src/hooks/useQuery.ts.

Comment thread src/pages/AuditLog.tsx Outdated
Comment on lines +229 to +237
<Label>Status</Label>
<Select
value={filters.status}
onValueChange={(status) => onFiltersChange({ ...filters, status: status ?? 'all' })}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in dedc4b0 by adding matching label/trigger ids for the Action, Source, and Status selects. Validated with pnpm build, pnpm test tests/audit.test.ts, and pnpm exec eslint src/pages/AuditLog.tsx src/lib/export-csv.ts src/hooks/useQuery.ts.

@tianzhou tianzhou marked this pull request as ready for review June 26, 2026 07:42
Copilot AI review requested due to automatic review settings June 26, 2026 07:43
@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds shared client-side filtering (search, action, source, status, date range) and CSV export to both the Connection and System audit log tabs, and raises the server-side page fetch ceiling from 500 to 1000 rows so that client-side operations cover a wider window.

  • AuditLog.tsx gains a reusable AuditFilterBar + AuditEntriesView component pair; all filter logic (filterEntries, matchesDateRange, uniqueValues) stays pure and is gated behind useMemo.
  • export-csv.ts type is loosened from ColumnMetadata[] to Array<Pick<ColumnMetadata, 'name'>> so the audit export can reuse the helper without importing SQL-editor types.
  • Both the server cap and the client request limit are bumped to 1000 in lockstep.

Confidence Score: 3/5

Safe to merge after addressing the filter-state persistence bug; all other changes are additive and well-scoped.

The connection-switch filter reset bug can silently show zero results — or results filtered by a stale action/source value that doesn't belong to the newly selected connection — with no visible indication to the user beyond the row count. The fix is a single key prop, but without it the feature behaves incorrectly on any warm-cache navigation. The remaining concern (missing label associations) is a minor accessibility gap with no functional impact.

src/pages/AuditLog.tsx — the AuditEntriesView render inside connectionContent needs a key prop tied to connectionId.

Important Files Changed

Filename Overview
src/pages/AuditLog.tsx Adds filter bar and CSV export; filter state is not keyed to connectionId, so it can silently carry stale filter values when the cache is warm.
src/lib/export-csv.ts Type loosened from ColumnMetadata[] to Array<Pick<ColumnMetadata, 'name'>>; logic unchanged and correct.
src/hooks/useQuery.ts Introduces AUDIT_LOG_LIMIT = 1000 constant and applies it to both audit query hooks, matching the new server-side ceiling.
server/services/query-service.ts Server cap raised from 500 to 1000 for both getAuditLogEntries and getSystemAuditLogEntries; auth guards unchanged.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User visits Audit Log tab] --> B{Connection or System?}
    B -->|Connection| C[useAuditLogEntries - limit 1000]
    B -->|System| D[useSystemAuditLogEntries - limit 1000]
    C --> E[EntriesPanel: loading / error / empty guard]
    D --> E
    E -->|entries available| F[AuditEntriesView - useState filters]
    F --> G[AuditFilterBar renders selects + search]
    G --> H{User changes filter}
    H --> I[useMemo: filterEntries called]
    I --> J{scope?}
    J -->|connection| K[ConnectionAuditTable]
    J -->|system| L[SystemAuditTable]
    G -->|Export CSV click| M[exportAuditEntries - filtered entries only]
    M --> N[exportToCsv - PapaParse + blob download]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[User visits Audit Log tab] --> B{Connection or System?}
    B -->|Connection| C[useAuditLogEntries - limit 1000]
    B -->|System| D[useSystemAuditLogEntries - limit 1000]
    C --> E[EntriesPanel: loading / error / empty guard]
    D --> E
    E -->|entries available| F[AuditEntriesView - useState filters]
    F --> G[AuditFilterBar renders selects + search]
    G --> H{User changes filter}
    H --> I[useMemo: filterEntries called]
    I --> J{scope?}
    J -->|connection| K[ConnectionAuditTable]
    J -->|system| L[SystemAuditTable]
    G -->|Export CSV click| M[exportAuditEntries - filtered entries only]
    M --> N[exportToCsv - PapaParse + blob download]
Loading

Reviews (1): Last reviewed commit: "fix: align audit log filter window" | Re-trigger Greptile

Comment thread src/pages/AuditLog.tsx Outdated
Comment thread src/pages/AuditLog.tsx

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread src/lib/export-csv.ts
Comment thread src/pages/AuditLog.tsx Outdated
Comment thread src/pages/AuditLog.tsx Outdated
Comment thread src/pages/AuditLog.tsx Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/hooks/useQuery.ts:356

  • With the audit-log fetch limit increased to 1000, these queries still refetch every 5s. That can significantly increase background load (network + server) compared to the previous 100-row payload. Consider whether the audit log really needs polling this frequently, or make the refetch interval configurable / longer for these endpoints.
const AUDIT_LOG_LIMIT = 1000;

export function useAuditLogEntries(connectionId: string, enabled = true) {
  return useQuery({
    queryKey: queryKeys.auditLog(connectionId),
    queryFn: async () => {
      const response = await queryClient.getAuditLogEntries({ connectionId, limit: AUDIT_LOG_LIMIT });
      return response.entries;
    },
    enabled: enabled && !!connectionId,
    refetchInterval: 5000,
  });
}

// System-level audit entries (auth.login / auth.logout). Owner-gated server-side, so
// only enable the query for instance owners.
export function useSystemAuditLogEntries(enabled = true) {
  return useQuery({
    queryKey: queryKeys.systemAuditLog(),
    queryFn: async () => {
      const response = await queryClient.getSystemAuditLogEntries({ limit: AUDIT_LOG_LIMIT });
      return response.entries;
    },
    enabled,
    refetchInterval: 5000,
  });

Comment thread src/lib/export-csv.ts
@tianzhou tianzhou merged commit 373156d into main Jun 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants