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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

πŸŽ₯ Demo (if applicable)

N/A

πŸ“Έ Screenshots (if applicable)

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

  • 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.
  • 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 6, 2025 11:36am

Copy link
Contributor

coderabbitai bot commented May 6, 2025

Walkthrough

Pagination functionality has been introduced to the frontend data table components. New pagination UI components were added, and the EnhancedDataTable and related toolbars now support pagination options and state. The linked accounts page uses these new features, and a dependency update for @radix-ui/react-slot was made.

Changes

Files/Groups Change Summary
frontend/package.json Updated @radix-ui/react-slot dependency from ^1.1.2 to ^1.2.2.
frontend/src/app/linked-accounts/page.tsx Passed paginationOptions prop to EnhancedDataTable to set initial pagination state.
frontend/src/components/ui-extensions/enhanced-data-table/data-table-pagination.tsx Added DataTablePagination, PaginationFirst, and PaginationLast components for pagination UI.
frontend/src/components/ui-extensions/enhanced-data-table/data-table-toolbar.tsx Added paginationOptions prop and conditional rendering of pagination controls in toolbar.
frontend/src/components/ui-extensions/enhanced-data-table/data-table.tsx Added pagination support: state management, prop, and integration with table and toolbar.
frontend/src/components/ui/pagination.tsx Introduced suite of reusable pagination UI components (container, links, ellipsis, etc.).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LinkedAccountsPage
    participant EnhancedDataTable
    participant EnhancedDataTableToolbar
    participant DataTablePagination

    User->>LinkedAccountsPage: Loads page
    LinkedAccountsPage->>EnhancedDataTable: Renders with paginationOptions
    EnhancedDataTable->>EnhancedDataTableToolbar: Passes paginationOptions
    EnhancedDataTableToolbar->>DataTablePagination: Conditionally renders if options present
    User->>DataTablePagination: Interacts with pagination controls (next, prev, jump)
    DataTablePagination->>EnhancedDataTable: Updates pagination state
    EnhancedDataTable->>EnhancedDataTable: Fetches and displays new page data
Loading

Assessment against linked issues

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

Possibly related PRs

  • aipotheosis-labs/aci#294: Replaces the linked accounts table with EnhancedDataTable, related to table usage but not pagination.
  • aipotheosis-labs/aci#290: Refactors a page to use EnhancedDataTable, related through table component but not pagination.

Suggested reviewers

  • dev-aipolabs
  • jiwei-aipolabs

Poem

A hop, a skip, a page anew,
With buttons bright and numbers true.
The data flows, the tables turn,
A rabbit’s joy in each page churn!
πŸƒπŸ‡
β€œJump ahead, don’t lag behindβ€”
Pagination keeps us all aligned!”

✨ 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.

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.

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
1 participant