Skip to content

OINT-1210: Datatable pagination #486

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 8 commits into from
Apr 22, 2025
Merged

OINT-1210: Datatable pagination #486

merged 8 commits into from
Apr 22, 2025

Conversation

Rodri77
Copy link
Collaborator

@Rodri77 Rodri77 commented Apr 17, 2025

Important

Adds pagination support to DataTable and updates various components to utilize paginated data handling.

  • Behavior:
    • Adds pagination to ConnectionsPage, ConnectorConfigList, CustomerList, and EventsList by introducing DATA_PER_PAGE constant and pageIndex state.
    • Updates DataTable component to handle paginated data with PaginatedData type and onPageChange callback.
    • Modifies processTypedPaginatedResponse() in pagination.ts to calculate total based on result length.
  • Components:
    • Updates DataTable in DataTable.tsx to support pagination with manualPagination and pageCount.
    • Adds Pagination component to DataTable for navigation controls.
    • Updates CustomersTable, ConnectorConfigTable, and DataTable stories to demonstrate pagination.
  • Misc:
    • Refactors timestamp formatting in events/page.client.tsx.
    • Adds handlePageChange function to manage page index state in multiple components.

This description was created by Ellipsis for 2752bcb. You can customize this summary. It will automatically update as commits are pushed.

Copy link

vercel bot commented Apr 17, 2025

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

Name Status Preview Comments Updated (UTC)
v1 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 21, 2025 5:39pm

Copy link

prophet-code-review-bot bot commented Apr 17, 2025

Bug Report

Name Severity Example test case Description
Division by zero in currentPage calculation Critical Set limit to 0 in the PaginatedData prop of the DataTable component. The currentPage is calculated as Math.floor(data.offset / data.limit). If data.limit is zero, this will lead to division by zero.
Incorrect data assignment in connector config page High Navigate to the connector config page. The DataTable component expects res.data to have items and total properties. However, the code directly assigns res.data to the connectorConfigs variable. It should be res.data that is passed to the DataTable, not connectorConfigs.
Incorrect data assignment in connections page High Navigate to the connections page. The DataTable component expects connectionData.data to have items and total properties. However, the code directly assigns connectionData.data.items to the data prop. It should be connectionData.data, not connectionData.data.items that is passed to the DataTable.
Incorrect data assignment in customers page High Navigate to the customers page. The CustomersTable component expects customerData.data to have items and total properties. However, the code directly assigns customerData.data.items to the data prop. It should be customerData.data, not customerData.data.items that is passed to the CustomersTable.

Copy link

recurseml bot commented Apr 17, 2025

⚠️ Only 5 files will be analyzed due to processing limits.

1 similar comment
Copy link

recurseml bot commented Apr 17, 2025

⚠️ Only 5 files will be analyzed due to processing limits.

Copy link

recurseml bot commented Apr 17, 2025

✨ No issues found! Your code is sparkling clean! ✨

🗒️ View all ignored comments in this repo
  • This export statement is redundant as it appears both in the diff and original source code. Adding it again will cause a duplicate export error. The line should be removed since it already exists in the source code.
  • Passing a Promise directly to a React component prop is incorrect. The Promise should be resolved before rendering. Either await the result before passing to the component, or use a proper data fetching pattern like React Query or SWR
  • Similar to the first bug, this prop is also passing a Promise directly without awaiting it. The API call api.listConnectors() should be awaited before passing the data. Should use 'await' before the API call.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR implements comprehensive pagination functionality across the application's data tables, with server-side pagination support and consistent UI patterns.

  • Added PaginatedData type in packages/ui-v1/components/DataTable.tsx to standardize pagination structure across tables
  • Implemented server-side pagination in DataTable component with manual pagination control and loading states
  • Fixed potential memory leak in columnsWithActions useMemo dependency array in apps/web/app/console/(authenticated)/connections/page.client.tsx
  • Added consistent page size of 10 items across all table implementations
  • Added loading state handling during page transitions with visual feedback

💡 (4/5) You can add custom instructions or style guidelines for the bot here!

8 file(s) reviewed, 10 comment(s)
Edit PR Review Bot Settings | Greptile

const PaginatedTable = (props: DataTableProps<Person, string | number>) => {
const [pageIndex, setPageIndex] = useState(0)
const [isLoading, setIsLoading] = useState(false)
const [currentData, setCurrentData] = useState(generateRandomData(10))
Copy link
Contributor

Choose a reason for hiding this comment

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

style: initial data generation should use props.data.limit instead of hardcoded 10

Comment on lines 104 to 105
type Story = StoryObj<
| typeof DataTable<Core['connector_config_select'], unknown>
| typeof ConnectorConfigTable
typeof DataTable<Core['connector_config_select'], unknown>
>
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Story type no longer includes ConnectorConfigTable but meta still uses it as component

Comment on lines +7 to +12
type PaginatedData<T> = {
items: T[]
total: number
limit: number
offset: number
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: PaginatedData type is duplicated from DataTable.tsx. Consider importing it instead of redefining.

const pageSize = isPaginated ? data.limit : items.length
const currentPage = isPaginated ? Math.floor(data.offset / data.limit) : 0

const [pageIndex, setPageIndex] = useState(currentPage)
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: pageIndex state may get out of sync with currentPage when data.offset changes externally

Suggested change
const [pageIndex, setPageIndex] = useState(currentPage)
const [pageIndex, setPageIndex] = useState(currentPage)
React.useEffect(() => {
setPageIndex(currentPage)
}, [currentPage])


export const Default: Story = {
args: {
data: customers,
onPageChange: () => {},
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Empty onPageChange handler won't demonstrate pagination behavior. Consider adding a mock implementation that logs the page change.

Suggested change
onPageChange: () => {},
onPageChange: (page: number) => { console.log('Page changed to:', page) },

Comment on lines +182 to +207
? (updater) => {
if (typeof updater === 'function') {
const newState = updater({pageIndex, pageSize})
setPageIndex(newState.pageIndex)
onPageChange?.(newState.pageIndex)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: onPaginationChange should handle non-function updaters (direct state updates) as well

type Story = StoryObj<
typeof DataTable<AppRouterOutput['listCustomers']['items'][number], unknown>
>
type Story = StoryObj<typeof CustomersTable>
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Story type changed from DataTable to CustomersTable, but meta still uses DataTable as component. This mismatch could cause type issues.

Suggested change
type Story = StoryObj<typeof CustomersTable>
const meta: Meta<typeof CustomersTable> = {
title: 'Domain Components/CustomersTable',
component: CustomersTable,
parameters: {
layout: 'padded',
},
}

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to f6198c2 in 2 minutes and 3 seconds

More details
  • Looked at 808 lines of code in 8 files
  • Skipped 0 files when reviewing.
  • Skipped posting 19 drafted comments based on config settings.
1. apps/web/app/console/(authenticated)/connections/page.client.tsx:63
  • Draft comment:
    Pagination is implemented correctly using pageIndex; ensure that the offset calculation (pageIndex * 10) aligns with API expected values.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
2. apps/web/app/console/(authenticated)/connector-config/page.client.tsx:35
  • Draft comment:
    Pagination is added by setting limit and offset; ensure that multiple queries (connector configs, connectors) remain in sync if pagination affects both.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
3. apps/web/app/console/(authenticated)/customers/page.client.tsx:9
  • Draft comment:
    Ensure the use of pageIndex state properly drives the customer list pagination.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
4. packages/ui-v1/components/DataTable.stories.tsx:207
  • Draft comment:
    The PaginatedTable story simulates a delay; ensure the delay logic (setTimeout) mimics real API pagination without side effects.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
5. packages/ui-v1/components/DataTable.tsx:180
  • Draft comment:
    The onPaginationChange callback only handles function updaters. Consider handling cases where updater might be a direct object for broader compatibility.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
6. packages/ui-v1/domain-components/tables/ConnectorConfigTable.stories.tsx:137
  • Draft comment:
    The Default story passes data as connectorConfigs.items while WithPagination uses connectorConfigs. Ensure clarity across stories for paginated and non-paginated props.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
7. packages/ui-v1/domain-components/tables/CustomerTable.tsx:71
  • Draft comment:
    The CustomersTable component wraps DataTable correctly. Verify that onPageChange and isLoading props align with paginated data structure expected by DataTable.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
8. packages/ui-v1/domain-components/tables/CustomersTable.stories.tsx:59
  • Draft comment:
    The story for CustomersTable provides a paginated data object. Ensure that the shape of data matches what CustomersTable component expects.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
9. apps/web/app/console/(authenticated)/connections/page.client.tsx:73
  • Draft comment:
    Consider memoizing the 'handlePageChange' function to avoid unnecessary re-renders.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
10. apps/web/app/console/(authenticated)/connector-config/page.client.tsx:53
  • Draft comment:
    Pagination logic is integrated well. Consider resetting pageIndex when filters or data conditions change.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
11. apps/web/app/console/(authenticated)/customers/page.client.tsx:17
  • Draft comment:
    Pagination options for listCustomers are correctly applied via limit and offset.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
12. packages/ui-v1/components/DataTable.stories.tsx:226
  • Draft comment:
    Consider parameterizing the simulated async delay in PaginatedTable for easier testing and clarity.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
13. packages/ui-v1/components/DataTable.tsx:180
  • Draft comment:
    Ensure that the onPaginationChange updater is always a function; consider adding fallback handling if a non‐function value is provided.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
14. packages/ui-v1/components/DataTable.tsx:195
  • Draft comment:
    Revisit memoization of the context value to ensure stable re-renders without performance trade-offs (see commented-out optimization).
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
15. packages/ui-v1/domain-components/tables/ConnectorConfigTable.stories.tsx:137
  • Draft comment:
    Ensure consistent data shapes for connectorConfigs: default stories pass an array while the pagination variant passes a full paginated object.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
16. packages/ui-v1/domain-components/tables/CustomersTable.stories.tsx:59
  • Draft comment:
    Consider adding additional story variants to simulate different pagination states (e.g. loading, empty page) for CustomersTable.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
17. packages/ui-v1/components/DataTable.stories.tsx:71
  • Draft comment:
    Typo: Remove the trailing comma after the closing tag of the Button in the NoData story's JSX. It may be confusing or lead to formatting issues.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
18. packages/ui-v1/components/DataTable.stories.tsx:97
  • Draft comment:
    Typo: Please remove the trailing comma after the closing Button tag in the WithCallToAction story's header. This extra comma is unnecessary and may affect consistency.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
19. packages/ui-v1/components/DataTable.tsx:248
  • Draft comment:
    Typo: The class 'size-full' seems out of place. In Tailwind CSS, 'w-full' is typically used for full width. Consider correcting this if it was unintentional.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_GwGYdqR3e0Vh9RVR


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

const pageSize = isPaginated ? data.limit : items.length
const currentPage = isPaginated ? Math.floor(data.offset / data.limit) : 0

const [pageIndex, setPageIndex] = useState(currentPage)
Copy link
Contributor

Choose a reason for hiding this comment

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

The derived currentPage is computed from data.offset but pageIndex state is initialized only once. Consider adding an effect to resync pageIndex when data.offset changes.

Copy link
Collaborator

@pellicceama pellicceama left a comment

Choose a reason for hiding this comment

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

Approach seems reasonable.

Please

  • Upload upload a video of it
  • Make 20 by default
  • Add to the events table
  • Address some of the concerning comments form the bots

@Rodri77 Rodri77 force-pushed the datatable-pagination branch from f6198c2 to 2752bcb Compare April 21, 2025 17:35
Copy link

prophet-code-review-bot bot commented Apr 21, 2025

Error: Agent timed out after 12 minutes of thinking

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed 2752bcb in 51 seconds. Click for details.
  • Reviewed 93 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 7 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. apps/web/app/console/(authenticated)/events/page.client.tsx:25
  • Draft comment:
    Good move shifting timestamp formatting into the cell renderer. Consider memoizing the date formatting for performance if the table is large.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
2. apps/web/app/console/(authenticated)/events/page.client.tsx:50
  • Draft comment:
    Ensure the TRPC response returns a paginated object with the expected shape (items, total, limit, offset) to match the DataTable's paginated data setup.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
3. packages/ui-v1/components/DataTable.tsx:375
  • Draft comment:
    Pagination now also checks for totalCount === 0 to not render pagination controls. Confirm that this behavior is intended, especially when zero items are a valid state.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
4. apps/web/app/console/(authenticated)/events/page.client.tsx:25
  • Draft comment:
    Good use of a custom cell for timestamp formatting. Consider extracting the repeated date formatting logic into a shared utility for consistency (e.g. used in sheet details too).
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
5. apps/web/app/console/(authenticated)/events/page.client.tsx:50
  • Draft comment:
    Pagination params (limit and offset) are now passed to the TRPC query. Verify that the backend correctly handles these values.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
6. apps/web/app/console/(authenticated)/events/page.client.tsx:63
  • Draft comment:
    handlePageChange updates pageIndex; ensure any dependent state (if needed) is also reset when changing pages.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
7. packages/ui-v1/components/DataTable.tsx:375
  • Draft comment:
    The added check for paginationInfo.totalCount === 0 cleanly avoids rendering pagination when no items exist. Ensure this behavior aligns with the overall UX for empty states.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_WSKTfiNBMAfG4Rlf

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@Rodri77 Rodri77 requested a review from pellicceama April 21, 2025 17:38
@pellicceama pellicceama merged commit 9403d2f into main Apr 22, 2025
9 checks passed
@pellicceama pellicceama deleted the datatable-pagination branch April 22, 2025 03:00
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.

2 participants