Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ const FormTemplateItemListPage = ({
);
};

const handlePerPageChange = (newPerPage) => {
getFormTemplateItems(
formTemplateId,
term,
DEFAULT_CURRENT_PAGE,
newPerPage,
order,
orderDir,
hideArchived
);
};
Comment on lines +104 to +114
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify callback source and current per-page handlers for potential string propagation.
rg -nP --type=js -C2 'handleChangeRowsPerPage\s*=\s*\(ev\)\s*=>\s*\{\s*onPerPageChange\(ev\.target\.value\)' src/components/mui
rg -nP --type=js -C2 'handlePerPageChange|handleManagedPerPageChange|handleCustomizedPerPageChange' src/pages

Repository: fntechgit/summit-admin

Length of output: 23932


🏁 Script executed:

cat -n src/components/mui/table/mui-table.js | sed -n '50,75p'

Repository: fntechgit/summit-admin

Length of output: 911


🏁 Script executed:

# Find the getFormTemplateItems action/reducer to see how perPage is used
rg -nP 'getFormTemplateItems|formTemplateItems' src --type=js -l | head -20

Repository: fntechgit/summit-admin

Length of output: 335


🏁 Script executed:

# Check action creators for form template items
fd -e js -p src | xargs grep -l "getFormTemplateItems" | head -10

Repository: fntechgit/summit-admin

Length of output: 268


🏁 Script executed:

cat -n src/actions/form-template-item-actions.js | head -50

Repository: fntechgit/summit-admin

Length of output: 2203


🏁 Script executed:

# Check how perPage is used in the reducer
cat -n src/reducers/sponsors_inventory/form-template-item-list-reducer.js | head -100

Repository: fntechgit/summit-admin

Length of output: 3524


🏁 Script executed:

# Search for API calls or functions that receive perPage to see if type matters
rg -nP 'perPage' src/actions/form-template-item-actions.js -A 3 -B 1

Repository: fntechgit/summit-admin

Length of output: 329


🏁 Script executed:

rg -nP 'export.*getFormTemplateItems' src/actions/form-template-item-actions.js -A 30

Repository: fntechgit/summit-admin

Length of output: 906


🏁 Script executed:

# Check how per_page is used in API calls across the codebase
rg -nP 'per_page' src/actions/form-template-item-actions.js -B 5 -A 5

Repository: fntechgit/summit-admin

Length of output: 352


🏁 Script executed:

# Check how perPage is used in the MUI table component
rg -nP 'perPage' src/components/mui/table/mui-table.js -B 2 -A 2

Repository: fntechgit/summit-admin

Length of output: 661


🏁 Script executed:

# Check if there are any arithmetic or comparison operations on perPage in the reducer or elsewhere
rg -nP 'perPage\s*[\+\-\*\/\%<>==!]|perPage\s*\?' src/reducers/sponsors_inventory/form-template-item-list-reducer.js

Repository: fntechgit/summit-admin

Length of output: 48


🏁 Script executed:

# Check the constants to confirm DEFAULT_PER_PAGE is numeric
rg -nP 'DEFAULT_PER_PAGE|TWENTY_PER_PAGE|FIFTY_PER_PAGE' src/utils/constants.js

Repository: fntechgit/summit-admin

Length of output: 179


🏁 Script executed:

# Check if there are any tests that verify the string-to-number handling
rg -nP 'handlePerPageChange|newPerPage' src/pages/sponsors-global/form-templates/__tests__/form-template-item-list-page.test.js -B 2 -A 2

Repository: fntechgit/summit-admin

Length of output: 48


🏁 Script executed:

# Verify the exact flow: check line 73-75 of mui-table.js more closely
cat -n src/components/mui/table/mui-table.js | sed -n '70,80p'

Repository: fntechgit/summit-admin

Length of output: 510


🏁 Script executed:

# Check if there's any type coercion happening in the reducer when storing perPage
cat -n src/reducers/sponsors_inventory/form-template-item-list-reducer.js | sed -n '42,68p'

Repository: fntechgit/summit-admin

Length of output: 839


🏁 Script executed:

# Check the actual TablePagination implementation to see if it expects numeric rowsPerPage
rg -nP 'rowsPerPage' src/components/mui/table/mui-table.js -B 1 -A 1

Repository: fntechgit/summit-admin

Length of output: 234


🏁 Script executed:

# Look for any normalization or parseInt/Number calls in similar handlers across the codebase
rg -nP 'Number\(|parseInt\(' src/pages/sponsors-global/form-templates/form-template-item-list-page.js

Repository: fntechgit/summit-admin

Length of output: 48


🏁 Script executed:

# Final verification: confirm the exact type that reaches perPage in reducer via payload
rg -nP 'REQUEST_FORM_TEMPLATE_ITEMS' src/actions/form-template-item-actions.js -B 5 -A 10

Repository: fntechgit/summit-admin

Length of output: 1694


🏁 Script executed:

# Verify that perPage is NOT included in the payload to the reducer
cat -n src/actions/form-template-item-actions.js | sed -n '112,121p'

Repository: fntechgit/summit-admin

Length of output: 505


🏁 Script executed:

# Check how the MUI TablePagination component behaves with string vs numeric rowsPerPage
rg -nP 'MuiTablePagination|TablePagination' src/components/mui/table/mui-table.js -B 2 -A 8

Repository: fntechgit/summit-admin

Length of output: 1436


🏁 Script executed:

# Check if there's any additional reducer action that updates perPage from the handler
rg -nP 'perPage' src/actions/form-template-item-actions.js

Repository: fntechgit/summit-admin

Length of output: 128


🏁 Script executed:

# Verify if perPage is passed in reducer payload by checking the createAction call
rg -nP 'createAction.*perPage|dispatch.*perPage' src/pages/sponsors-global/form-templates/form-template-item-list-page.js

Repository: fntechgit/summit-admin

Length of output: 48


Normalize newPerPage to a number before dispatching.

onPerPageChange receives ev.target.value from the MUI table callback, which is a string. Passing it directly causes type mismatches: the sort operation in mui-table.js (line 75) will fail when a string is added to a numeric array and sorted with arithmetic, and MUI's TablePagination component expects a numeric rowsPerPage prop.

Proposed patch
   const handlePerPageChange = (newPerPage) => {
+    const perPageValue = Number(newPerPage);
+    if (Number.isNaN(perPageValue)) return;
+
     getFormTemplateItems(
       formTemplateId,
       term,
       DEFAULT_CURRENT_PAGE,
-      newPerPage,
+      perPageValue,
       order,
       orderDir,
       hideArchived
     );
   };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/sponsors-global/form-templates/form-template-item-list-page.js`
around lines 104 - 114, The handlePerPageChange handler passes newPerPage (a
string from MUI) directly into getFormTemplateItems causing type mismatches;
coerce newPerPage to a number before dispatching (e.g., parseInt/Number) and
pass that numeric value into getFormTemplateItems and as the rowsPerPage
equivalent so DEFAULT_CURRENT_PAGE, order, orderDir, and hideArchived calls
remain unchanged; update references in handlePerPageChange and any places that
consume its value to expect a Number (function: handlePerPageChange, call:
getFormTemplateItems).


const handleSort = (key, dir) => {
getFormTemplateItems(
formTemplateId,
Expand Down Expand Up @@ -295,6 +307,7 @@ const FormTemplateItemListPage = ({
totalRows={totalFormTemplateItems}
currentPage={currentPage}
onPageChange={handlePageChange}
onPerPageChange={handlePerPageChange}
onSort={handleSort}
onEdit={handleRowEdit}
onArchive={handleArchiveItem}
Expand Down
12 changes: 12 additions & 0 deletions src/pages/sponsors/sponsor-form-item-list-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ const SponsorFormItemListPage = ({
getSponsorFormItems(formId, page, perPage, order, orderDir, hideArchived);
};

const handlePerPageChange = (newPerPage) => {
getSponsorFormItems(
formId,
DEFAULT_CURRENT_PAGE,
newPerPage,
order,
orderDir,
hideArchived
);
};

const handleSort = (key, dir) => {
getSponsorFormItems(formId, currentPage, perPage, key, dir, hideArchived);
};
Expand Down Expand Up @@ -283,6 +294,7 @@ const SponsorFormItemListPage = ({
currentPage={currentPage}
onDelete={handleRowDelete}
onPageChange={handlePageChange}
onPerPageChange={handlePerPageChange}
onSort={handleSort}
onCellChange={handleCellEdit}
onEdit={handleRowEdit}
Expand Down
29 changes: 28 additions & 1 deletion src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ const SponsorFormsTab = ({
getSponsorManagedForms(term, page, perPage, order, orderDir, hideArchived);
};

const handleManagedPerPageChange = (newPerPage) => {
const { order, orderDir } = managedForms;
getSponsorManagedForms(
term,
DEFAULT_CURRENT_PAGE,
newPerPage,
order,
orderDir,
hideArchived
);
};

const handleManagedSort = (key, dir) => {
const { currentPage, perPage } = managedForms;
getSponsorManagedForms(term, currentPage, perPage, key, dir, hideArchived);
Expand All @@ -84,6 +96,18 @@ const SponsorFormsTab = ({
);
};

const handleCustomizedPerPageChange = (newPerPage) => {
const { order, orderDir } = customizedForms;
getSponsorCustomizedForms(
term,
DEFAULT_CURRENT_PAGE,
newPerPage,
order,
orderDir,
hideArchived
);
};

const handleCustomizedSort = (key, dir) => {
const { currentPage, perPage } = customizedForms;
getSponsorCustomizedForms(
Expand Down Expand Up @@ -157,7 +181,8 @@ const SponsorFormsTab = ({
);
};

const handleSaveFormFromTemplate = (entity) => saveSponsorManagedForm(entity).then(() => {
const handleSaveFormFromTemplate = (entity) =>
saveSponsorManagedForm(entity).then(() => {
const { perPage, order, orderDir } = managedForms;
getSponsorManagedForms(
term,
Expand Down Expand Up @@ -364,6 +389,7 @@ const SponsorFormsTab = ({
totalRows={customizedForms.totalCount}
currentPage={customizedForms.currentPage}
onPageChange={handleCustomizedPageChange}
onPerPageChange={handleCustomizedPerPageChange}
onSort={handleCustomizedSort}
onEdit={handleCustomizedEdit}
onDelete={handleCustomizedDelete}
Expand All @@ -383,6 +409,7 @@ const SponsorFormsTab = ({
totalRows={managedForms.totalCount}
currentPage={managedForms.currentPage}
onPageChange={handleManagedPageChange}
onPerPageChange={handleManagedPerPageChange}
onSort={handleManagedSort}
/>
</div>
Expand Down
Loading