codeant-ai-for-open-source[bot] commented on code in PR #41754:
URL: https://github.com/apache/superset/pull/41754#discussion_r3529607117
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/AgGridTableChart.tsx:
##########
@@ -113,26 +114,55 @@ export default function TableChart<D extends DataRecord =
DataRecord>(
}
}, [columns]);
+ // A single effect owns every ownState write derived from render state.
+ // updateTableOwnState replaces ownState wholesale, so separate effects that
+ // each spread serverPaginationData in the same render would clobber one
+ // another's keys: clamping the current page, priming the raw-mode summary
+ // columns and nudging a re-query for missing totals must be one combined
+ // delta.
useEffect(() => {
- if (!serverPagination || !serverPaginationData || !rowCount) return;
+ const nextOwnState = { ...serverPaginationData };
+ let changed = false;
+
+ if (serverPagination && serverPaginationData && rowCount) {
+ const currentPage = serverPaginationData.currentPage ?? 0;
+ const currentPageSize = serverPaginationData.pageSize ??
serverPageLength;
+ const totalPages = Math.ceil(rowCount / currentPageSize);
+ if (currentPage >= totalPages && totalPages > 0) {
+ nextOwnState.currentPage = Math.max(0, totalPages - 1);
+ changed = true;
Review Comment:
Yes — this is a real bug.
The current guard:
```ts
if (serverPagination && serverPaginationData && rowCount) {
```
treats `0` as “missing”, so the clamp logic never runs when filters reduce
the result set to zero rows. That can leave a stale `currentPage` in `ownState`.
### Minimal fix
Check for a defined row count instead of truthiness, and clamp zero-row
cases to page `0`:
```ts
if (serverPagination && serverPaginationData && rowCount !== undefined) {
const currentPage = serverPaginationData.currentPage ?? 0;
const currentPageSize = serverPaginationData.pageSize ?? serverPageLength;
const totalPages = Math.ceil(rowCount / currentPageSize);
if (totalPages === 0 || currentPage >= totalPages) {
nextOwnState.currentPage = 0;
changed = true;
}
}
```
This keeps pagination state consistent when the dataset becomes empty.
Would you like me to review and fix the other comments on this PR as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]