bito-code-review[bot] commented on code in PR #37555:
URL: https://github.com/apache/superset/pull/37555#discussion_r2835660416
##########
superset-frontend/src/components/Datasource/components/CollectionTable/index.tsx:
##########
@@ -416,6 +448,21 @@ export default class CRUDCollection extends PureComponent<
}
: undefined;
+ // Build controlled pagination config, clamping currentPage to valid range
+ // when the collection shrinks (e.g. due to filtering/search)
+ const totalItems = this.state.collectionArray.length;
+ const pageSize = this.state.pageSize;
+ const maxPage = totalItems > 0 ? Math.ceil(totalItems / pageSize) : 1;
+ const currentPage = Math.min(this.state.currentPage, maxPage);
+ const paginationConfig: false | TablePaginationConfig | undefined =
+ pagination === false || pagination === undefined
+ ? pagination
+ : {
+ ...(typeof pagination === 'object' ? pagination : {}),
+ current: currentPage,
+ pageSize,
+ };
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incorrect pagination clamping with filtering</b></div>
<div id="fix">
The pagination clamping logic uses the full collectionArray.length for
totalItems, but since pagination applies to the filtered displayData, this can
result in currentPage being set to a value higher than the available pages in
the filtered view. For example, if filtering reduces 100 items to 5 and the
user is on page 5, currentPage remains 5 instead of being clamped to 1. Change
totalItems to displayData.length and add total to paginationConfig for correct
behavior.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
const totalItems = displayData.length;
const pageSize = this.state.pageSize;
const maxPage = totalItems > 0 ? Math.ceil(totalItems / pageSize) : 1;
const currentPage = Math.min(this.state.currentPage, maxPage);
const paginationConfig: false | TablePaginationConfig | undefined =
pagination === false || pagination === undefined
? pagination
: {
...(typeof pagination === 'object' ? pagination : {}),
current: currentPage,
pageSize,
total: totalItems,
};
````
</div>
</details>
</div>
<small><i>Code Review Run #d6e220</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]