Skip to content

feat: allow clicking on keyid on overview#2990

Closed
ogzhanolguncu wants to merge 1 commit intomainfrom
feat-allow-clicking-on-key-id
Closed

feat: allow clicking on keyid on overview#2990
ogzhanolguncu wants to merge 1 commit intomainfrom
feat-allow-clicking-on-key-id

Conversation

@ogzhanolguncu
Copy link
Contributor

@ogzhanolguncu ogzhanolguncu commented Mar 19, 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?

  • 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

  • New Features

    • Log details now include clickable links, allowing users to quickly navigate to detailed key views.
    • Additional key information is displayed in the identifiers section, enhancing clarity in log data.
  • Refactor

    • Adjusted the visual aggregation for extended time ranges, providing a clearer overview by grouping data into 6-hour intervals.

@changeset-bot
Copy link

changeset-bot bot commented Mar 19, 2025

⚠️ No Changeset found

Latest commit: 70ed593

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 Mar 19, 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 Mar 19, 2025 10:31am
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2025 10:31am
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2025 10:31am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2025 10:31am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

📝 Walkthrough

Walkthrough

The changes update multiple dashboard API log components to accept and utilize two new optional properties, apiId and keyAuthId. This update modifies component interfaces, prop passing, and rendering logic to conditionally render navigable links where applicable. Additionally, the time series granularity logic in a utility function has been adjusted to change the default granularity value for extended time ranges.

Changes

File(s) Change Summary
apps/dashboard/app/(app)/apis/[apiId]/_overview/.../log-section.tsx
apps/dashboard/app/(app)/apis/[apiId]/_overview/.../log-details/index.tsx
apps/dashboard/app/(app)/apis/[apiId]/_overview/.../override-indicator.tsx
apps/dashboard/app/(app)/apis/[apiId]/_overview/.../logs-table.tsx
apps/dashboard/app/(app)/apis/[apiId]/_overview/logs-client.tsx
Updated several components by adding new optional props apiId and keyAuthId. Modified the rendering logic to conditionally render a <Link> when a key is "ID", and updated type definitions and component signatures accordingly.
apps/dashboard/lib/trpc/routers/utils/granularity.ts Modified the getTimeseriesGranularity function to use "per6Hours" instead of "perHour" for time ranges ≥ 2 weeks.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant LS as LogSection / KeyIdentifierColumn
    participant L as Link Component
    participant DV as Detailed View

    U->>LS: Interact with log entry
    alt Key equals "ID"
        LS->>L: Render clickable Link with apiId & keyAuthId
        L->>DV: Navigate to detailed view using provided identifiers
        DV-->>U: Display detailed key information
    else
        LS-->>U: Display plain text value
    end
Loading

Possibly related PRs

Suggested labels

Feature

Suggested reviewers

  • mcstepp
  • perkinsjr
  • chronark
  • MichaelUnkey

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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 Mar 19, 2025

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

@vercel vercel bot temporarily deployed to Preview – www March 19, 2025 10:27 Inactive
@vercel vercel bot temporarily deployed to Preview – engineering March 19, 2025 10:27 Inactive
@vercel vercel bot temporarily deployed to Preview – play March 19, 2025 10:28 Inactive
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)/apis/[apiId]/_overview/components/table/components/log-details/index.tsx (1)

32-36: ⚠️ Potential issue

Missing apiId in component destructuring.

The component function parameters don't include the apiId prop that was added to the type definition, which creates a mismatch between the defined props and what the component actually receives.

export const KeysOverviewLogDetails = ({
  distanceToTop,
  log,
  setSelectedLog,
+  apiId,
}: KeysOverviewLogDetailsProps) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f4e5f6d and 70ed593.

📒 Files selected for processing (6)
  • apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/components/log-details/components/log-section.tsx (3 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/components/log-details/index.tsx (2 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/components/override-indicator.tsx (4 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/logs-table.tsx (1 hunks)
  • apps/dashboard/app/(app)/apis/[apiId]/_overview/logs-client.tsx (1 hunks)
  • apps/dashboard/lib/trpc/routers/utils/granularity.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/logs-table.tsx (1)
apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/components/override-indicator.tsx (1) (1)
  • KeyIdentifierColumn (64-90)
apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/components/log-details/index.tsx (1)
apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/components/log-details/components/log-section.tsx (1) (1)
  • LogSection (29-113)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Test Go API Local / Test
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Build / Build
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (11)
apps/dashboard/app/(app)/apis/[apiId]/_overview/logs-client.tsx (1)

29-34: LGTM! Passing apiId to child component.

The change correctly passes the apiId prop down to the KeysOverviewLogDetails component, which is necessary for enabling key ID links in the log details view.

apps/dashboard/lib/trpc/routers/utils/granularity.ts (1)

92-92: Improved time series granularity for extended time ranges.

Changing from "perHour" to "per6Hours" for time ranges over 2 weeks is a good optimization that will reduce data points while maintaining meaningful visualization for longer periods.

apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/logs-table.tsx (1)

39-39: LGTM! Passing apiId to KeyIdentifierColumn.

This change correctly provides the apiId to the KeyIdentifierColumn component, which is necessary for building the proper navigation link when clicking on key IDs.

apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/components/log-details/components/log-section.tsx (3)

9-9: LGTM! Adding Link import.

Correctly adds the Next.js Link component import which is needed for the clickable key ID functionality.


29-39: LGTM! Updated component props.

The component signature is properly updated to include the optional keyAuthId and apiId parameters, which are necessary for building navigation links.


81-93: LGTM! Implemented clickable key ID links.

The implementation correctly creates a clickable link when the field key is "ID", directing users to the detailed key view using the provided apiId and keyAuthId. The styling is consistent with the application's design patterns.

apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/components/log-details/index.tsx (1)

28-28: Props type correctly updated to include apiId.

The KeysOverviewLogDetailsProps type has been properly updated to include the apiId string property, which will be used for navigation purposes.

apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/components/override-indicator.tsx (4)

6-6: Required import added for Link component.

The import for the Link component from Next.js is correctly added to implement navigable key IDs.


33-33: Props type correctly updated to include apiId.

The KeyIdentifierColumnProps type is properly updated to include the apiId string property.


64-64: Component signature updated correctly.

The component function signature now correctly includes the apiId parameter, matching the updated type definition.


78-87:

Details

❓ Verification inconclusive

Improved user experience with navigable key IDs.

Replacing the static <div> with a <Link> component improves user experience by making key IDs clickable. However, there's potential for a broken link if log.key_details?.key_auth_id is undefined.

Consider adding a check to ensure both required parameters exist before attempting navigation:

<Link
  title="Link to the key details"
  className="font-mono group-hover:underline decoration-dotted"
-  href={`/apis/${apiId}/keys/${log.key_details?.key_auth_id}/${log.key_id}`}
+  href={log.key_details?.key_auth_id 
+    ? `/apis/${apiId}/keys/${log.key_details.key_auth_id}/${log.key_id}` 
+    : '#'}
+  onClick={(e) => !log.key_details?.key_auth_id && e.preventDefault()}
>

Let's check if there are cases where key_auth_id might be undefined:


🏁 Script executed:

#!/bin/bash
# Check if there are any logs without key_auth_id
rg -A 3 "key_details\s*[=:]\s*\{" --type=typescript | grep -i "key_auth_id" -B 3

Length of output: 115


Below is a revised review comment. I've updated the suggestion diff and noted that our initial verification using the "typescript" file type wasn’t conclusive. In this case, I recommend re-running a grep command (for example, with the correct "tsx" file type) or manually verifying that every log provides a defined key_auth_id before clicking the link.

Improved navigation for key IDs – verify presence of key_auth_id

Replacing the static <div> with a <Link> component improves the user experience by making key IDs clickable. However, if log.key_details?.key_auth_id is undefined, the generated URL will be broken. Please verify that every log has a valid key authentication ID. For instance, you can re-run a command such as:

If any missing values are found, you should update the link construction accordingly. A possible improvement would be:

<Link
  title="Link to the key details"
  className="font-mono group-hover:underline decoration-dotted"
-  href={`/apis/${apiId}/keys/${log.key_details?.key_auth_id}/${log.key_id}`}
+  href={log.key_details?.key_auth_id 
+    ? `/apis/${apiId}/keys/${log.key_details.key_auth_id}/${log.key_id}` 
+    : '#'}
+  onClick={(e) => !log.key_details?.key_auth_id && e.preventDefault()}
>

Please manually verify whether there are any cases where key_auth_id might be undefined to avoid broken links in production.


🏁 Script executed:

#!/bin/bash
# Re-run the search using file type "tsx" because the file under review is a TSX file.
rg -A 3 "key_details\s*[=:]\s*\{" --type=tsx | grep -i "key_auth_id" -B 3

Length of output: 223


Action Required: Verify Handling of Undefined key_auth_id

Replacing the static <div> with a <Link> component indeed improves the user experience by making key IDs clickable. However, if log.key_details?.key_auth_id is undefined, the generated URL will be broken. While our suggested diff provides a safeguard by defaulting to a '#' link and preventing navigation, our automated search for cases where key_auth_id might be missing did not yield conclusive results—likely due to the file type issue with ripgrep.

Please verify manually (or re-run using, for example, a file-pattern-based search like rg -g '*.tsx') that every log includes a valid key_auth_id.

<Link
  title="Link to the key details"
  className="font-mono group-hover:underline decoration-dotted"
-  href={`/apis/${apiId}/keys/${log.key_details?.key_auth_id}/${log.key_id}`}
+  href={log.key_details?.key_auth_id 
+    ? `/apis/${apiId}/keys/${log.key_details.key_auth_id}/${log.key_id}` 
+    : '#'}
+  onClick={(e) => !log.key_details?.key_auth_id && e.preventDefault()}
>

Comment on lines +100 to +105
<LogSection
title="Identifiers"
details={identifiers}
keyAuthId={log.key_details.key_auth_id}
apiId={log.key_id}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enhanced LogSection with navigational capabilities.

The LogSection is now correctly enhanced with keyAuthId and apiId props, enabling navigation to key details. However, I noticed that apiId is being set to log.key_id, which seems incorrect as apiId typically refers to the API identifier, not a key ID.

The value passed to apiId should probably be the actual API ID from the props. Please verify this value:

<LogSection
  title="Identifiers"
  details={identifiers}
  keyAuthId={log.key_details.key_auth_id}
-  apiId={log.key_id}
+  apiId={apiId}
/>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<LogSection
title="Identifiers"
details={identifiers}
keyAuthId={log.key_details.key_auth_id}
apiId={log.key_id}
/>
<LogSection
title="Identifiers"
details={identifiers}
keyAuthId={log.key_details.key_auth_id}
apiId={apiId}
/>

@vercel vercel bot temporarily deployed to Preview – dashboard March 19, 2025 10:31 Inactive
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.

1 participant