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

feat(settings): A user can edit the root key name #2086

Merged
merged 3 commits into from
Sep 12, 2024

Conversation

mcstepp
Copy link
Collaborator

@mcstepp mcstepp commented Sep 12, 2024

What does this PR do?

Fixes #1979

If there is not an issue for this, please create one first. This is used to tracking purposes and also helps use understand why this PR exists

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  1. Log into Unkey
  2. Go to Settings > Root Keys
  3. Click the [...] next to your root key that you want to modify. If you don't have one, create one.
  4. Select Details
  5. Update the name of the root key in the appropriate card. You can also delete the name if you wanted. Names are optional.
  6. Click Save
  7. Success

https://www.loom.com/share/1d1e6113ab3a4078813d3c4c3666fb3f?sid=0b6e0c44-8e4c-4239-87a9-be5835ec84f8

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features

    • Introduced a new component for updating the name of root keys, enhancing user management of API keys.
    • Streamlined the display of key metrics by removing the key name, focusing on essential attributes like ID and creation date.
  • Bug Fixes

    • Improved error handling and user notifications for key name updates.

Copy link

linear bot commented Sep 12, 2024

Copy link

changeset-bot bot commented Sep 12, 2024

⚠️ No Changeset found

Latest commit: e99d803

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

vercel bot commented Sep 12, 2024

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

Name Status Preview Comments Updated (UTC)
dashboard 🛑 Canceled (Inspect) Sep 12, 2024 7:15pm
planetfall ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 7:15pm
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 7:15pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 7:15pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
workflows ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 7:15pm

Copy link
Contributor

coderabbitai bot commented Sep 12, 2024

Walkthrough

Walkthrough

The pull request introduces a feature allowing users to update the name of a root key within the dashboard. It modifies the existing Layout component by removing the display of the key's name, adds a new UpdateRootKeyName component for editing the name, and implements the necessary backend functionality to handle the update request. This change enhances the user interface and expands the API capabilities related to root key management.

Changes

Files Change Summary
apps/dashboard/app/(app)/settings/root-keys/[keyId]/layout.tsx Removed the Metric component displaying the key's name from the Layout function.
apps/dashboard/app/(app)/settings/root-keys/[keyId]/page.tsx Added UpdateRootKeyName component to allow users to update the root key name.
apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx Introduced UpdateRootKeyName component with form handling for updating the root key name.
apps/dashboard/lib/trpc/routers/index.ts Added update route in the rootKey router for updating the root key name.
apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts Implemented procedure for updating the root key name, including authentication and error handling.

Assessment against linked issues

Objective Addressed Explanation
Allow users to edit the name after the root key is created (#[1979])

Possibly related PRs


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0583b47 and e99d803.

Files selected for processing (5)
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/layout.tsx (0 hunks)
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/page.tsx (2 hunks)
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/index.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/layout.tsx
Files skipped from review as they are similar to previous changes (4)
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/page.tsx
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx
  • apps/dashboard/lib/trpc/routers/index.ts
  • apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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 Sep 12, 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: 0

Outside diff range and nitpick comments (1)
apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts (1)

8-67: LGTM with suggestions!

The updateRootKeyName function is well-structured and follows a clear flow. It handles errors appropriately and logs an audit event for tracking the key update. Great job!

Here are a couple of suggestions for further improvement:

  1. Consider adding input validation for the name property to ensure it meets certain criteria (e.g., length, format). This can help prevent invalid or malicious input.

  2. The error messages can be made more user-friendly and provide more specific details about the error. For example, instead of a generic "We are unable to find the correct key" message, you could include the specific keyId that was not found.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9345e10 and 0583b47.

Files selected for processing (5)
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/layout.tsx (0 hunks)
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/page.tsx (2 hunks)
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/index.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • apps/dashboard/app/(app)/settings/root-keys/[keyId]/layout.tsx
Additional comments not posted (9)
apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx (5)

23-36: LGTM!

The form schema and component prop types are correctly defined. The handling of an empty name string is a good addition.


38-104: Great work!

The UpdateRootKeyName component is well-implemented and follows best practices. The use of React Hook Form and Zod ensures proper form validation and handling. The tRPC mutation is correctly defined, and the form UI is clean and user-friendly.


52-62: Nicely done!

The tRPC mutation is correctly defined and handles success and error cases appropriately. The use of router.refresh() ensures that the page is updated with the new name after a successful update. Parsing the tRPC error and showing a user-friendly error toast is a good practice.


81-92: Looks good!

The form control rendering is correctly implemented and follows the UI library's pattern. The use of FormField, Input, and FormMessage components ensures a consistent and accessible form control.


96-98: Perfect!

The form submission button is correctly implemented and follows best practices. Disabling the button when the mutation is loading or the form is invalid prevents multiple submissions and ensures data integrity. Showing a loading spinner provides good user feedback during the submission process.

apps/dashboard/app/(app)/settings/root-keys/[keyId]/page.tsx (2)

15-15: LGTM!

The import statement for the UpdateRootKeyName component is correctly written. Based on the AI-generated summary, this component is intended to allow users to update the name of a root key, which aligns with the PR objectives.


129-129: Verify the UpdateRootKeyName component functionality.

The UpdateRootKeyName component is correctly rendered within the RootKeyPage component, and the key prop is passed as apiKey. This change aligns with the PR objectives of allowing users to update the name of a root key.

To ensure that the UpdateRootKeyName component correctly updates the root key name, please run the following verification steps:

  1. Navigate to the UpdateRootKeyName component file.
  2. Search for the usage of the apiKey prop within the component.
  3. Verify that the component correctly extracts the root key ID from the apiKey prop.
  4. Ensure that the component sends the updated root key name to the backend API when the user submits the form.
  5. Confirm that the backend API updates the root key name in the database based on the provided ID and new name.
  6. Verify that the updated root key name is correctly displayed in the UI after the update is successful.

If you encounter any issues during the verification process, please let me know, and I'll be happy to assist you further.

apps/dashboard/lib/trpc/routers/index.ts (2)

19-19: LGTM!

The import statement is correctly written and the imported function is likely used in the subsequent code changes.


93-95: Excellent work on implementing the root key name update functionality!

The code change follows the existing router structure and correctly uses the imported updateRootKeyName function to enable updating the name of a root key. This aligns perfectly with the PR objective and enhances the API capabilities for root key management.

Copy link
Collaborator

@perkinsjr perkinsjr left a comment

Choose a reason for hiding this comment

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

Code looks good.

Root key updated for both orgs and users.
Audit log displays correctly.

@perkinsjr perkinsjr enabled auto-merge September 12, 2024 20:25
@perkinsjr perkinsjr added this pull request to the merge queue Sep 12, 2024
Merged via the queue into main with commit 6b0f4f2 Sep 12, 2024
26 checks passed
@perkinsjr perkinsjr deleted the ENG-1284-edit-root-key-name branch September 12, 2024 20:29
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.

Root Key doesn't have feature to edit name after creation
3 participants