bito-code-review[bot] commented on code in PR #39661:
URL: https://github.com/apache/superset/pull/39661#discussion_r3891740938
##########
superset-frontend/plugins/plugin-chart-table/src/DataTable/DataTable.tsx:
##########
@@ -244,6 +244,15 @@ export default typedMemo(function DataTable<D extends
object>({
...tableHooks,
);
+ // Clamp pageIndex when filtered data shrinks below current view (#31403).
+ // pageCount is derived from the filtered rows, so zero rows always means
+ // pageCount === 0 and is handled by the second branch.
+ if (pageCount > 0 && pageIndex >= pageCount) {
+ gotoPage(pageCount - 1);
+ } else if (pageCount === 0 && pageIndex !== 0) {
+ gotoPage(0);
+ }
Review Comment:
<!-- Bito Reply -->
The implementation of the clamp logic directly within the render body is
appropriate in this context. As you noted, this pattern is supported by React
for adjusting state based on props, and moving this logic to a `useEffect`
would indeed introduce a race condition where an invalid `pageIndex` could be
rendered before the effect executes. The current approach ensures the state is
consistent before the commit phase, preventing the pagination model from
entering an invalid state.
**superset-frontend/plugins/plugin-chart-table/src/DataTable/DataTable.tsx**
```
// Clamp pageIndex when filtered data shrinks below current view (#31403).
// pageCount is derived from the filtered rows, so zero rows always means
// pageCount === 0 and is handled by the second branch.
if (pageCount > 0 && pageIndex >= pageCount) {
gotoPage(pageCount - 1);
} else if (pageCount === 0 && pageIndex !== 0) {
gotoPage(0);
}
```
--
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]