Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: audit log filters use search params #2769

Merged
merged 1 commit into from
Dec 20, 2024
Merged

fix: audit log filters use search params #2769

merged 1 commit into from
Dec 20, 2024

Conversation

chronark
Copy link
Collaborator

@chronark chronark commented Dec 20, 2024

This moves the audit logs from /audit/[bucket] to /audit?bucket= to make use of unified tooling via nuqs

Summary by CodeRabbit

  • New Features

    • Introduced a new BucketSelect component for selecting audit log buckets.
    • Added an AuditPage component for displaying audit logs with enhanced data fetching and conditional rendering.
  • Bug Fixes

    • Updated placeholder text in the Filter component from "Events" to "Search".
  • Refactor

    • Renamed parameters from bucket to bucketName across various components and functions for clarity.
    • Streamlined filtering logic to focus on audit logs.
  • Chores

    • Updated import paths for better structure and clarity.

Copy link

vercel bot commented Dec 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 10:39am
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 10:39am
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 10:39am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 10:39am

Copy link

changeset-bot bot commented Dec 20, 2024

⚠️ No Changeset found

Latest commit: 7d37e24

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Dec 20, 2024

📝 Walkthrough

Walkthrough

This pull request introduces significant changes to the audit logs functionality in the dashboard application. The modifications primarily focus on refactoring the audit log components, updating type definitions, and improving the user interface for selecting and filtering audit logs. The changes include renaming parameters, simplifying database queries, and restructuring components to provide a more streamlined approach to displaying and interacting with audit log data.

Changes

File Path Change Summary
apps/dashboard/app/(app)/audit/actions.ts Updated type definitions and function signatures, replacing bucket with bucketName
apps/dashboard/app/(app)/audit/components/filters/bucket-select.tsx New BucketSelect component with dynamic bucket selection using useQueryState
apps/dashboard/app/(app)/audit/components/filters/index.tsx Updated filtering logic and type definitions for workspace selection
apps/dashboard/app/(app)/audit/page.tsx Replaced redirect with a full AuditPage component, added dynamic rendering options
apps/dashboard/lib/trpc/routers/audit/fetch.ts Renamed bucket parameter to bucketName in input schemas and query functions
Other files Minor updates to component imports, filtering, and UI text

Suggested labels

dashboard, audit-logs, refactoring, ui-improvement

Suggested reviewers

  • mcstepp
  • perkinsjr
  • MichaelUnkey
  • ogzhanolguncu

Possibly related PRs

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Dec 20, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
apps/dashboard/app/(app)/audit/actions.ts (1)

Line range hint 55-67: Consider extracting the default bucket name to a constant

The hardcoded value "unkey_mutations" is used as a default. This should be centralized with other constants like DEFAULT_BUCKET_NAME that's imported in filters/index.tsx.

- bucketName: bucketParser.withDefault("unkey_mutations").parseServerSide(params.bucketName),
+ bucketName: bucketParser.withDefault(DEFAULT_BUCKET_NAME).parseServerSide(params.bucketName),
🧹 Nitpick comments (6)
apps/dashboard/app/(app)/audit/page.tsx (2)

1-5: Use caution with external icon library imports.
The usage of "@unkey/icons" is fine here, but be mindful of potential increases in bundle size if many icons are imported. Consider only importing the needed icons or treeshaking the library if possible.


40-51: Provide actionable suggestions in EmptyPlaceholder.
Currently, the "No logs" message suggests creating a key or resource. Consider linking directly to relevant pages, or providing a CTA button to guide users more effectively (e.g. "Create Key").

apps/dashboard/app/(app)/audit/components/filters/bucket-select.tsx (1)

30-43: Refine labeling for clarity.
Currently, the label "Ratelimit: {b.name}" is shown for buckets other than "unkey_mutations". If these buckets no longer relate specifically to rate limiting, adapt the label to reflect their true purpose within the audit logs.

- {b.name === "unkey_mutations" ? "System" : `Ratelimit: ${b.name}`}
+ {b.name === "unkey_mutations" ? "System" : `Audit Bucket: ${b.name}`}
apps/dashboard/app/(app)/audit/actions.ts (1)

11-16: Consider adding an index for the orderBy clause

The query now includes an orderBy clause on createdAt. For optimal performance, ensure there's an index on this column.

apps/dashboard/app/(app)/audit/components/filters/index.tsx (2)

19-19: Consider adding prop validation

Since selectedBucketName is required and should match available bucket names, consider adding runtime validation.

if (!workspace.auditLogBuckets.some(b => b.name === selectedBucketName)) {
  console.warn(`Invalid bucket name: ${selectedBucketName}`);
}

Also applies to: 23-23


Line range hint 29-48: Consider extracting event options to a constant

The hardcoded ratelimit events could be moved to a constant for better maintainability.

const RATELIMIT_EVENTS = [
  { value: "ratelimit.success", label: "Ratelimit success" },
  { value: "ratelimit.denied", label: "Ratelimit denied" }
] as const;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9dcdc7 and 7d37e24.

📒 Files selected for processing (12)
  • apps/dashboard/app/(app)/audit/[bucket]/components/filters/bucket-select.tsx (0 hunks)
  • apps/dashboard/app/(app)/audit/[bucket]/page.tsx (0 hunks)
  • apps/dashboard/app/(app)/audit/actions.ts (4 hunks)
  • apps/dashboard/app/(app)/audit/components/filters/bucket-select.tsx (1 hunks)
  • apps/dashboard/app/(app)/audit/components/filters/filter.tsx (1 hunks)
  • apps/dashboard/app/(app)/audit/components/filters/index.tsx (3 hunks)
  • apps/dashboard/app/(app)/audit/components/filters/root-key-filter.tsx (1 hunks)
  • apps/dashboard/app/(app)/audit/components/filters/user-filter.tsx (1 hunks)
  • apps/dashboard/app/(app)/audit/components/table/audit-log-table-client.tsx (1 hunks)
  • apps/dashboard/app/(app)/audit/components/table/table-details.tsx (1 hunks)
  • apps/dashboard/app/(app)/audit/page.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/audit/fetch.ts (6 hunks)
💤 Files with no reviewable changes (2)
  • apps/dashboard/app/(app)/audit/[bucket]/page.tsx
  • apps/dashboard/app/(app)/audit/[bucket]/components/filters/bucket-select.tsx
✅ Files skipped from review due to trivial changes (1)
  • apps/dashboard/app/(app)/audit/components/filters/filter.tsx
🔇 Additional comments (12)
apps/dashboard/app/(app)/audit/page.tsx (2)

10-11: Be aware of forced dynamic rendering and edge runtime.
Using dynamic = "force-dynamic" and runtime = "edge" may impact SSR caching and performance. Verify that these align with your caching and scaling strategies.

Would you like to run a script to check how often these flags appear in your codebase and confirm usage intent?


30-39: Clarify table client dependencies.
While the conditional logic for rendering is straightforward, ensure that necessary filters or data are passed to the table if you plan to handle user interactions or advanced sorting/pagination later.

apps/dashboard/app/(app)/audit/components/filters/root-key-filter.tsx (1)

8-9: Reassess deleted and expired keys filtering.
Previously, keys might have been filtered to exclude deleted or expired ones. Now, the code no longer checks that. Confirm whether you still need to exclude those keys to avoid confusing or invalid results.

apps/dashboard/app/(app)/audit/components/filters/user-filter.tsx (1)

10-10: Ensure tenant ID logic is consistent.
The conditional check for tenantId.startsWith("user_") might skip revealing certain organization members if the ID is unexpected. Confirm that all valid organization IDs do not start with "user_".

apps/dashboard/app/(app)/audit/components/filters/bucket-select.tsx (1)

17-25: Verify default bucket logic.
The default value "unkey_mutations" might be a legacy placeholder. Ensure it remains relevant for new or reorganized audit log structures.

apps/dashboard/app/(app)/audit/actions.ts (1)

42-42: Verify the type change impact across the codebase

The type change from optional bucket to required bucketName in ParsedParams could affect existing code. Ensure all consumers handle this non-nullable requirement correctly.

Also applies to: 51-51

apps/dashboard/app/(app)/audit/components/filters/index.tsx (1)

3-3: LGTM! Type safety improvements

Good use of explicit type imports and schema definitions.

Also applies to: 15-15

apps/dashboard/app/(app)/audit/components/table/table-details.tsx (1)

6-6: LGTM! Import path simplified

The import path has been simplified by removing unnecessary parent directory traversal.

apps/dashboard/app/(app)/audit/components/table/audit-log-table-client.tsx (1)

22-22: LGTM: Parameter rename maintains functionality

The rename from bucket to bucketName is consistent with the schema changes in the TRPC router. The optional chaining and undefined fallback are handled correctly.

apps/dashboard/lib/trpc/routers/audit/fetch.ts (3)

14-14: LGTM: Schema update with proper default

The schema correctly defines bucketName with a default value of DEFAULT_BUCKET_NAME, maintaining backward compatibility.


27-27: LGTM: Consistent parameter destructuring

The destructuring pattern matches the updated schema definition.


132-133: Verify query performance with renamed field

The query condition has been updated to use bucketName, but we should verify the performance impact.

apps/dashboard/app/(app)/audit/page.tsx Show resolved Hide resolved
@chronark chronark added this pull request to the merge queue Dec 20, 2024
Merged via the queue into main with commit e886e0d Dec 20, 2024
29 checks passed
@chronark chronark deleted the audit-logs-filters branch December 20, 2024 10:44
This was referenced Jan 13, 2025
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