Skip to content

fix: badge scans list rows per page fix#811

Open
priscila-moneo wants to merge 1 commit intomasterfrom
fix/badge-scans-list-rows-per-page-fix
Open

fix: badge scans list rows per page fix#811
priscila-moneo wants to merge 1 commit intomasterfrom
fix/badge-scans-list-rows-per-page-fix

Conversation

@priscila-moneo
Copy link

@priscila-moneo priscila-moneo commented Mar 4, 2026

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

Summary by CodeRabbit

  • Bug Fixes

    • Pagination now consistently tracks and respects current page and items-per-page when fetching badge scans; searches and per-page changes reset to the first page.
  • Tests

    • Added comprehensive unit tests covering badge scans list behavior, pagination, data mapping, and edge cases.
  • Chores

    • Updated copyright year references.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 53640956-a383-455d-953a-2c304a0b7204

📥 Commits

Reviewing files that changed from the base of the PR and between 9877de0 and 94b6442.

📒 Files selected for processing (3)
  • src/pages/sponsors/sponsor-badge-scans/index.js
  • src/reducers/sponsors/__tests__/badge-scans-list-reducer.test.js
  • src/reducers/sponsors/badge-scans-list-reducer.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/reducers/sponsors/tests/badge-scans-list-reducer.test.js
  • src/reducers/sponsors/badge-scans-list-reducer.js

📝 Walkthrough

Walkthrough

Pagination defaults now reset to DEFAULT_CURRENT_PAGE when searching or changing per-page on the sponsor badge scans page; the reducer records currentPage and perPage from REQUEST_BADGE_SCANS. A comprehensive test suite for the badgeScansListReducer was added.

Changes

Cohort / File(s) Summary
Badge Scans Page
src/pages/sponsors/sponsor-badge-scans/index.js
Imported DEFAULT_CURRENT_PAGE; handleSearch and handlePerPageChange now use DEFAULT_CURRENT_PAGE for fetches; copyright year updated to 2026.
Badge Scans Reducer
src/reducers/sponsors/badge-scans-list-reducer.js
On REQUEST_BADGE_SCANS, reducer now reads page and perPage from action payload and sets currentPage and perPage in state.
Reducer Tests
src/reducers/sponsors/__tests__/badge-scans-list-reducer.test.js
Added comprehensive Jest tests covering request/receive flows, pagination behavior (including per-page change reset), data normalization, sponsor append/replace, logout/reset, and default behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • smarcet

Poem

🐇 I hopped through lines and fixed the view,
Back to page one when searches brew,
Per-page flips reset with cheer,
Scans and tests now crystal clear,
A tiny rabbit clap — hooray, review! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: badge scans list rows per page fix' directly reflects the main changes in the PR, which update pagination handling (rows per page) in the badge scans list component and reducer.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/badge-scans-list-rows-per-page-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@priscila-moneo priscila-moneo marked this pull request as ready for review March 4, 2026 19:09
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.

🧹 Nitpick comments (2)
src/reducers/sponsors/badge-scans-list-reducer.js (1)

24-36: Consider importing pagination constants for consistency.

DEFAULT_STATE uses hardcoded values currentPage: 1 and perPage: 10. These match DEFAULT_CURRENT_PAGE and DEFAULT_PER_PAGE from utils/constants.js. Using the constants would improve maintainability.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/reducers/sponsors/badge-scans-list-reducer.js` around lines 24 - 36,
DEFAULT_STATE currently hardcodes pagination values (currentPage: 1, perPage:
10); import DEFAULT_CURRENT_PAGE and DEFAULT_PER_PAGE from utils/constants.js
and replace those hardcoded values in the DEFAULT_STATE object so the reducer
(badgeScansListReducer / DEFAULT_STATE) uses the shared constants for
maintainability.
src/pages/sponsors/sponsor-badge-scans/index.js (1)

81-83: Use DEFAULT_CURRENT_PAGE for consistency.

handleSort uses a hardcoded 1 while handleSearch and handlePerPageChange use DEFAULT_CURRENT_PAGE. For maintainability, consider using the constant here as well.

♻️ Suggested change
 const handleSort = (key, dir) => {
-    getBadgeScans(sponsor.id, term, 1, perPage, key, dir);
+    getBadgeScans(sponsor.id, term, DEFAULT_CURRENT_PAGE, perPage, key, dir);
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/sponsors/sponsor-badge-scans/index.js` around lines 81 - 83,
handleSort currently passes a hardcoded 1 as the page argument to getBadgeScans
while handleSearch and handlePerPageChange use DEFAULT_CURRENT_PAGE; update
handleSort to use DEFAULT_CURRENT_PAGE instead to keep behavior
consistent—locate the handleSort function and replace the literal page argument
with the DEFAULT_CURRENT_PAGE constant when calling getBadgeScans(sponsor.id,
term, DEFAULT_CURRENT_PAGE, perPage, key, dir).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/pages/sponsors/sponsor-badge-scans/index.js`:
- Around line 81-83: handleSort currently passes a hardcoded 1 as the page
argument to getBadgeScans while handleSearch and handlePerPageChange use
DEFAULT_CURRENT_PAGE; update handleSort to use DEFAULT_CURRENT_PAGE instead to
keep behavior consistent—locate the handleSort function and replace the literal
page argument with the DEFAULT_CURRENT_PAGE constant when calling
getBadgeScans(sponsor.id, term, DEFAULT_CURRENT_PAGE, perPage, key, dir).

In `@src/reducers/sponsors/badge-scans-list-reducer.js`:
- Around line 24-36: DEFAULT_STATE currently hardcodes pagination values
(currentPage: 1, perPage: 10); import DEFAULT_CURRENT_PAGE and DEFAULT_PER_PAGE
from utils/constants.js and replace those hardcoded values in the DEFAULT_STATE
object so the reducer (badgeScansListReducer / DEFAULT_STATE) uses the shared
constants for maintainability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 649457b0-9594-48d2-906c-e4e7c1931f11

📥 Commits

Reviewing files that changed from the base of the PR and between dbb5d5a and 7c267df.

📒 Files selected for processing (3)
  • src/pages/sponsors/sponsor-badge-scans/index.js
  • src/reducers/sponsors/__tests__/badge-scans-list-reducer.test.js
  • src/reducers/sponsors/badge-scans-list-reducer.js

@priscila-moneo priscila-moneo force-pushed the fix/badge-scans-list-rows-per-page-fix branch from 7c267df to 9877de0 Compare March 4, 2026 19:34
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/reducers/sponsors/__tests__/badge-scans-list-reducer.test.js`:
- Around line 41-58: The tests for badgeScansListReducer use the default
initialState so they can false-pass; replace the use of the default initialState
in the SET_CURRENT_SUMMIT and LOGOUT_USER test cases with a non-default state
fixture (e.g., a mutated copy of initialState with at least one changed
property) and assert that badgeScansListReducer(initialNonDefaultState, { type:
SET_CURRENT_SUMMIT }) and badgeScansListReducer(initialNonDefaultState, { type:
LOGOUT_USER }) return that same non-default state unchanged; update references
to initialState in those two tests to a clearly named fixture like
nonDefaultState to ensure the reducer truly preserves state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb66f86e-b161-41f7-b1e5-c6534f85f253

📥 Commits

Reviewing files that changed from the base of the PR and between 7c267df and 9877de0.

📒 Files selected for processing (3)
  • src/pages/sponsors/sponsor-badge-scans/index.js
  • src/reducers/sponsors/__tests__/badge-scans-list-reducer.test.js
  • src/reducers/sponsors/badge-scans-list-reducer.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/reducers/sponsors/badge-scans-list-reducer.js
  • src/pages/sponsors/sponsor-badge-scans/index.js

Comment on lines +41 to +58
describe("SET_CURRENT_SUMMIT", () => {
it("execution", () => {
result = badgeScansListReducer(initialState, {
type: SET_CURRENT_SUMMIT
});

expect(result).toStrictEqual(initialState);
});
});

describe("LOGOUT_USER", () => {
it("execution", () => {
result = badgeScansListReducer(initialState, {
type: LOGOUT_USER
});

expect(result).toStrictEqual(initialState);
});
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

State-preservation tests can false-pass with default-shaped input.

Line 43 and Line 53 use initialState (default values), so these assertions would still pass if the reducer incorrectly returned its default state. Use a non-default state fixture to validate true preservation behavior.

✅ Suggested test hardening
 describe("SET_CURRENT_SUMMIT", () => {
   it("execution", () => {
-    result = badgeScansListReducer(initialState, {
+    const currentState = {
+      ...initialState,
+      term: "active-filter",
+      currentPage: 3,
+      perPage: 50
+    };
+    result = badgeScansListReducer(currentState, {
       type: SET_CURRENT_SUMMIT
     });

-    expect(result).toStrictEqual(initialState);
+    expect(result).toStrictEqual(currentState);
   });
 });

 describe("LOGOUT_USER", () => {
   it("execution", () => {
-    result = badgeScansListReducer(initialState, {
+    const currentState = {
+      ...initialState,
+      term: "active-filter",
+      currentPage: 3,
+      perPage: 50
+    };
+    result = badgeScansListReducer(currentState, {
       type: LOGOUT_USER
     });

-    expect(result).toStrictEqual(initialState);
+    expect(result).toStrictEqual(currentState);
   });
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/reducers/sponsors/__tests__/badge-scans-list-reducer.test.js` around
lines 41 - 58, The tests for badgeScansListReducer use the default initialState
so they can false-pass; replace the use of the default initialState in the
SET_CURRENT_SUMMIT and LOGOUT_USER test cases with a non-default state fixture
(e.g., a mutated copy of initialState with at least one changed property) and
assert that badgeScansListReducer(initialNonDefaultState, { type:
SET_CURRENT_SUMMIT }) and badgeScansListReducer(initialNonDefaultState, { type:
LOGOUT_USER }) return that same non-default state unchanged; update references
to initialState in those two tests to a clearly named fixture like
nonDefaultState to ensure the reducer truly preserves state.

@priscila-moneo priscila-moneo force-pushed the fix/badge-scans-list-rows-per-page-fix branch from 9877de0 to 94b6442 Compare March 4, 2026 21:17
Copy link

@martinquiroga-exo martinquiroga-exo left a comment

Choose a reason for hiding this comment

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

LGTM

sponsor.id,
searchTerm,
currentPage,
DEFAULT_CURRENT_PAGE,

Choose a reason for hiding this comment

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

Although this would work since it's a safe state it will cause the UI to always take you to the first page whenever you enlarge the records per page. It's good enough for me, up to you @caseylocker

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