Skip to content

feat: add audit log page - #23

Merged
tianzhou merged 4 commits into
mainfrom
feat/audit-log-page
Jun 25, 2026
Merged

tianzhou merged 4 commits into
mainfrom
feat/audit-log-page

Conversation

@tianzhou

Copy link
Copy Markdown
Contributor

Summary

Adds an admin-only, per-connection Audit Log page at /audit-log.

  • New AuditLog page (src/pages/AuditLog.tsx) — full-width, with a connection dropdown filter that drives the connectionId query param. Gated on the selected connection's admin permission (non-admins see a "need admin permission" message).
  • Route wired into App.tsx. The connection-validation redirect (missing/invalid connectionId → first connection) is generalized from editor-only to connection-scoped routes (/ and /audit-log), preserving the current path.
  • Sidebar footer entry point in ObjectSidebar.tsx: a horizontal divider with an audit-log icon (navigates to /audit-log) on the left and the app version on the right; hovering the version shows the git commit hash.

Notes

  • The page is currently a stub — empty-state placeholder where the log table will go. No backend/RPC for audit data exists yet; that's a follow-up (proto + service).
  • There's no audit data source wired in; the dropdown and gating are functional.

Test plan

  • /audit-log?connectionId=<id> renders for an admin on that connection
  • Non-admin on the selected connection sees the gated message
  • Connection dropdown updates the connectionId param
  • Visiting /audit-log with no/invalid connectionId redirects to the first connection
  • Sidebar footer icon navigates to the page; version tooltip shows the commit hash

🤖 Generated with Claude Code

Add an admin-only, per-connection audit log page at /audit-log:
- New AuditLog page with a connection dropdown filter that drives the
  connectionId query param, gated on the connection's admin permission
- Route wired in App.tsx; connection-validation redirect generalized to
  cover connection-scoped routes (/ and /audit-log)
- Sidebar footer entry point: an audit-log icon plus the app version,
  with the git commit hash shown on hover

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 25, 2026 10:22
@vercel

vercel Bot commented Jun 25, 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 25, 2026 11:00am

@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds an admin-gated /audit-log page (stub), wires it into the router, generalizes the connectionId redirect logic to cover all connection-scoped routes, and adds a sidebar footer with an audit-log icon and version tooltip.

  • AuditLog.tsx: Admin gate checks hasAdmin synchronously before useConnections resolves, showing the "need admin permission" message to all users on first load; the connection dropdown is also hidden in the gated view, leaving non-admin users with no in-page way to switch connections.
  • App.tsx: Redirect generalization is clean, but the hasShownInvalidToast ref is never reset on route change, so only the first invalid-connection redirect across the session surfaces a toast.
  • ObjectSidebar.tsx: Footer addition is clean and straightforward.

Confidence Score: 3/5

Safe to merge as a stub, but the permission gate will incorrectly deny every admin user during initial data load, which should be fixed before the page goes beyond placeholder content.

The admin gate in AuditLog.tsx renders the 'need admin permission' message before connections data resolves, so every admin user sees the wrong state on first load. The gated view also hides the connection dropdown, making it impossible to recover to an admin connection without leaving the page.

src/pages/AuditLog.tsx — the permission gate and connection-dropdown placement both need attention before this page carries live data.

Important Files Changed

Filename Overview
src/pages/AuditLog.tsx New audit log page with admin permission gating; gate fires before connections data loads (false negative for admins on first render), and the connection dropdown is absent from the gated view leaving users stranded on non-admin connections.
src/App.tsx Connection-validation redirect generalized from editor-only to all connection-scoped routes; hasShownInvalidToast ref is never reset between route changes, so the second invalid-connection redirect on a different scoped route fires silently.
src/components/sql-editor/ObjectSidebar.tsx Adds a sidebar footer with an audit-log navigation icon and a version/commit-hash tooltip; straightforward and correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User navigates to /audit-log] --> B{connectionId in URL?}
    B -- No --> C[Redirect: pathname + first connection]
    B -- Yes --> D{Valid connectionId?}
    D -- No --> E[Show toast + Redirect: pathname + first connection]
    D -- Yes --> F[Render AuditLog with selectedConnectionId]
    F --> G{connections loaded?}
    G -- Not yet --> H[Show 'need admin permission' message - false negative]
    G -- Loaded --> I{hasAdmin?}
    I -- No --> J[Show 'need admin permission' message - no dropdown]
    I -- Yes --> K[Show Audit Log + Connection Dropdown stub]
    K --> L{User changes connection}
    L --> M[navigate /audit-log?connectionId=new-id]
    M --> F
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 navigates to /audit-log] --> B{connectionId in URL?}
    B -- No --> C[Redirect: pathname + first connection]
    B -- Yes --> D{Valid connectionId?}
    D -- No --> E[Show toast + Redirect: pathname + first connection]
    D -- Yes --> F[Render AuditLog with selectedConnectionId]
    F --> G{connections loaded?}
    G -- Not yet --> H[Show 'need admin permission' message - false negative]
    G -- Loaded --> I{hasAdmin?}
    I -- No --> J[Show 'need admin permission' message - no dropdown]
    I -- Yes --> K[Show Audit Log + Connection Dropdown stub]
    K --> L{User changes connection}
    L --> M[navigate /audit-log?connectionId=new-id]
    M --> F
Loading

Reviews (1): Last reviewed commit: "feat: add audit log page" | Re-trigger Greptile

Comment thread src/pages/AuditLog.tsx Resolved
Comment thread src/pages/AuditLog.tsx Resolved
Comment thread src/App.tsx Outdated
Comment on lines 55 to 65
@@ -57,9 +61,9 @@ function AppLayout() {
type: 'error',
});
}
navigate(`/?connectionId=${connections[0].id}`, { replace: true });
navigate(`${location.pathname}?connectionId=${connections[0].id}`, { replace: true });
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 hasShownInvalidToast ref never resets on route change

The hasShownInvalidToast ref is set to true the first time an invalid connectionId triggers a redirect, but it is never cleared. Because the ref persists for the lifetime of AppLayout, switching between / and /audit-log with an invalid connectionId will only ever surface the toast once per session. A second invalid-connection navigation to a different connection-scoped route will redirect silently.

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 a new admin-only, per-connection Audit Log page at /audit-log, wires it into routing, and introduces a sidebar footer entry point that links to the page and exposes build metadata.

Changes:

  • Added a new AuditLog page with a connection dropdown and an empty-state placeholder.
  • Updated routing to include /audit-log and generalized connectionId validation/redirect to connection-scoped routes.
  • Added an ObjectSidebar footer with an Audit Log icon and a version tooltip showing the git commit hash.

Reviewed changes

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

File Description
src/pages/AuditLog.tsx New Audit Log page (stub UI) with connection selection and admin gating.
src/components/sql-editor/ObjectSidebar.tsx Adds sidebar footer entry point to Audit Log + version/commit tooltip.
src/App.tsx Registers /audit-log route and generalizes connectionId redirect logic to include it.

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

Comment thread src/App.tsx Resolved
Comment thread src/pages/AuditLog.tsx Resolved
- AuditLog: defer the admin gate until connections load so admins don't
  flash the denied state; keep the connection dropdown outside the gate
  so non-admins can switch to a connection they can access
- App: gate useEditorNavigation to the editor route so /audit-log no longer
  writes editor URL params (schema/object) or fires schema/table queries;
  reset the invalid-connection toast guard on valid connections
- useEditorNavigation/useQuery: thread an enabled flag through to disable
  schema/table queries and the URL-sync effect when inactive
- ObjectSidebar: add aria-label to the audit-log icon button and make the
  version tooltip trigger keyboard-focusable

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

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 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/pages/AuditLog.tsx Outdated
Comment on lines +14 to +30
const { data: connections, isLoading } = useConnections()
const { hasAdmin } = useConnectionPermissions(connectionId)

// Permissions are derived from the connections query, so defer the admin gate
// until it resolves — otherwise admins briefly see the denied state on load.
const content = isLoading || !connections ? (
<div className="text-gray-500 text-sm">Loading…</div>
) : !hasAdmin ? (
<p className="text-gray-600">
You need admin permission on this connection to view its audit log.
</p>
) : (
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-gray-300 py-16 text-gray-500">
<ScrollText size={32} />
<p className="text-sm">No audit log entries yet.</p>
</div>
)
Resolve useConnections() error and empty-list states explicitly before
the admin gate, so a query error no longer shows "Loading…" forever and
zero connections shows a clear message instead of "need admin permission".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

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 5 out of 5 changed files in this pull request and generated 1 comment.

Replace the focusable <span tabIndex=0> with a <button type="button"> so
the version/commit tooltip trigger has proper interactive semantics for
keyboard and screen-reader users.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tianzhou
tianzhou merged commit 833a951 into main Jun 25, 2026
3 checks passed
@tianzhou
tianzhou deleted the feat/audit-log-page branch June 29, 2026 09:04

This branch was successfully deployed

1 active deployment
Preview — 548deabf Deployed Jun 25, 2026 by vercel[bot]
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