Skip to content

fix: correct disabled stats metric displaying valid count instead of …#2796

Merged
ogzhanolguncu merged 2 commits intomainfrom
fix/api-key-disabled-stats-display
Jan 9, 2025
Merged

fix: correct disabled stats metric displaying valid count instead of …#2796
ogzhanolguncu merged 2 commits intomainfrom
fix/api-key-disabled-stats-display

Conversation

@ogzhanolguncu
Copy link
Contributor

@ogzhanolguncu ogzhanolguncu commented Jan 9, 2025

…disabled

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?

  • Test A
  • Test B

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

  • Bug Fixes

    • Corrected the label for "Disabled" metric to accurately display the count of disabled verifications.
  • New Features

    • Introduced a new date formatting function for improved date display in charts.
    • Updated tooltip configuration to utilize the new date formatting function.
  • Refactor

    • Enhanced readability of color definitions in the chart components.

@ogzhanolguncu ogzhanolguncu marked this pull request as ready for review January 9, 2025 09:46
@changeset-bot
Copy link

changeset-bot bot commented Jan 9, 2025

⚠️ No Changeset found

Latest commit: fc3dd27

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

@vercel
Copy link

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the APIKeyDetailPage component and the StackedColumnChart component. Key changes in the APIKeyDetailPage include the creation of a sortedVerifications array for sorting verification data, the introduction of uniqueDates for capturing unique timestamps, and updates to the verification outcome arrays to ensure they reflect all timestamps, including those with zero counts. In the StackedColumnChart, a new formatDate function is added to format dates based on granularity, along with enhancements to tooltip configurations.

Changes

File Change Summary
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx - Introduced sortedVerifications for sorting verification data
- Added uniqueDates to capture unique timestamps
- Updated verification outcome arrays to include zero counts for all timestamps
- Corrected label for "Disabled" metric to reference stats.disabled
apps/dashboard/components/dashboard/charts.tsx - Modified useColors function for improved readability
- Added formatDate(date: string) function for date formatting
- Updated tooltip configuration to use formatDate and enhanced numerical value formatting

Suggested labels

Bug, Improvement

Suggested reviewers

  • mcstepp
  • chronark
  • perkinsjr

Possibly related PRs

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.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 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]/page.tsx (1)

Line range hint 212-241: Consider performance optimizations for role tree construction.

The role tree construction logic is correct but could benefit from performance optimizations:

  1. Consider memoizing the nested permissions structure to prevent unnecessary recalculations on re-renders
  2. The deeply nested loops for permission path processing could be optimized for large permission sets

Here's a suggested optimization using memoization:

+ import { useMemo } from 'react';

  const roleTee = key.workspace.roles.map((role) => {
+   const buildNestedPermissions = useMemo(() => {
      const nested: NestedPermissions = {};
      for (const permission of key.workspace.permissions) {
        let n = nested;
        const parts = permission.name.split(".");
        for (let i = 0; i < parts.length; i++) {
          const p = parts[i];
          if (!(p in n)) {
            n[p] = {
              id: permission.id,
              name: permission.name,
              description: permission.description,
              checked: role.permissions.some((p) => p.permissionId === permission.id),
              part: p,
              permissions: {},
              path: parts.slice(0, i).join("."),
            };
          }
          n = n[p].permissions;
        }
      }
      return nested;
+   }, [key.workspace.permissions, role.permissions]);

    return {
      id: role.id,
      name: role.name,
      description: role.description,
      keyId: key.id,
      active: key.roles.some((keyRole) => keyRole.roleId === role.id),
-     nestedPermissions: nested,
+     nestedPermissions: buildNestedPermissions,
    };
  });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 71d211e and 8978f1b.

📒 Files selected for processing (1)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx (2 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 API / API Test Local
  • GitHub Check: Test Packages / Test ./internal/billing
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Build / Build
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx (1)

332-332: LGTM! Correct fix for disabled stats display.

The metric now correctly displays the count of disabled verifications using stats.disabled instead of stats.valid.

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 (2)
apps/dashboard/components/dashboard/charts.tsx (2)

139-141: LGTM! Consider extracting the unit as a prop.

The addition of the 'ms' unit improves clarity. However, to make the component more reusable, consider making the unit configurable through props.

 export const LineChart: React.FC<{
   data: {
     category: string;
     x: string;
     y: number;
   }[];
+  unit?: string;
 }> = ({ data }) => {
   // ...
   tooltip={{
     formatter: (datum) => ({
       name: datum.category,
       value: `${Intl.NumberFormat(undefined, {
         notation: "compact",
-      }).format(Number(datum.y))} ms`,
+      }).format(Number(datum.y))}${unit ? ` ${unit}` : ''}`,
     }),
   }}

208-254: LGTM! Consider extracting date formatting logic to a shared utility.

The date formatting implementation is robust with proper error handling and granularity support. However, there are opportunities for improvement:

  1. This formatting logic could be useful in other components. Consider moving it to a shared utility file.
  2. Some date format options are repeated across cases. Consider creating shared format configurations.

Example refactor:

// utils/dateFormatting.ts
const SHARED_DATE_FORMAT = {
  month: "short",
  day: "numeric",
  year: "numeric",
} as const;

export const formatDateByGranularity = (
  date: string,
  granularity?: "minute" | "hour" | "day" | "month"
) => {
  const d = new Date(date);
  if (Number.isNaN(d.getTime())) {
    return date;
  }

  const formats: Record<string, Intl.DateTimeFormatOptions> = {
    minute: {
      ...SHARED_DATE_FORMAT,
      hour: "numeric",
      minute: "2-digit",
      hour12: true,
    },
    hour: {
      ...SHARED_DATE_FORMAT,
      hour: "numeric",
      hour12: true,
    },
    // ... other cases
  };

  return d.toLocaleString(undefined, formats[granularity] ?? formats.minute);
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8978f1b and fc3dd27.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx (4 hunks)
  • apps/dashboard/components/dashboard/charts.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/page.tsx
⏰ 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 Agent Local / test_agent_local
  • GitHub Check: Test Packages / Test ./internal/billing
  • GitHub Check: Build / Build
  • GitHub Check: Test API / API Test Local
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
apps/dashboard/components/dashboard/charts.tsx (2)

11-14: LGTM! Improved type definition readability.

The multi-line format enhances code readability while maintaining the same type structure.


329-336: LGTM! Enhanced tooltip formatting.

The tooltip improvements provide better number formatting with appropriate precision control and compact display. The integration with the new formatDate function ensures consistent date formatting.

@ogzhanolguncu ogzhanolguncu added this pull request to the merge queue Jan 9, 2025
Merged via the queue into main with commit 7664efc Jan 9, 2025
@ogzhanolguncu ogzhanolguncu deleted the fix/api-key-disabled-stats-display branch January 9, 2025 10:48
@coderabbitai coderabbitai bot mentioned this pull request Jan 10, 2025
18 tasks
@coderabbitai coderabbitai bot mentioned this pull request Feb 26, 2025
18 tasks
@coderabbitai coderabbitai bot mentioned this pull request Mar 13, 2025
18 tasks
@coderabbitai coderabbitai bot mentioned this pull request Mar 17, 2025
18 tasks
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