Skip to content

feat: add new load more component#3033

Merged
chronark merged 9 commits intomainfrom
feat-table-new-load-more
Apr 8, 2025
Merged

feat: add new load more component#3033
chronark merged 9 commits intomainfrom
feat-table-new-load-more

Conversation

@ogzhanolguncu
Copy link
Contributor

@ogzhanolguncu ogzhanolguncu commented Mar 27, 2025

What does this PR do?

This PR adds a "load more" component to our Table component. To be able to show the total count, ClickHouse queries were updated accordingly.

  • Ratelimit logs ClickHouse query updated
  • Ratelimit overview logs ClickHouse query updated
  • Logs ClickHouse query updated

The new component is currently disabled for the /apis/[apiId] table.

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

Summary by CodeRabbit

  • New Features

    • Introduced an interactive footer for data tables that displays current and total counts, and allows users to load additional content dynamically.
    • Added functionality to track and display the total number of logs in various components.
  • Bug Fixes

    • Improved loading state management for better user experience when fetching additional data.
  • Refactor

    • Enhanced table layout with improved spacing for a cleaner, more responsive design.
    • Streamlined configuration by removing unnecessary settings to optimize the overall user experience.

@vercel
Copy link

vercel bot commented Mar 27, 2025

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

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 1 resolved Apr 8, 2025 3:32pm
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2025 3:32pm
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2025 3:32pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2025 3:32pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 27, 2025

📝 Walkthrough

Walkthrough

This pull request replaces the previous LoadingIndicator component with a new, interactive LoadMoreFooter component in the virtual table. The new component introduces props to manage loading behavior and display item counts, incorporating internal state tracking. Additionally, the configuration for the table has been simplified by removing the tableBorder property from both constants and types, and the useTableHeight hook has been updated to use a fixed "breathing space" constant. Minor comment adjustments were also applied in the Tailwind configuration.

Changes

File(s) Change Summary
apps/dashboard/components/virtual-table/components/loading-indicator.tsx
apps/dashboard/components/virtual-table/index.tsx
Replaced the LoadingIndicator with the new LoadMoreFooter component; updated import statements and rendering logic to provide props for loading actions and visual feedback.
apps/dashboard/components/virtual-table/constants.ts
apps/dashboard/components/virtual-table/types.ts
Removed the tableBorder property from the table configuration (DEFAULT_CONFIG and TableConfig), simplifying the visual border settings.
apps/dashboard/components/virtual-table/hooks/useTableHeight.ts Simplified the hook by removing headerHeight and tableBorder parameters; introduced a constant BREATHING_SPACE to adjust available height calculation.
internal/ui/tailwind.config.js Modified comments in the generateRadixColors function—removed the comment for "grayA" and reformatted the comment for "accent" without altering functionality.
apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/logs-table.tsx
apps/dashboard/app/(app)/logs/components/table/logs-table.tsx
apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/logs-table.tsx
apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/table/logs-table.tsx
Added loadMoreFooterProps to the VirtualTable component, enhancing pagination and display functionalities for logs, including properties like buttonText, hasMore, and countInfoText.
apps/dashboard/app/(app)/logs/components/table/hooks/use-logs-query.ts
apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/table/hooks/use-logs-query.ts
Introduced a new state variable totalCount to track the total number of logs, updated return values to include totalCount.
apps/dashboard/lib/trpc/routers/logs/query-logs/index.ts
apps/dashboard/lib/trpc/routers/ratelimit/query-logs/index.ts
apps/dashboard/lib/trpc/routers/ratelimit/query-overview-logs/index.ts
Added a total property to response schemas, modified fetching logic to include both logs and total counts using concurrent queries.
internal/clickhouse/src/logs.ts
internal/clickhouse/src/ratelimits.ts
Restructured SQL query logic to eliminate CTEs, returning both logs and total counts from separate queries.

Suggested reviewers

  • mcstepp
  • chronark

Possibly related PRs


📜 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 6e07914 and 7f9adf9.

📒 Files selected for processing (3)
  • apps/dashboard/lib/trpc/routers/logs/query-logs/index.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/ratelimit/query-logs/index.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/ratelimit/query-overview-logs/index.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Test Go API Local / Test (Shard 4/8)
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Test Go API Local / Test (Shard 1/8)
  • GitHub Check: Test Packages / Test ./packages/api
  • GitHub Check: Test Packages / Test ./internal/hash
  • GitHub Check: Test Packages / Test ./internal/billing
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Build / Build
🔇 Additional comments (12)
apps/dashboard/lib/trpc/routers/logs/query-logs/index.ts (4)

10-20: Good addition of the total property to the schema

Adding the total count to the response schema is beneficial for the new load more component mentioned in the PR objectives. This will allow the UI to accurately display progress and remaining items.


52-58: Well-structured query improvement

The restructured query logic now properly handles both the logs and total count queries. This aligns with the PR objectives of updating ClickHouse queries to show total counts.


60-67: Good use of Promise.all for concurrent execution

Using Promise.all to execute both queries concurrently is a performance optimization that prevents sequential waiting. The error handling has been properly updated to check for errors in both query results.


72-83: Correctly implemented response with total count

The response now includes the total count from the ClickHouse query, which is essential for the load more component functionality described in the PR objectives.

apps/dashboard/lib/trpc/routers/ratelimit/query-logs/index.ts (4)

10-20: Good addition of the total property to the schema

Adding the total count to the RatelimitLogsResponse schema is consistent with the changes in the logs router and supports the new load more component mentioned in the PR.


61-68: Well-structured query improvement

The restructured query logic correctly separates the count and logs queries. This change is consistent with the other routers and aligns with the PR objectives.


70-77: Good use of Promise.all for concurrent execution

Using Promise.all for concurrent execution improves performance and the error handling has been properly updated to check both query results.


79-91: Correctly implemented response with total count

The response now includes the total count from ClickHouse, which will be used by the new load more component. The implementation is consistent with the other routers.

apps/dashboard/lib/trpc/routers/ratelimit/query-overview-logs/index.ts (4)

10-20: Good addition of the total property to the schema

Adding the total count to the RatelimitOverviewLogsResponse schema maintains consistency across all log-related routers and supports the new load more feature.


61-68: Well-structured query improvement

The restructured query logic correctly handles both the count and logs queries, following the same pattern as the other routers.


70-77: Good use of Promise.all for concurrent execution

The concurrent execution of queries using Promise.all improves performance, and the error handling correctly checks both query results.


81-92: Correctly implemented response with total count

The response now includes the total count and maintains the same structure as the other log-related responses, ensuring consistency throughout the API.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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 27, 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 (4)
internal/ui/tailwind.config.js (1)

78-78: Clarify the "accent" → "brand" association.
Noting that "accent" is also labeled as "brand" in Figma ensures alignment between design and development. Please double-check for references that may still use “brand” terminology in code or documentation.

apps/dashboard/components/virtual-table/hooks/useTableHeight.ts (1)

2-3: Use a configurable spacing constant.
It’s helpful to have a top-level constant for “breathing space.” Consider making it a configurable parameter if different pages or layouts might require custom spacing.

apps/dashboard/components/virtual-table/index.tsx (1)

279-307: Remove the commented-out code block.
The new <LoadMoreFooter /> is fully integrated, so the old load-more UI snippet is no longer needed. Eliminating it cleans up the file and avoids confusion.

-          {/* <div className="sticky bottom-0 left-0 right-0 w-full items-center ... */}
-          {/*   ... */}
-          {/* </div> */}
+          // Removed old code as it's no longer used
apps/dashboard/components/virtual-table/components/loading-indicator.tsx (1)

1-124: Comprehensive “load more” footer implementation.
This component provides a clean UI/UX pattern with proximity detection and loading states. A couple of ideas:
• Make PROXIMITY_THRESHOLD configurable for different user interactions.
• Consider making onLoadMore a required prop if loading more is always intended.
Overall, this is a handy addition that aligns well with common usage patterns.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b3b68eb and 9fbe3f0.

📒 Files selected for processing (6)
  • apps/dashboard/components/virtual-table/components/loading-indicator.tsx (1 hunks)
  • apps/dashboard/components/virtual-table/constants.ts (0 hunks)
  • apps/dashboard/components/virtual-table/hooks/useTableHeight.ts (1 hunks)
  • apps/dashboard/components/virtual-table/index.tsx (3 hunks)
  • apps/dashboard/components/virtual-table/types.ts (0 hunks)
  • internal/ui/tailwind.config.js (2 hunks)
💤 Files with no reviewable changes (2)
  • apps/dashboard/components/virtual-table/constants.ts
  • apps/dashboard/components/virtual-table/types.ts
🧰 Additional context used
🧬 Code Definitions (1)
apps/dashboard/components/virtual-table/index.tsx (2)
apps/dashboard/components/virtual-table/hooks/useTableHeight.ts (1)
  • useTableHeight (4-27)
apps/dashboard/components/virtual-table/components/loading-indicator.tsx (1)
  • LoadMoreFooter (14-123)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Test Go API Local / Test (Shard 5/8)
  • GitHub Check: Test Go API Local / Test (Shard 7/8)
  • GitHub Check: Test Go API Local / Test (Shard 8/8)
  • GitHub Check: Test Go API Local / Test (Shard 6/8)
  • GitHub Check: Test Go API Local / Test (Shard 3/8)
  • GitHub Check: Test Go API Local / Test (Shard 4/8)
  • GitHub Check: Test Go API Local / Test (Shard 2/8)
  • GitHub Check: Test Go API Local / Test (Shard 1/8)
  • GitHub Check: Test Packages / Test ./packages/nextjs
  • 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: Analyze (javascript-typescript)
🔇 Additional comments (6)
internal/ui/tailwind.config.js (1)

68-68: No issues with alpha color usage.
The addition of "grayA" is consistent with how alpha colors are handled. Good job keeping the naming approach uniform.

apps/dashboard/components/virtual-table/hooks/useTableHeight.ts (3)

12-12: Recalculation logic appears sound.
Subtracting BREATHING_SPACE is a neat and direct approach to control the table height within the viewport.


25-25: Dependency array correctly updated.
Removing now-unneeded dependencies keeps the effect properly scoped to containerRef.


4-4:

Details

❓ Verification inconclusive

Simplified hook signature.
Removing extra parameters reduces complexity. Verify all references to headerHeight and tableBorder are eliminated to avoid potential runtime issues.


🏁 Script executed:

#!/bin/bash
# Searching for references to removed parameters in the entire repository
rg -A 3 "useTableHeight\("
rg -A 3 "headerHeight"
rg -A 3 "tableBorder"

Length of output: 847


Simplified hook signature verified – manual confirm required for remaining headerHeight references.

The refactoring of useTableHeight to accept only a containerRef appears correct based on the repository search. No call to this hook is passing extra parameters, and tableBorder has been fully removed. However, note that headerHeight still exists in the virtual table’s type definitions (in types.ts) and constants (in constants.ts). Please ensure that these static references to headerHeight are intentional and remain decoupled from the hook’s implementation to avoid any unintended runtime dependencies.

apps/dashboard/components/virtual-table/index.tsx (2)

5-5: Updated import aligns with the new loading component.
This import replacement is consistent with removing the previous LoadingIndicator. Confirm that any old references are removed.


58-58: Hook usage reflects parameter removal.
Using only containerRef is consistent with the simplified useTableHeight signature.

@changeset-bot
Copy link

changeset-bot bot commented Mar 28, 2025

⚠️ No Changeset found

Latest commit: f70d0f4

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 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/lib/trpc/routers/ratelimit/query-logs/index.ts (1)

69-74: Consider more specific error handling

The current error handling doesn't distinguish between failures in the count query versus the logs query. This might make debugging more difficult.

-if (countResult.err || logsResult.err) {
+if (countResult.err || logsResult.err) {
+  const errorSource = countResult.err ? 'count query' : 'logs query';
   throw new TRPCError({
     code: "INTERNAL_SERVER_ERROR",
-    message: "Something went wrong when fetching data from clickhouse.",
+    message: `Something went wrong when fetching data from clickhouse (${errorSource}).`,
   });
 }
apps/dashboard/components/virtual-table/components/loading-indicator.tsx (2)

16-32: Consider improving visibility logic and empty return

The component correctly initializes default values and has early return logic, but there are two minor issues:

  1. The shouldShow logic only checks if onLoadMore exists, but doesn't consider hasMore. Consider hiding the component when there's nothing more to load.
  2. Returning undefined when hide is true could cause issues in some contexts. Consider returning null instead.
-  const shouldShow = !!onLoadMore;
+  const shouldShow = !!onLoadMore && hasMore;

-  if (hide) {
-    return;
-  }
+  if (hide) {
+    return null;
+  }

33-64: Consider making the component more responsive

The component has a fixed width of 740px which might not work well on smaller screens. Consider using responsive width classes to ensure it works across different device sizes.

-      <div className="w-[740px] border bg-gray-1 dark:bg-black border-gray-6 h-[60px] flex items-center justify-center p-[18px] rounded-[10px] drop-shadow-lg shadow-sm mb-5">
+      <div className="w-full max-w-[740px] mx-auto border bg-gray-1 dark:bg-black border-gray-6 h-[60px] flex items-center justify-center p-[18px] rounded-[10px] drop-shadow-lg shadow-sm mb-5">
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9fbe3f0 and 407b1fa.

📒 Files selected for processing (15)
  • apps/dashboard/app/(app)/apis/[apiId]/_overview/components/table/logs-table.tsx (1 hunks)
  • apps/dashboard/app/(app)/logs/components/table/hooks/use-logs-query.ts (3 hunks)
  • apps/dashboard/app/(app)/logs/components/table/logs-table.tsx (2 hunks)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/hooks/use-logs-query.ts (3 hunks)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/logs-table.tsx (2 hunks)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/table/hooks/use-logs-query.ts (3 hunks)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/table/logs-table.tsx (2 hunks)
  • apps/dashboard/components/virtual-table/components/loading-indicator.tsx (1 hunks)
  • apps/dashboard/components/virtual-table/index.tsx (3 hunks)
  • apps/dashboard/components/virtual-table/types.ts (1 hunks)
  • apps/dashboard/lib/trpc/routers/logs/query-logs/index.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/ratelimit/query-logs/index.ts (2 hunks)
  • apps/dashboard/lib/trpc/routers/ratelimit/query-overview-logs/index.ts (2 hunks)
  • internal/clickhouse/src/logs.ts (2 hunks)
  • internal/clickhouse/src/ratelimits.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/components/virtual-table/index.tsx
🧰 Additional context used
🧬 Code Definitions (3)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/logs-table.tsx (1)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/hooks/use-logs-query.ts (1)
  • useRatelimitOverviewLogsQuery (14-128)
internal/clickhouse/src/ratelimits.ts (2)
internal/clickhouse/src/client/client.ts (1)
  • query (24-61)
internal/clickhouse/src/client/noop.ts (1)
  • query (6-22)
apps/dashboard/app/(app)/logs/components/table/logs-table.tsx (1)
apps/dashboard/app/(app)/logs/components/table/hooks/use-logs-query.ts (1)
  • useLogsQuery (18-241)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Test Go API Local / Test (Shard 3/8)
  • GitHub Check: Test Go API Local / Test (Shard 5/8)
  • GitHub Check: Test Packages / Test ./packages/rbac
  • GitHub Check: Test Go API Local / Test (Shard 6/8)
  • GitHub Check: Test Go API Local / Test (Shard 1/8)
  • GitHub Check: Test Go API Local / Test (Shard 4/8)
  • GitHub Check: Test Packages / Test ./packages/nextjs
  • GitHub Check: Test Packages / Test ./packages/hono
  • GitHub Check: Test Packages / Test ./internal/hash
  • GitHub Check: Test Packages / Test ./packages/api
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Packages / Test ./internal/encryption
  • GitHub Check: Test Packages / Test ./internal/billing
  • GitHub Check: Test Packages / Test ./internal/id
  • GitHub Check: Test Packages / Test ./internal/keys
  • GitHub Check: Test Packages / Test ./internal/resend
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Build / Build
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (41)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/hooks/use-logs-query.ts (3)

15-15: LGTM: Good addition of totalCount state

The addition of totalCount state is a good enhancement that will help provide better pagination information in the UI.


113-115: LGTM: Properly handling totalCount update

This implementation correctly updates the totalCount when data is available and safely handles the case where no pages exist.


124-124: LGTM: Exposing totalCount in the return value

Exposing the totalCount in the return object makes it available to components that use this hook, which aligns with the PR objective of improving the load more component functionality.

apps/dashboard/components/virtual-table/types.ts (1)

47-53: Well-structured properties for the new load more footer

The type definition for loadMoreFooterProps is well-structured and provides a clear API for the new load more component. The optional nature of all properties gives flexibility in how this feature can be used across different tables.

apps/dashboard/lib/trpc/routers/ratelimit/query-logs/index.ts (4)

13-13: LGTM: Adding total property to response schema

Adding the total property to the response schema is a good enhancement that will support the new load more functionality.


59-66: LGTM: Destructuring queries for better readability

Good refactoring to destructure the count and logs queries for clarity.


67-68: LGTM: Using Promise.all for concurrent execution

Using Promise.all to execute both queries concurrently is an excellent performance optimization.


76-88: LGTM: Adding total count to the response

Good implementation of adding the total count to the response object from the count query result.

apps/dashboard/app/(app)/logs/components/table/hooks/use-logs-query.ts (3)

25-25: New state variable for tracking total count.

This addition of the totalCount state enables proper pagination indicators in the UI.


217-220: LGTM: Effective update of totalCount from initial data.

The conditional check ensures that totalCount is only updated when initialData.pages has content, preventing potential errors.


239-239: Properly exposing totalCount through the hook return value.

This change completes the integration of the total count functionality, making it available to consuming components.

apps/dashboard/lib/trpc/routers/logs/query-logs/index.ts (5)

13-13: Schema updated to include total count information.

Adding the total field to the LogsResponse schema ensures type safety for the new count information.


50-55: Improved query structure with separate count and logs queries.

The destructuring approach clearly separates the distinct query responsibilities.


57-59: Performance optimization with concurrent queries.

Using Promise.all to execute both queries concurrently is an excellent performance improvement compared to sequential execution.


66-66: Variable assignment updated for clarity.

Updating the variable assignment to use logsResult.val improves code readability.


72-72: Total count properly included in the response.

This change ensures the total count information is returned to the client for use in pagination UI.

apps/dashboard/lib/trpc/routers/ratelimit/query-overview-logs/index.ts (5)

13-13: Schema updated consistently with logs router.

Adding the total field to the RatelimitOverviewLogsResponse schema maintains consistency with other similar schemas.


59-65: Improved query structure for ratelimit overview logs.

The destructuring approach clearly separates the count and logs queries, mirroring the pattern used in the logs router.


67-69: Performance optimization with concurrent queries.

Using Promise.all to execute both queries concurrently is a good performance practice. The error handling properly checks both query results.


76-76: Variable assignment updated for consistency.

Using logsResult.val maintains consistency with the variable naming changes in the logs router.


80-80: Total count properly included in the response.

Including the total count in the response enables pagination UI to show accurate information to users.

apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/table/logs-table.tsx (2)

29-32: Updated hook usage to include pagination information.

The destructuring now includes hasMore and totalCount, which are necessary for the new load more functionality.


218-230: Enhanced UI with informative load more footer.

The new loadMoreFooterProps configuration provides users with valuable context about:

  1. The number of items currently displayed
  2. The total number of items available
  3. A clear call-to-action for loading more items

The hide: isLoading property ensures the footer is only displayed when appropriate.

apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/table/hooks/use-logs-query.ts (3)

24-24: Good addition of totalCount state variable.

This state variable is necessary for tracking the total number of logs available, which will be used for displaying pagination information in the new LoadMoreFooter component.


197-199: Well implemented totalCount update.

The code correctly sets the total count from the first page of results, ensuring the pagination information is accurate as soon as data is available.


219-219: Good exposure of totalCount in return value.

Including totalCount in the return object allows consuming components to access this information for pagination display.

apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/table/logs-table.tsx (2)

69-74: Correctly destructured additional properties from useRatelimitLogsQuery hook.

The code now properly retrieves totalCount and hasMore from the updated hook to support the load more functionality.


221-233: Well-structured loadMoreFooterProps implementation.

The implementation provides a clear UI for pagination with:

  • A descriptive button label
  • Conditional display based on loading state
  • Informative count text showing progress through available results
  • Proper usage of hasMore for determining when to show the load more option

This creates a more interactive and informative experience for users browsing through logs.

internal/clickhouse/src/ratelimits.ts (5)

341-342: Good approach with comment documenting the separation of concerns.

The comment clearly explains that this is the main query for paginated results, which helps with code readability and maintenance.


405-421: Well-implemented count query for pagination support.

The added count query is properly structured to:

  1. Return only the total count without retrieving all data
  2. Use the same filtering conditions as the main query
  3. Return the count in a consistent, well-typed format

This implementation follows the principle of separation of concerns and avoids performance issues that could arise from counting large datasets.


423-426: Good restructuring of the return value.

The function now returns both query results in a clear and structured object, allowing consumers to access both the paginated data and the total count.


653-668: Consistent implementation for overview logs count.

The implementation follows the same pattern as the main logs query, ensuring consistency across the codebase. The count query specifically counts distinct identifiers, which is appropriate for this context.


670-673: Consistent return structure for overview logs.

The return structure mirrors that of the getRatelimitLogs function, maintaining a predictable API pattern throughout the codebase.

apps/dashboard/app/(app)/logs/components/table/logs-table.tsx (2)

119-123: Correctly destructured additional properties from useLogsQuery hook.

The code appropriately retrieves the hasMore and total properties from the updated hook to support the load more functionality in the logs table.


250-262: Consistent implementation of loadMoreFooterProps across tables.

This implementation maintains consistency with the ratelimits table, using the same pattern for:

  • Conditional display based on loading state
  • Clear button text
  • Informative count information
  • Proper tracking of pagination state

This ensures a unified user experience across different sections of the dashboard.

internal/clickhouse/src/logs.ts (4)

75-131: Improved query structure with consolidated filter conditions

The refactoring to consolidate filter conditions into a single string variable with clear section comments makes the query logic more maintainable and easier to follow. The SQL conditions are well-structured and properly parameterized to prevent SQL injection.


133-143: Well-implemented total count query to support pagination

Adding a total count query is essential for implementing the "load more" functionality. The implementation correctly reuses the filter conditions and has proper schema validation.


145-179: Simplified query structure using consolidated filter conditions

The logs query now uses the consolidated filter conditions, which makes the code more DRY and maintainable. The cursor pagination implementation is correctly applied after the other filters.


181-184: Enhanced return value with both logs and total count

The function now returns both the logs query and total count query results, which is necessary for the new load more component to function properly. This is a good architectural decision for supporting pagination.

apps/dashboard/components/virtual-table/components/loading-indicator.tsx (2)

3-14: Well-defined props interface for the new LoadMoreFooter component

The LoadMoreFooterProps type clearly defines all the necessary properties needed for a flexible load more component, including loading states, counts, and customization options.


53-61: Well implemented button with proper loading and disabled states

The Button component correctly handles loading states and disables interaction when either fetching is in progress or there's nothing more to load. This prevents users from triggering multiple requests and provides good UX feedback.

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)
internal/clickhouse/src/ratelimits.ts (1)

404-419: Consider adding a comment explaining the count query's purpose

This count query is important for the feature, but its purpose might not be immediately clear to future developers.

    const countQuery = ch.query({
+     // Get total count of matching logs for pagination UI
      query: `
SELECT
    count(*) as total_count
FROM ratelimits.raw_ratelimits_v1 r
WHERE workspace_id = {workspaceId: String}
    AND namespace_id = {namespaceId: String}
    AND time BETWEEN {startTime: UInt64} AND {endTime: UInt64}
    ${hasRequestIds ? "AND request_id IN {requestIds: Array(String)}" : ""}
    AND (${identifierConditions})
    AND (${statusCondition})`,
      params: extendedParamsSchema,
      schema: z.object({
        total_count: z.number().int(),
      }),
    });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 407b1fa and 6e07914.

📒 Files selected for processing (2)
  • internal/clickhouse/src/logs.ts (2 hunks)
  • internal/clickhouse/src/ratelimits.ts (3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
internal/clickhouse/src/ratelimits.ts (2)
internal/clickhouse/src/client/client.ts (1)
  • query (24-61)
internal/clickhouse/src/client/noop.ts (1)
  • query (6-22)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Test Go API Local / Test (Shard 8/8)
  • GitHub Check: Test Go API Local / Test (Shard 1/8)
  • GitHub Check: Test Go API Local / Test (Shard 5/8)
  • GitHub Check: Test Go API Local / Test (Shard 7/8)
  • GitHub Check: Test Packages / Test ./packages/rbac
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test Packages / Test ./internal/encryption
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Packages / Test ./internal/id
  • GitHub Check: Test Packages / Test ./internal/hash
  • 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 (6)
internal/clickhouse/src/ratelimits.ts (2)

341-402: Excellent enhancement to enable pagination with total count

The refactoring of this function allows for more sophisticated UI controls by returning both the paginated logs data and the total count. This supports the new load more functionality mentioned in the PR objectives.

Also applies to: 404-424


651-670: Well-implemented count query for overview logs

The addition of a count query that returns the total number of distinct identifiers is a good approach for providing accurate pagination information. This maintains consistency with the implementation pattern used in getRatelimitLogs.

internal/clickhouse/src/logs.ts (4)

75-130: Well-structured filter conditions with clear SQL organization

The new filterConditions string consolidates all filtering logic in one place, using proper parameterization for security and CASE statements for conditional filtering. The commented sections make it clear what each filter does, improving maintainability.


132-142: Added total count query to support load more functionality

Adding a count query is essential for implementing the "load more" component mentioned in the PR objectives. This allows the UI to show progress (e.g., "X of Y records").


144-179: Refactored main query to use consolidated filter conditions

The main query now properly uses the shared filter conditions, ensuring consistency between the count and data retrieval queries. The pagination logic with cursor is maintained correctly.


180-183:

Details

❓ Verification inconclusive

Updated return structure to include both queries

The function now returns both the logs data and total count queries, aligning with the PR objective of supporting a "load more" component for tables.

Make sure all code that calls getLogs() has been updated to handle the new return structure. The previous implementation returned a single query result, but now it returns an object with logsQuery and totalQuery.


🏁 Script executed:

#!/bin/bash
# Find all places where getLogs is imported and used
rg "getLogs|logs\.(logsQuery|totalQuery)" --type ts -A 5 -B 5

Length of output: 5175


Action Required: Verify Updated Return Structure for getLogs

The getLogs function in internal/clickhouse/src/logs.ts now returns an object with both logsQuery and totalQuery, which supports the "load more" component for tables. However, please ensure that all call sites (for example, in internal/clickhouse/src/index.ts) have been updated to correctly handle this new return structure. Specifically:

  • Confirm that code previously expecting a single value now extracts the logsQuery and totalQuery properties.
  • Verify that any downstream usage is updated to accommodate the split between query results.

@chronark chronark added this pull request to the merge queue Apr 8, 2025
Merged via the queue into main with commit ff5fd41 Apr 8, 2025
29 of 36 checks passed
@chronark chronark deleted the feat-table-new-load-more branch April 8, 2025 15:35
@coderabbitai coderabbitai bot mentioned this pull request Sep 12, 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.

3 participants