-
Notifications
You must be signed in to change notification settings - Fork 403
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
Conversation
…n LinkedAccountsPage
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughPagination 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
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
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
⛔ 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 theEnhancedDataTableProps
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 theEnhancedDataTableToolbar
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 suggestionFix 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.
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. |
There was a problem hiding this 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 correctionThe 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 feedbackThe 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 caseWhen 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 classThe 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
📒 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 algorithmThe 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 handlingThe component correctly handles pagination state and page jumping with appropriate validation and boundary checks.
135-160
: Nice implementation of jump-to-page functionalityThe 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 implementationThis 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
🏷️ 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 theLinkedAccountsPage
. 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)
✅ Checklist
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Enhancements
Documentation
Chores