bito-code-review[bot] commented on code in PR #38563:
URL: https://github.com/apache/superset/pull/38563#discussion_r2934040005
##########
superset-frontend/packages/superset-ui-core/src/components/TableView/TableView.tsx:
##########
@@ -117,43 +117,45 @@ const RawTableView = ({
...props
}: TableViewProps) => {
const tableRef = useRef<HTMLTableElement>(null);
+ const effectivePageSize = initialPageSize ?? DEFAULT_PAGE_SIZE;
+ const [pageIndex, setPageIndex] = useState(initialPageIndex ?? 0);
const initialState = useMemo(
() => ({
- pageSize: initialPageSize ?? DEFAULT_PAGE_SIZE,
- pageIndex: initialPageIndex ?? 0,
+ pageSize: effectivePageSize,
+ pageIndex: 0,
sortBy: initialSortBy,
}),
- [initialPageSize, initialPageIndex, initialSortBy],
+ [effectivePageSize, initialSortBy],
);
const {
getTableProps,
getTableBodyProps,
headerGroups,
- page,
rows,
prepareRow,
- gotoPage,
setSortBy,
- state: { pageIndex, sortBy },
+ state: { sortBy },
} = useTable(
{
columns,
data,
initialState,
- manualPagination: serverPagination,
+ manualPagination: true,
manualSortBy: serverPagination,
- pageCount: serverPagination
- ? Math.ceil(totalCount / initialState.pageSize)
- : undefined,
autoResetSortBy: false,
},
useFilters,
useSortBy,
- ...(withPagination ? [usePagination] : []),
);
+ const content = useMemo(() => {
+ if (!withPagination) return rows;
+ const start = pageIndex * effectivePageSize;
+ return rows.slice(start, start + effectivePageSize);
+ }, [withPagination, rows, pageIndex, effectivePageSize]);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Server pagination data slicing error</b></div>
<div id="fix">
For server-side pagination, the data prop should contain only the current
page's data from the server, so client-side slicing in the content useMemo is
incorrect and can display wrong or empty rows. The condition should return rows
un sliced when serverPagination is enabled.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
const content = useMemo(() => {
if (!withPagination || serverPagination) return rows;
const start = pageIndex * effectivePageSize;
return rows.slice(start, start + effectivePageSize);
}, [withPagination, rows, pageIndex, effectivePageSize, serverPagination]);
````
</div>
</details>
</div>
<small><i>Code Review Run #098e84</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]