Skip to content

Conversation

@niko-exo
Copy link

@niko-exo niko-exo commented Jan 16, 2026

ref: https://app.clickup.com/t/86b7gfrw5

86b7gfrw5 - fix: pagination on sponsor forms when rows per page change

Changelog

  • Set page parameter on service call depending on the totalCount and pages perPages selected.
  • Unit tests.

Links

86b7gfrw5 - Pagination does not function, throws error

Evidence

2026-01-16_15-09-29.-.evidence.-.86b7gfrw5.mp4

Summary by CodeRabbit

  • Tests

    • Added comprehensive test suite for sponsor forms pagination with multiple scenarios.
  • Bug Fixes

    • Improved pagination handling to reset to the first page when page size exceeds available items, preventing potential backend errors.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

The pull request renames the getSponsorForms action's second parameter from page to currentPage and introduces pagination reset logic that automatically sets the page to 1 when the items-per-page value exceeds the total item count. A test suite validates both pagination scenarios.

Changes

Cohort / File(s) Summary
Sponsor Forms Actions
src/actions/sponsor-forms-actions.js
Renamed page parameter to currentPage, added sponsorFormsListState extraction, and implemented conditional page reset to 1 when perPage exceeds totalCount.
Sponsor Forms Actions Tests
src/actions/__tests__/sponsor-forms-actions.test.js
New test suite using redux-mock-store and thunk that validates two pagination scenarios: when perPage exceeds totalCount (page resets to 1) and when perPage is less than totalCount (respects user selection).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • smarcet

Poem

🐰 A page reset when sizes grow too wide,
Sponsor forms now paginate with pride,
Tests verify each hop is just right,
From perPage's constraints to pagination's flight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: pagination on sponsor forms when rows per page change' clearly and specifically describes the main change: fixing pagination behavior when the rows-per-page value changes on sponsor forms.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/actions/sponsor-forms-actions.js (1)

117-132: Cap currentPage to lastPage when perPage changes.

Line 131 only resets when perPage > totalCount. If perPage increases but still <= totalCount, currentPage can still exceed the last page (e.g., totalCount=50, perPage=25, currentPage=3). This will keep sending an invalid page and can still trigger the backend error you’re trying to avoid. Consider computing lastPage and capping currentPage.

🐛 Proposed fix
-    // Resets page to avoid backend error.
-    const page = perPage > totalCount ? 1 : currentPage;
+    // Reset/cap page to avoid backend errors.
+    const safeTotal = Number.isFinite(totalCount) ? totalCount : 0;
+    const lastPage = Math.max(1, Math.ceil(safeTotal / perPage));
+    const page = Math.min(currentPage, lastPage);
🧹 Nitpick comments (1)
src/actions/__tests__/sponsor-forms-actions.test.js (1)

62-121: Add a test for currentPage > lastPage when perPage changes.

Right now the tests don’t cover the scenario where perPage changes but currentPage is now beyond the last page (even if perPage <= totalCount). Adding a test will lock in the intended cap behavior once the fix above is applied.

✅ Suggested test case
+      it("should cap page to last page when currentPage exceeds last page after perPage change", async () => {
+        const store = mockStore({
+          currentSummitState: { currentSummit: {} },
+          sponsorFormsListState: { totalCount: 50 }
+        });
+
+        store.dispatch(getSponsorForms("", 5, 25, "id", 1, false, []));
+        await flushPromises();
+
+        expect(getRequest).toHaveBeenCalledWith(
+          expect.anything(),
+          expect.anything(),
+          expect.anything(),
+          expect.anything(),
+          {
+            hideArchived: false,
+            order: "id",
+            orderDir: 1,
+            page: 2,
+            perPage: 25,
+            term: ""
+          }
+        );
+      });
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b3148d and 72bcbd9.

📒 Files selected for processing (2)
  • src/actions/__tests__/sponsor-forms-actions.test.js
  • src/actions/sponsor-forms-actions.js
🧰 Additional context used
🧬 Code graph analysis (2)
src/actions/sponsor-forms-actions.js (4)
src/reducers/sponsors/sponsor-form-items-list-reducer.js (1)
  • currentPage (79-83)
src/reducers/sponsors/sponsor-forms-list-reducer.js (3)
  • currentPage (95-99)
  • currentPage (190-194)
  • currentPage (222-227)
src/reducers/sponsors/sponsor-page-forms-list-reducer.js (2)
  • currentPage (96-100)
  • currentPage (138-142)
src/utils/constants.js (6)
  • DEFAULT_CURRENT_PAGE (73-73)
  • DEFAULT_CURRENT_PAGE (73-73)
  • DEFAULT_PER_PAGE (75-75)
  • DEFAULT_PER_PAGE (75-75)
  • DEFAULT_ORDER_DIR (91-91)
  • DEFAULT_ORDER_DIR (91-91)
src/actions/__tests__/sponsor-forms-actions.test.js (1)
src/actions/sponsor-forms-actions.js (2)
  • getSponsorForms (106-168)
  • getSponsorForms (106-168)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

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.

3 participants