bito-code-review[bot] commented on code in PR #34562:
URL: https://github.com/apache/superset/pull/34562#discussion_r2776619213


##########
superset-frontend/packages/superset-ui-core/src/components/TableView/TableView.tsx:
##########
@@ -250,6 +250,22 @@ const RawTableView = ({
     }
   }, [initialState.sortBy, onServerPagination, serverPagination, sortBy]);
 
+  // Reset to first page when current page exceeds available pages
+  // (e.g., when filtering reduces the data below the current page)
+  const pageSize = initialPageSize ?? DEFAULT_PAGE_SIZE;
+  const pageCount = Math.ceil(data.length / pageSize);
+  useEffect(() => {
+    if (
+      withPagination &&
+      !serverPagination &&
+      !loading &&
+      pageIndex > pageCount - 1 &&
+      pageCount > 0
+    ) {
+      gotoPage(0);
+    }
+  }, [withPagination, serverPagination, loading, pageIndex, pageCount, 
gotoPage]);

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Pagination Reset Logic Bug</b></div>
   <div id="fix">
   
   The useEffect for resetting pageIndex on data changes has two issues: the 
condition 'pageIndex > pageCount - 1 && pageCount > 0' fails to reset when 
pageCount is 0 (e.g., no data), potentially leaving pageIndex invalid. Also, 
the deps array misses 'data.length' and 'initialPageSize', so the effect won't 
trigger if data shrinks without changing pageIndex. This could show empty pages 
incorrectly.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
     useEffect(() => {
       if (
         withPagination &&
         !serverPagination &&
         !loading &&
         pageIndex >= pageCount
       ) {
         gotoPage(0);
       }
     }, [withPagination, serverPagination, loading, pageIndex, pageCount, 
gotoPage, data.length, initialPageSize]);
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #586eb2</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]

Reply via email to