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 a comprehensive test suite covering sponsor-forms pagination across multiple scenarios, ensuring correct requests and async handling.
  • Bug Fixes

    • Improved pagination logic to reset to the first page when the selected page size exceeds total available items, preventing invalid backend requests.

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

@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

Renames the getSponsorForms action's second parameter from page to currentPage and adds logic to reset the effective page to 1 when perPage exceeds the total item count. Adds/rewrites tests to validate both pagination scenarios via a mocked store.

Changes

Cohort / File(s) Summary
Sponsor Forms Action
src/actions/sponsor-forms-actions.js
Renamed second parameter from pagecurrentPage; extract sponsorFormsListState (to read totalCount); compute a local page and reset it to 1 when perPage > totalCount; use computed page in API request.
Sponsor Forms Tests
src/actions/__tests__/sponsor-forms-actions.test.js
Replaced test scaffolding with Jest + jsdom, redux-mock-store, thunk, and flush-promises; mock UI core actions and token retrieval; add tests asserting request payload and page behavior for two perPage/totalCount scenarios.
Manifest / Package
manifest_file, package.json
Small metadata updates (lines changed noted in diff).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • smarcet

Poem

🐰 I nudged a page back to one with care,
When pages stretch beyond what's there,
Tests hop in to check the race,
Pagination kept in proper place,
🥕✨

🚥 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 clearly describes the main change: fixing pagination behavior on sponsor forms when rows per page change, which aligns with the changeset's core objective.
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.

@niko-exo niko-exo force-pushed the fix/pagination-does-no-work branch from 72bcbd9 to 168246c Compare January 21, 2026 19:20
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: 1

🤖 Fix all issues with AI agents
In `@src/actions/__tests__/sponsor-forms-actions.test.js`:
- Around line 46-53: The mock dispatch block incorrectly falls through and
dispatches receiveActionCreator twice when it is a function; update the block
that checks typeof receiveActionCreator === "function" (the anonymous function
passed to new Promise) to prevent fallthrough by returning after calling
dispatch(receiveActionCreator({ response: {} })) and resolve({ response: {} })
(or change to an if/else) so the unconditional dispatch(receiveActionCreator)
and resolve(...) lines are not executed in that branch.
🧹 Nitpick comments (1)
src/actions/__tests__/sponsor-forms-actions.test.js (1)

62-121: Good test coverage for the main scenarios.

The two tests effectively validate the core pagination fix behavior. Consider adding edge case tests for completeness:

  • totalCount === 0 (empty list)
  • perPage === totalCount (boundary condition)
  • Initial state where totalCount might be undefined

Comment on lines +46 to +53
return new Promise((resolve) => {
if (typeof receiveActionCreator === "function") {
dispatch(receiveActionCreator({ response: {} }));
resolve({ response: {} });
}
dispatch(receiveActionCreator);
resolve({ response: {} });
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Bug in mock: receiveActionCreator is dispatched twice when it's a function.

When receiveActionCreator is a function, the code dispatches it at line 48 and resolves, but then falls through to line 51-52 which dispatches it again unconditionally. The resolve at line 49 doesn't exit the function.

🐛 Proposed fix
             return new Promise((resolve) => {
               if (typeof receiveActionCreator === "function") {
                 dispatch(receiveActionCreator({ response: {} }));
-                resolve({ response: {} });
+                return resolve({ response: {} });
               }
               dispatch(receiveActionCreator);
               resolve({ response: {} });
             });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return new Promise((resolve) => {
if (typeof receiveActionCreator === "function") {
dispatch(receiveActionCreator({ response: {} }));
resolve({ response: {} });
}
dispatch(receiveActionCreator);
resolve({ response: {} });
});
return new Promise((resolve) => {
if (typeof receiveActionCreator === "function") {
dispatch(receiveActionCreator({ response: {} }));
return resolve({ response: {} });
}
dispatch(receiveActionCreator);
resolve({ response: {} });
});
🤖 Prompt for AI Agents
In `@src/actions/__tests__/sponsor-forms-actions.test.js` around lines 46 - 53,
The mock dispatch block incorrectly falls through and dispatches
receiveActionCreator twice when it is a function; update the block that checks
typeof receiveActionCreator === "function" (the anonymous function passed to new
Promise) to prevent fallthrough by returning after calling
dispatch(receiveActionCreator({ response: {} })) and resolve({ response: {} })
(or change to an if/else) so the unconditional dispatch(receiveActionCreator)
and resolve(...) lines are not executed in that branch.

@niko-exo
Copy link
Author

Branch rebased

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