codeant-ai-for-open-source[bot] commented on code in PR #37555:
URL: https://github.com/apache/superset/pull/37555#discussion_r2842200244


##########
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;

Review Comment:
   **Suggestion:** The pagination clamping logic uses the full, unfiltered 
collection length instead of the filtered `displayData` length, so when a 
search filter reduces the number of rows and the user is on a higher page, the 
table can show an empty page because `currentPage` remains valid for the 
unfiltered collection but out of range for the filtered data. Use 
`displayData.length` when computing `totalItems` so `currentPage` is clamped 
against the actually rendered rows. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Metrics tab search can show empty table unexpectedly.
   - ⚠️ Users may think no metrics match their search.
   - ⚠️ Editing metrics becomes confusing when filter hides rows.
   - ⚠️ New pagination/filter UX degraded on multi-page datasets.
   ```
   </details>
   
   ```suggestion
       const totalItems = displayData.length;
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open any dataset in the Dataset Editor UI, which renders 
`DatasourceEditor` in
   
`superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx`
   (constructor and `render()` around lines 307–2599).
   
   2. Navigate to the "Metrics" tab, which calls 
`this.renderMetricCollection()` (same file)
   and renders `CollectionTable` with both `pagination` and filter props:
   
      - `pagination={{ pageSize: 25, showSizeChanger: true, pageSizeOptions: 
[10, 25, 50,
      100] }}`
   
      - `filterTerm={metricSearchTerm}`, `filterFields={['metric_name', 
'verbose_name']}`.
   
   3. Ensure the dataset has more than 50 metrics so that pagination creates at 
least 3
   pages; click through the table pagination controls to go to page 3 (this sets
   `currentPage` in `CRUDCollection` state via `handleTableChange` in
   `CollectionTable/index.tsx`).
   
   4. In the "Search metrics by key or label" input (defined in 
`renderMetricCollection`),
   type a search term that matches only a small number of metrics (e.g., 1–2, 
fewer than
   `pageSize`), causing `displayData` in `CRUDCollection.render()` (same file) 
to be computed
   from `this.state.collectionArray.filter(...)` while the pagination config at 
lines 451–464
   still uses `this.state.collectionArray.length` for `totalItems`. Because 
`currentPage`
   remains 3 but `displayData.length` is now < `pageSize`, the `Table` receives
   `data={displayData}` with `pagination.current=3` and `pageSize=25`, 
resulting in an empty
   table body despite matching rows existing on "page 1" of the filtered 
results.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/components/Datasource/components/CollectionTable/index.tsx
   **Line:** 453:453
   **Comment:**
        *Logic Error: The pagination clamping logic uses the full, unfiltered 
collection length instead of the filtered `displayData` length, so when a 
search filter reduces the number of rows and the user is on a higher page, the 
table can show an empty page because `currentPage` remains valid for the 
unfiltered collection but out of range for the filtered data. Use 
`displayData.length` when computing `totalItems` so `currentPage` is clamped 
against the actually rendered rows.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37555&comment_hash=5f3ccdf1c363eb77e50b562f0177029b5cc8e25ab8cde1039b5c01cdceecbd5c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37555&comment_hash=5f3ccdf1c363eb77e50b562f0177029b5cc8e25ab8cde1039b5c01cdceecbd5c&reaction=dislike'>👎</a>



-- 
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