Skip to content

feat: Add pagination with Prev/Next buttons to Data Explorer#55

Open
devendra-w wants to merge 3 commits into
Mananwebdev160408:mainfrom
devendra-w:feat-pagination
Open

feat: Add pagination with Prev/Next buttons to Data Explorer#55
devendra-w wants to merge 3 commits into
Mananwebdev160408:mainfrom
devendra-w:feat-pagination

Conversation

@devendra-w
Copy link
Copy Markdown
Contributor

Summary

Closes #11

Adds Prev/Next pagination buttons to the Data Explorer so users can browse large tables page by page instead of being limited to the first few records.


Type of Change

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • Documentation update
  • UI / style improvement
  • Tests
  • Config / CI / tooling

What Was Changed

  • Added offset and pageSize (50) state variables in App.tsx
  • Updated loadTable to pass offset and limit parameters to the API
  • Added Prev/Next buttons below the table with current page number indicator
  • Disabled Prev button when on first page (offset === 0)
  • Disabled Next button when returned data is less than pageSize (no more records)
  • Reset offset to 0 when switching to a different table

How to Test

  1. Run npm install && npm run dev (backend) and npm run dev:ui (frontend)
  2. Set up .env with a DATABASE_URL pointing to a database with 50+ records
  3. Open http://localhost:3000
  4. Click any table from the sidebar
  5. Click Next to go to the next page — verify data changes
  6. Click Prev to go back — verify Prev is disabled on page 1
  7. Verify Next is disabled on the last page

Checklist

  • My code follows the project's TypeScript conventions
  • npm run lint passes (no TypeScript errors)
  • I have tested my changes locally
  • I have added comments where the code is complex or non-obvious
  • This PR is linked to an open issue

Screenshots (if UI change)


Related Issues / PRs

Resolves #11 — Pagination for Data Explorer

@Mananwebdev160408
Copy link
Copy Markdown
Owner

Thanks for tackling pagination! This is a highly requested feature, but there are a few React state and closure bugs in the current implementation that prevent it from functioning correctly:

  1. Stale Closure Bug in loadTable
    The loadTable function is wrapped in useCallback with [activeDbId] as its only dependency. Because it references the offset state variable inside the function body, offset will always evaluate to its initial value (0) inside the closure, regardless of what page the user clicks.

    • Fix: Update loadTable to accept an offset parameter (e.g., targetOffset?: number) instead of relying on the component state.
  2. State Reset Bug
    Inside loadTable, there is an explicit call to setOffset(0);. This means every time loadTable runs (even when clicking "Next"), it immediately forces the UI back to page 1.

    • Fix: You should only reset the offset to 0 when switching tables or changing filters, not during regular pagination.
  3. Component Clutter
    Adding all the pagination JSX and inline CSS styles directly into App.tsx makes the main file quite cluttered.

    • Fix: Consider extracting the Prev/Next buttons into a separate, reusable <Pagination /> component.
  4. Stacked Commits
    This branch currently contains commits from PRs fix: add Ctrl+Enter keyboard shortcut to run query in QueryWorkbench #52, fix: add friendly error UI with retry button for failed API calls #53, and feat: Add Export CSV button to TableView for data export #54 which have just been merged into main.

    • Fix: Please run git pull origin main and rebase your branch against main to remove the duplicate commits and prevent merge conflicts.

Could you please look into addressing these state issues? Let us know if you need any help with the React hooks!

@devendra-w
Copy link
Copy Markdown
Contributor Author

Thank you for the detailed review! I understand all 4 issues clearly.

Here's my plan to fix them:

  1. Update loadTable to accept a targetOffset parameter instead of reading from state
  2. Only call setOffset(0) when switching tables, not during Next/Prev clicks
  3. Extract pagination into a separate <Pagination /> component
  4. Rebase the branch against main to remove duplicate commits

I'll push the fixes shortly!

@devendra-w
Copy link
Copy Markdown
Contributor Author

Fixed all 4 issues:

  1. Updated loadTable to accept targetOffset parameter no more stale closure
  2. setOffset(0) only called when switching tables, not during Next/Prev
  3. Extracted pagination into separate <Pagination /> component
  4. Rebased against main duplicate commits removed

Build passes with 0 TypeScript errors. Ready for review @Mananwebdev160408!

@devendra-w
Copy link
Copy Markdown
Contributor Author

Hey @Mananwebdev160408, just checking in on this PR. Could you confirm if this project is officially listed under GSSoC 2026? Wanted to make sure my contributions will be counted toward the program. Thanks!

@Mananwebdev160408
Copy link
Copy Markdown
Owner

Sorry for the delay in reviewing this, it was due to my end-semester exams.

@Mananwebdev160408
Copy link
Copy Markdown
Owner

Hi @devendra-w,

Thanks for the contribution! We reviewed this PR and found a couple of issues that need to be resolved before it can be merged:

  1. Merge Conflicts: The PR currently has merge conflicts with the main branch.
  2. Missing Pagination Parameters in Fetch Call: Although the offset, resolvedOffset, and pageSize state variables are defined in the frontend, they are never passed to the backend. In App.tsx, the fetch URL is constructed as:
    let url = `/api/data/${encodeURIComponent(name)}?dbId=${dbToUse}&limit=200`;
    It should instead use the dynamic pageSize (as the limit query param) and resolvedOffset (as the offset query param) to let the backend know which page to retrieve:
    let url = `/api/data/${encodeURIComponent(name)}?dbId=${dbToUse}&limit=${pageSize}&offset=${resolvedOffset}`;
  3. Infinite Loading of Page 1: Because of the hardcoded limit=200 and missing offset query parameter, clicking "Prev"/"Next" pagination buttons triggers a reload but always shows the exact same first page of records.

Please resolve the merge conflicts and update the fetch call parameters so we can merge this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pagination for Data Explorer

2 participants