Skip to content

feat: integrate pagination into EnhancedDataTable toolbar #326

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

Merged
merged 7 commits into from
May 12, 2025

Conversation

tianlilei-c
Copy link
Collaborator

@tianlilei-c tianlilei-c commented May 6, 2025

🏷️ Ticket

Closes #295

📝 Description

This PR introduces front-end pagination support to the EnhancedDataTable component via TanStack Table's pagination model and integrates it into the LinkedAccountsPage. It also includes a jump-to-page input UX, improves pagination accessibility via ShadCN components, and conditionally renders the pagination toolbar when options are provided.
Additionally, the data-table-pagination component is now encapsulated to handle multiple pagination scenarios through the getPageItems function. The bottom pagination section now adopts a page number button layout, with dynamic rendering based on the current page index and total pages. Special attention is required for the handling of edge cases in getPageItems to ensure consistent pagination behavior, particularly when the total page count is less than or equal to 7 or when the current page is at the boundary.

🎥 Demo (if applicable)

N/A

📸 Screenshots (if applicable)

image
image

✅ Checklist

  • I have signed the Contributor License Agreement (CLA) and read the contributing guide
  • I have linked this PR to an issue or a ticket
  • I have updated the documentation related to my change
  • I have updated the tests accordingly (if applicable)
  • All checks on CI passed

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive pagination controls for data tables, including navigation buttons, direct page input, and improved accessibility.
    • Added a new suite of pagination UI components for consistent styling and usability across the application.
  • Enhancements

    • Data tables now support configurable pagination options, allowing users to control page size and navigate through large datasets more efficiently.
  • Documentation

    • Updated EnhancedDataTable documentation to include usage instructions for the new pagination feature.
  • Chores

    • Updated a UI library dependency for improved stability and features.

@tianlilei-c tianlilei-c requested a review from dev-aipolabs May 6, 2025 11:36
Copy link

vercel bot commented May 6, 2025

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

Name Status Preview Comments Updated (UTC)
aci-dev-portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2025 9:05pm

Copy link
Contributor

coderabbitai bot commented May 6, 2025

Walkthrough

Pagination functionality was integrated into the EnhancedDataTable component, including a new pagination UI suite and supporting logic. The LinkedAccountsPage now uses these pagination features. Documentation was updated to describe the new pagination options. A dependency update for @radix-ui/react-slot was also made.

Changes

File(s) Change Summary
frontend/src/components/ui/pagination.tsx Introduced a new suite of pagination UI components (Pagination, PaginationContent, PaginationItem, PaginationLink, etc).
frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx Added DataTablePagination generic component for table pagination UI and logic.
frontend/src/components/ui-extensions/enhanced-data-table/data-table.tsx Added pagination logic and state to EnhancedDataTable, supporting new paginationOptions prop and rendering pagination UI.
frontend/src/app/linked-accounts/page.tsx Updated to pass paginationOptions to EnhancedDataTable for initial page and page size.
frontend/src/components/ui-extensions/enhanced-data-table/README.md Updated documentation to include usage and configuration of pagination.
frontend/package.json Updated @radix-ui/react-slot dependency version.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LinkedAccountsPage
    participant EnhancedDataTable
    participant DataTablePagination

    User->>LinkedAccountsPage: Loads page
    LinkedAccountsPage->>EnhancedDataTable: Renders with paginationOptions
    EnhancedDataTable->>DataTablePagination: Renders pagination controls
    User->>DataTablePagination: Interacts (next/prev/page input)
    DataTablePagination->>EnhancedDataTable: Updates pagination state
    EnhancedDataTable->>EnhancedDataTable: Updates displayed rows
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement pagination for the apps page on the dev portal (#295)

Possibly related PRs

Suggested reviewers

  • jiwei-aipolabs

Poem

A hop, a skip, a page or two,
Now tables scroll as rabbits do!
With buttons, links, and numbers bright,
Your data’s paged just right.
So leap through rows, don’t hesitate—
This bunny’s work will paginate!
🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 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 b88a01c and 45a0164.

📒 Files selected for processing (1)
  • frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Compose Tests
  • GitHub Check: Format & Lint
  • GitHub Check: Format, Lint, and Test
✨ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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 (5)
frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx (3)

3-9: Remove commented out imports that are not used.

The code contains commented-out import statements for Select components that aren't used in the implementation. Remove these commented imports to keep the codebase clean.

-// import {
-//   Select,
-//   SelectContent,
-//   SelectItem,
-//   SelectTrigger,
-//   SelectValue,
-// } from "@/components/ui/select";

101-118: Consider handling potential invalid input values for pagination input.

The current implementation doesn't handle non-numeric or empty input values, which could lead to unexpected behavior if users manually clear the input field.

 <Input
   type="number"
   min={1}
   max={pageCount}
   value={pageInput}
-  onChange={(e) => setPageInput(Number(e.target.value))}
+  onChange={(e) => {
+    const value = e.target.value;
+    // Handle empty input or non-numeric values
+    const numValue = value === '' ? 1 : Number(value);
+    setPageInput(numValue);
+  }}
   onKeyDown={(e) => e.key === "Enter" && jumpToPage()}
   className="w-14 text-center"
 />

76-149: Consider adding pagination size configuration for different view contexts.

The pagination component currently has fixed styling, but for better reusability, consider adding size variants (compact, default, large) to accommodate different UI contexts.

You could extend the component interface to support different sizes:

interface DataTablePaginationProps<TData> {
  table: Table<TData>;
+ size?: 'compact' | 'default' | 'large';
}

// Then apply conditional classes based on size
frontend/src/components/ui/pagination.tsx (2)

29-35: Consider adding more default styling to PaginationItem.

The PaginationItem component has an empty string as the default className. Consider adding some minimal default styling to ensure consistent appearance.

-  <li ref={ref} className={cn("", className)} {...props} />
+  <li ref={ref} className={cn("list-none", className)} {...props} />

109-117: Consider adding a reference to documentation in export comment block.

For better developer experience, consider adding a reference to usage documentation or examples above the export block.

+/**
+ * Pagination components for creating accessible pagination interfaces.
+ * 
+ * @example
+ * ```tsx
+ * <Pagination>
+ *   <PaginationContent>
+ *     <PaginationItem>
+ *       <PaginationPrevious href="#" />
+ *     </PaginationItem>
+ *     {/* ... */}
+ *   </PaginationContent>
+ * </Pagination>
+ * ```
+ */
export {
  Pagination,
  PaginationContent,
  PaginationLink,
  PaginationItem,
  PaginationPrevious,
  PaginationNext,
  PaginationEllipsis,
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8441bdb and 8bd7d74.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • frontend/package.json (1 hunks)
  • frontend/src/app/linked-accounts/page.tsx (1 hunks)
  • frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx (1 hunks)
  • frontend/src/components/ui-extensions/enhanced-data-table/data-table-toolbar.tsx (2 hunks)
  • frontend/src/components/ui-extensions/enhanced-data-table/data-table.tsx (7 hunks)
  • frontend/src/components/ui/pagination.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx (1)
frontend/src/components/ui/pagination.tsx (6)
  • PaginationLink (112-112)
  • Pagination (110-110)
  • PaginationContent (111-111)
  • PaginationItem (113-113)
  • PaginationPrevious (114-114)
  • PaginationNext (115-115)
frontend/src/components/ui-extensions/enhanced-data-table/data-table-toolbar.tsx (1)
frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx (1)
  • DataTablePagination (57-150)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Format & Lint
  • GitHub Check: Compose Tests
  • GitHub Check: Format, Lint, and Test
🔇 Additional comments (24)
frontend/package.json (1)

30-30: Appropriate dependency version update.

Updating @radix-ui/react-slot from ^1.1.2 to ^1.2.2 appropriately supports the new pagination components that leverage the Slot primitive for component composition.

frontend/src/app/linked-accounts/page.tsx (1)

399-402: Well-implemented pagination configuration.

The pagination settings with an initial page size of 10 items is a good default for this data table. This provides a nice balance between showing enough data without overwhelming the user interface.

frontend/src/components/ui-extensions/enhanced-data-table/data-table.tsx (7)

14-15: Good addition of necessary TanStack Table imports.

These imports correctly bring in the pagination model and state type from TanStack Table, which are required for implementing the pagination functionality.


49-52: Well-defined pagination options interface.

The PaginationOptions interface is clear and properly typed with optional properties, making it flexible for different usage scenarios.


60-60: Proper interface extension.

Adding the optional paginationOptions property to the EnhancedDataTableProps interface makes pagination opt-in, which is a good design choice.


89-92: Clean pagination state initialization.

The pagination state is properly initialized with sensible defaults, falling back to page index 0 and page size 10 when not explicitly provided.


112-112: Correct state management for pagination.

The pagination state is correctly included in the table state object, and the dependency array for the useMemo hook is properly updated to include pagination.

Also applies to: 121-121


129-135: Effective conditional pagination setup.

The pagination row model is conditionally applied only when pagination options are provided, and the pagination change handler is correctly wired up. This is an elegant approach that avoids unnecessary processing when pagination isn't needed.


189-189: Proper prop passing to toolbar.

The paginationOptions prop is correctly passed down to the EnhancedDataTableToolbar component, enabling the conditional rendering of pagination controls.

frontend/src/components/ui-extensions/enhanced-data-table/data-table-toolbar.tsx (4)

8-8: Appropriate component import.

Importing the DataTablePagination component correctly brings in the specialized pagination UI for the data table.


10-13: Consistent interface definition.

The PaginationOptions interface matches the one in the data table component, maintaining consistency across the component hierarchy.


20-20: Clean interface extension.

The toolbar props interface is properly extended to include the optional pagination options.


70-70: Effective conditional rendering.

The pagination component is only rendered when pagination options are provided, which is an efficient approach that avoids rendering unnecessary UI elements.

Looking at the DataTablePagination implementation from the relevant code snippets, the pagination controls include first/previous/next/last buttons and a jump-to-page input with validation, providing a complete pagination experience.

frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx (5)

23-36: LGTM: Well-implemented PaginationFirst component with proper accessibility.

The PaginationFirst component is well-structured, properly extends PaginationLink, and includes appropriate aria-label and screen reader text for accessibility.


38-51: LGTM: Well-implemented PaginationLast component with proper accessibility.

The PaginationLast component follows the same good pattern as PaginationFirst, with appropriate accessibility attributes.


60-68: LGTM: Proper state management and synchronization.

The component correctly manages its internal state and synchronizes with the table's current page index using useEffect.


70-73: LGTM: Well-implemented page jumping function.

The jumpToPage function correctly handles boundary conditions, ensuring the page index is always within valid range.


134-136: 🛠️ Refactor suggestion

Fix incorrect disable condition for PaginationLast button.

The PaginationLast button uses the same condition as PaginationNext, but it should check if we're already at the last page specifically.

className={
-  !table.getCanNextPage()
+  !(table.getState().pagination.pageIndex < pageCount - 1)
    ? "pointer-events-none opacity-50"
    : ""
}

Likely an incorrect or invalid review comment.

frontend/src/components/ui/pagination.tsx (6)

7-14: LGTM: Well-structured Pagination component with proper accessibility attributes.

The Pagination component correctly uses the navigation role and includes an aria-label for accessibility.


17-26: LGTM: Well-implemented PaginationContent component.

The PaginationContent component correctly uses forwardRef and has appropriate styling.


37-60: LGTM: Well-designed PaginationLink component with proper aria attributes.

The PaginationLink component is well-implemented with proper aria-current attribute for accessibility and a clean approach to styling active state.


62-76: LGTM: Well-implemented PaginationPrevious component with good accessibility.

The PaginationPrevious component includes both icon and text label, with proper aria-label for accessibility.


78-92: LGTM: Well-implemented PaginationNext component with good accessibility.

The PaginationNext component is consistent with PaginationPrevious and has proper accessibility attributes.


94-107: LGTM: Well-implemented PaginationEllipsis with screen reader support.

The PaginationEllipsis component correctly uses aria-hidden for the visual ellipsis while providing descriptive text for screen readers.

@tianlilei-c
Copy link
Collaborator Author

Hi @dev-aipolabs I have merged the latest main and resolved the conflicts. I've also optimized the input jump button logic. It's ready for review.
image

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)
frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx (4)

19-19: Comment style needs correction

The comment has double slashes which appears to be unintentional. This looks like a leftover from a commented-out code section rather than an intended comment.

-// // `current0` indicates a 0-based page index (internal state), converted to `currentPage` (1-based) for user-facing pagination.
+// `current0` indicates a 0-based page index (internal state), converted to `currentPage` (1-based) for user-facing pagination.

60-63: Consider enhancing input validation feedback

The current input validation silently resets invalid input. Consider providing visual feedback to improve user experience.

if (isNaN(pageInput) || pageInput === null) {
  setPageInput(pageIndex + 1);
+ // Consider adding toast or inline feedback here
  return;
}

74-76: Handle zero page count edge case

When there are no pages, the component would show "1 – 0 / 0" which looks odd. Consider adding a conditional display for this case.

<div className="text-sm font-medium">
-  {startRow} – {endRow} / {table.getRowCount()}
+  {table.getRowCount() > 0 
+    ? `${startRow} – ${endRow} / ${table.getRowCount()}`
+    : "No items"
+  }
</div>

145-147: Remove redundant comment and consider extracting CSS utility class

The CSS for hiding spinner buttons is duplicated in both the comment and className. Consider creating a utility class for this styling pattern.

-                // Hide the arrow of the input box  [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none
-                className="h-7 w-14 text-center [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
+                // Hide the spinner buttons for number input
+                className="h-7 w-14 text-center number-input-no-spinner"

Then add a utility class in your CSS:

.number-input-no-spinner {
  appearance: textfield;
}
.number-input-no-spinner::-webkit-outer-spin-button,
.number-input-no-spinner::-webkit-inner-spin-button {
  appearance: none;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f704849 and b88a01c.

📒 Files selected for processing (2)
  • frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx (1 hunks)
  • frontend/src/components/ui-extensions/enhanced-data-table/data-table.tsx (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/ui-extensions/enhanced-data-table/data-table.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Format & Lint
  • GitHub Check: Format, Lint, and Test
  • GitHub Check: Compose Tests
🔇 Additional comments (4)
frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx (4)

20-42: LGTM! Well-structured pagination algorithm

The pagination algorithm is well-designed to handle different scenarios (small page count, beginning, middle, and end pages). The ellipsis display logic makes the UI clean and usable.


44-67: Well-implemented component with proper page handling

The component correctly handles pagination state and page jumping with appropriate validation and boundary checks.


135-160: Nice implementation of jump-to-page functionality

The jump-to-page implementation with input validation, keyboard support (Enter key), and Go button with appropriate disabled state enhances user experience. Accessibility is well-addressed with appropriate aria-labels.


1-166: Overall excellent pagination implementation

This component is well-structured with appropriate accessibility considerations, edge case handling, and a clean UI design. The pagination algorithm intelligently displays a reasonable number of page links with ellipses at strategic positions, and the jump-to-page functionality enhances user experience.

…tion and empty state handling

- Added useMemo for page item calculation to optimize performance.
- Implemented a message for empty tables to improve user experience.
- Updated comments for clarity on pagination logic.
Copy link
Contributor

@dev-aipolabs dev-aipolabs left a comment

Choose a reason for hiding this comment

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

lgtm

@dev-aipolabs dev-aipolabs merged commit c7c6d4e into main May 12, 2025
6 checks passed
@dev-aipolabs dev-aipolabs deleted the feat/apps-table-pagination branch May 12, 2025 21:07
@coderabbitai coderabbitai bot mentioned this pull request Jun 15, 2025
5 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.

Implement pagination for the apps page on the dev portal
2 participants