fix: badge scans list rows per page fix#811
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughPagination 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/reducers/sponsors/badge-scans-list-reducer.js (1)
24-36: Consider importing pagination constants for consistency.
DEFAULT_STATEuses hardcoded valuescurrentPage: 1andperPage: 10. These matchDEFAULT_CURRENT_PAGEandDEFAULT_PER_PAGEfromutils/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: UseDEFAULT_CURRENT_PAGEfor consistency.
handleSortuses a hardcoded1whilehandleSearchandhandlePerPageChangeuseDEFAULT_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
📒 Files selected for processing (3)
src/pages/sponsors/sponsor-badge-scans/index.jssrc/reducers/sponsors/__tests__/badge-scans-list-reducer.test.jssrc/reducers/sponsors/badge-scans-list-reducer.js
7c267df to
9877de0
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
src/pages/sponsors/sponsor-badge-scans/index.jssrc/reducers/sponsors/__tests__/badge-scans-list-reducer.test.jssrc/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
| 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); | ||
| }); |
There was a problem hiding this comment.
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.
9877de0 to
94b6442
Compare
| sponsor.id, | ||
| searchTerm, | ||
| currentPage, | ||
| DEFAULT_CURRENT_PAGE, |
There was a problem hiding this comment.
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
ref: https://app.clickup.com/t/86b7ubjgu
Summary by CodeRabbit
Bug Fixes
Tests
Chores