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: UI for update and create key #2795

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

MichaelUnkey
Copy link
Collaborator

@MichaelUnkey MichaelUnkey commented Jan 8, 2025

What does this PR do?

Fixes # (issue)

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?

Verify creating and updating keys work as expected.

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

    • Enhanced key management settings with more dynamic refill interval options.
    • Added ability to select refill intervals: "none", "daily", and "monthly".
    • Improved form validation for key limit and refill settings.
  • Bug Fixes

    • Refined form logic to ensure consistent and logical input for refill settings.
    • Improved handling of default values for refill intervals and amounts.
    • Disabled refill amount field when refill interval is not valid.

Copy link

changeset-bot bot commented Jan 8, 2025

⚠️ No Changeset found

Latest commit: 1acc997

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 Jan 8, 2025

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 Jan 9, 2025 7:34pm
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 7:34pm
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 7:34pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 7:34pm

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

📝 Walkthrough

Walkthrough

This pull request introduces modifications to key management components in the dashboard application, specifically focusing on refill settings for API keys. The changes primarily affect two files: update-key-remaining.tsx and new/client.tsx. The modifications enhance the form's capability to handle refill intervals, with new logic for setting default values, managing form submission, and improving field interdependencies. The updates introduce a more dynamic approach to configuring key usage limits and refill settings.

Changes

File Change Summary
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/settings/update-key-remaining.tsx - Added new select component imports
- Introduced interval field in refill schema
- Updated form default value logic
- Modified form submission conditions
- Added new FormField for refill interval
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx - Changed default limit.refill.interval to "none"
- Updated limit.refill.amount field handling
- Added conditional disabling logic for refill amount
- Removed limit.refill.refillDay field
packages/api/package.json - Reformatted keywords and files arrays to single-line format
packages/hono/package.json - Reformatted keywords and files arrays to single-line format
packages/nextjs/package.json - Reformatted keywords and files arrays to single-line format
packages/ratelimit/package.json - Reformatted keywords and files arrays to single-line format

Possibly related PRs

  • feat: allow-developer-to-set-a-custom-refill-time-when-using-the #2114: This PR introduces a new optional property, refillDay, to the refill object schema, which is directly related to the changes in the main PR that also involve managing refill settings and the refill object.
  • fix: create key toggle issue #2711: This PR modifies the CreateKey component to enhance form handling logic, including the management of the refill object, which aligns with the changes made in the main PR regarding the UpdateKeyRemaining component's logic for refill settings.
  • fix: enable card correctly #2794: This PR focuses on enabling the card correctly based on the remaining and refillAmount properties, which is directly related to the logic changes in the main PR regarding how refill settings are managed.

Suggested labels

Bug, Needs Approval

Suggested reviewers

  • mcstepp
  • chronark
  • ogzhanolguncu
  • perkinsjr

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 99ac8db and 1acc997.

📒 Files selected for processing (6)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx (6 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (4 hunks)
  • packages/api/package.json (1 hunks)
  • packages/hono/package.json (1 hunks)
  • packages/nextjs/package.json (1 hunks)
  • packages/ratelimit/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • packages/ratelimit/package.json
  • packages/hono/package.json
  • packages/nextjs/package.json
  • packages/api/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: Test Packages / Test ./packages/rbac
  • GitHub Check: Test Packages / Test ./packages/nextjs
  • GitHub Check: Test Packages / Test ./packages/hono
  • GitHub Check: Test Packages / Test ./packages/cache
  • GitHub Check: Test Packages / Test ./packages/api
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Build / Build
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test Packages / Test ./internal/hash
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)

Finishing Touches

  • 📝 Generate Docstrings

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 Jan 8, 2025

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

🧹 Nitpick comments (3)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx (3)

79-79: Consider simplifying the interval initialization logic.

The current initialization can be simplified using a more straightforward approach.

-        interval: apiKey.refillDay ? "monthly" : apiKey.refillAmount ? "daily" : "none",
+        interval: apiKey.refillDay 
+          ? "monthly" 
+          : apiKey.refillAmount 
+            ? "daily" 
+            : "none",

Also applies to: 82-82


107-109: Consider adding additional validation for refill settings.

While the current validation is good, consider adding these checks:

  1. Validate that refill amount is less than or equal to the remaining amount
  2. Validate that monthly refill day is within the valid range (1-28) to handle all months consistently
+    if (values.refill?.amount && values.remaining && values.refill.amount > values.remaining) {
+      form.setError("refill.amount", {
+        message: "Refill amount cannot be greater than remaining uses",
+      });
+      return;
+    }
+
+    if (values.refill?.interval === "monthly" && values.refill?.refillDay) {
+      if (values.refill.refillDay > 28) {
+        form.setError("refill.refillDay", {
+          message: "Please select a day between 1-28 to ensure consistent monthly refills",
+        });
+        return;
+      }
+    }

Also applies to: 111-116, 125-127


206-207: Consider simplifying the disabled conditions.

The disabled conditions could be more concise while maintaining readability.

-                  !form.watch("limitEnabled") === true ||
-                  form.watch("refill.interval") === "none"
+                  !form.watch("limitEnabled") || form.watch("refill.interval") === "none"

Also applies to: 234-236, 244-244, 248-253

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 727ef7d and cd6f2a1.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx (6 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Test Packages / Test ./packages/rbac
  • GitHub Check: Test Packages / Test ./packages/nextjs
  • GitHub Check: Test Packages / Test ./packages/hono
  • GitHub Check: Test Packages / Test ./packages/cache
  • GitHub Check: Test Packages / Test ./packages/api
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Packages / Test ./internal/resend
  • GitHub Check: Test Packages / Test ./internal/keys
  • GitHub Check: Test Packages / Test ./internal/id
  • GitHub Check: Test Packages / Test ./internal/hash
  • GitHub Check: Test Packages / Test ./internal/encryption
  • GitHub Check: Test Packages / Test ./internal/billing
  • GitHub Check: Build / Build
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test API / API Test Local
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx (3)

23-29: LGTM!

The select components are correctly imported from the UI library.


46-46: LGTM!

The schema changes are well-structured:

  • The interval field correctly uses an enum type with appropriate values
  • The amount field validation is properly chained

Also applies to: 50-51


176-200: LGTM!

The refill interval form field is well-implemented with:

  • Proper disabled conditions
  • Clear labeling and descriptions
  • Appropriate use of UI components
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (1)

510-510: LGTM!

The default value handling for refill interval is consistent with the update form implementation.

…-you-to-choose' of https://github.com/unkeyed/unkey into eng-1598-creating-a-key-in-the-ui-with-remaining-forces-you-to-choose
Copy link
Collaborator

@chronark chronark left a comment

Choose a reason for hiding this comment

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

I was able to create a key with remaining, interval but without refillAmount, the rest looks fine
CleanShot 2025-01-09 at 07 28 49@2x

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