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: check whether it's undefined #2817

Merged
merged 4 commits into from
Jan 14, 2025
Merged

fix: check whether it's undefined #2817

merged 4 commits into from
Jan 14, 2025

Conversation

chronark
Copy link
Collaborator

@chronark chronark commented Jan 14, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced form for creating keys with improved handling of rate limiting configurations, including new properties for refill settings.
  • Bug Fixes
    • Improved validation logic for key refill settings to prevent potential undefined value errors.
    • Enhanced input validation for refill interval and amount fields, allowing for more flexible input handling.
    • Updated validation schema to make the refill day optional, enhancing user input flexibility.

Copy link

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

Copy link

changeset-bot bot commented Jan 14, 2025

⚠️ No Changeset found

Latest commit: 41b5b96

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

📝 Walkthrough

Walkthrough

The pull request introduces changes to the validation logic in the UpdateKeyRemaining component, specifically refining the condition that checks the refill.amount field by adding an explicit check for undefined interval. The CreateKey component's structure has been updated to include a new limit property in defaultValues, enhancing the handling of rate limiting configurations. Additionally, the validation schema has been modified to make the refillDay field optional, allowing it to be omitted from input.

Changes

File Change Summary
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx Updated validation condition for refill.amount to explicitly check for undefined interval before applying existing validation logic.
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx Modified CreateKey component to include a new structure for limit in defaultValues, adjusted onSubmit logic for refill, and refined handling of limit.refill.amount input.
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/validation.ts Changed refillDay field in validation schema to be optional, removing its mandatory default value.

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 relevant to the changes in the UpdateKeyRemaining component's validation logic in the main PR.
  • fix: enable card correctly #2794: This PR modifies the logic for determining the limitEnabled field in the UpdateKeyRemaining component, which is directly related to the changes made in the main PR regarding the validation logic for refill amounts.
  • fix: UI for update and create key #2795: This PR updates the UpdateKeyRemaining component to include an optional interval field within the refill object, which is directly related to the changes made in the main PR regarding the validation logic for the refill.amount field.

Suggested labels

Bug, Needs Approval

Suggested reviewers

  • mcstepp
  • perkinsjr
  • ogzhanolguncu
  • MichaelUnkey

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 14, 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: 0

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

111-115: LGTM! Consider enhancing type safety further.

The addition of the undefined check improves the robustness of the validation logic.

For even better type safety, consider using a type guard or the nullish coalescing operator:

-    if (
-      values.refill?.interval !== undefined &&
-      values.refill?.interval !== "none" &&
-      !values.refill?.amount
-    ) {
+    if (values.refill?.interval && values.refill.interval !== "none" && !values.refill.amount) {

This approach is more concise and ensures that interval is both defined and not "none" in a single check.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between abf169d and f26d515.

📒 Files selected for processing (1)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Build / Build

This adds correct validation to the form, it also fixes an issue where
we don't set interval back to undefined if it set to none. So the form
is always refilling.
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: 2

🧹 Nitpick comments (1)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (1)

122-125: Use explicit undefined check for more precise logic.

The current condition might incorrectly handle edge cases where refillDay is 0. Use an explicit undefined check for more precise control.

Apply this diff to improve the logic:

   if (refill?.interval === "daily") {
     refill.refillDay = undefined;
   }
-  if (refill?.interval === "monthly" && !refill.refillDay) {
+  if (refill?.interval === "monthly" && refill.refillDay === undefined) {
     refill.refillDay = 1;
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f26d515 and 7ee51dc.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (3 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/validation.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Build / Build
🔇 Additional comments (1)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (1)

71-78: LGTM! Well-structured form initialization.

The default values are properly structured with appropriate initial states for all fields.

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 comments (1)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (1)

Line range hint 744-748: Fix incorrect error message in metadata section.

The metadata card is incorrectly showing rate limit errors. This appears to be copy-pasted error handling that should be specific to metadata validation.

-                            {form.formState.errors.ratelimit && (
-                              <p className="text-xs text-center text-content-alert">
-                                {form.formState.errors.ratelimit.message}
-                              </p>
-                            )}
+                            {form.formState.errors.meta && (
+                              <p className="text-xs text-center text-content-alert">
+                                {form.formState.errors.meta.message}
+                              </p>
+                            )}
🧹 Nitpick comments (1)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (1)

122-125: Add validation for monthly refill day.

While the logic for handling refill days is correct, consider adding validation to ensure the refill day is between 1 and 31 when the interval is monthly.

    if (refill?.interval === "monthly" && !refill.refillDay) {
      refill.refillDay = 1;
    }
+   if (refill?.interval === "monthly" && (refill.refillDay < 1 || refill.refillDay > 31)) {
+     form.setError("limit.refill.refillDay", {
+       type: "manual",
+       message: "Refill day must be between 1 and 31",
+     });
+     return;
+   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ee51dc and ba24aaa.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (3 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/validation.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/validation.ts
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Test Packages / Test ./packages/hono
  • 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: Test API / API Test Local
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Build / Build
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (2)

71-78: Well-structured initialization of the limit configuration!

The nested structure provides good type safety and proper initialization of all fields.


528-528: Properly controlled Select component.

The removal of defaultValue in favor of value prop aligns with React's controlled component pattern.

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

🧹 Nitpick comments (1)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (1)

122-124: Consider a more explicit check for the monthly refill day.

The condition !refill.refillDay would treat 0 as falsy. Consider using refill.refillDay === undefined for a more explicit check.

-    if (refill?.interval === "monthly" && !refill.refillDay) {
+    if (refill?.interval === "monthly" && refill.refillDay === undefined) {
       refill.refillDay = 1;
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba24aaa and 41b5b96.

📒 Files selected for processing (1)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Test Packages / Test ./packages/nextjs
  • 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 API / API Test Local
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test Packages / Test ./internal/hash
  • GitHub Check: Test Packages / Test ./internal/encryption
  • GitHub Check: Build / Build
  • GitHub Check: autofix
  • GitHub Check: Test Packages / Test ./internal/billing
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx (2)

71-78: LGTM! Well-structured default values for the limit configuration.

The default values are properly structured with appropriate initial values for optional fields.


526-526: LGTM! Properly implemented controlled component pattern.

The redundant defaultValue prop has been removed, and the component is now properly controlled via the value prop.

@perkinsjr perkinsjr merged commit f6ffe80 into main Jan 14, 2025
26 checks passed
@perkinsjr perkinsjr deleted the update-remaining-form branch January 14, 2025 19:47
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