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


##########
superset-frontend/src/explore/components/controls/ContourControl/index.tsx:
##########
@@ -88,12 +89,9 @@ const ContourControl = ({ onChange, ...props }: 
ContourControlProps) => {
   };
 
   const onShiftContour = (hoverIndex: number, dragIndex: number) => {
-    const newContours = [...contours];
-    [newContours[hoverIndex], newContours[dragIndex]] = [
-      newContours[dragIndex],
-      newContours[hoverIndex],
-    ];
-    setContours(newContours);
+    // @dnd-kit reports the final indices at drag-end, so reorder with a full
+    // arrayMove rather than an adjacent swap to support non-adjacent drags.
+    setContours(arrayMove(contours, dragIndex, hoverIndex));

Review Comment:
   **Suggestion:** The reorder callback still receives indices in the legacy 
`(hoverIndex, dragIndex)` semantic order, but `arrayMove` expects `(fromIndex, 
toIndex)`. Using `arrayMove(contours, dragIndex, hoverIndex)` with the current 
parameter naming reverses the move direction, so dragging item A onto B can 
move B to A instead. Swap the arguments passed to `arrayMove` (or 
rename/reorder the callback parameters) so the source index is first and 
destination index is second. [incorrect variable usage]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ ContourControl pill reordering moves wrong contour entry.
   - ⚠️ DeckGL Contour chart shows unexpected contour order.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open an Explore view using the DeckGL Contour visualization; its control 
panel wires
   the `contours` control to `ContourControl` via
   `plugins/preset-chart-deckgl/src/layers/Contour/controlPanel.ts:12-23` and 
the control
   registry in `superset-frontend/src/explore/components/controls/index.ts:29` 
(mapping
   `ContourControl` into `controlMap`).
   
   2. In `ContourControl`
   
(`superset-frontend/src/explore/components/controls/ContourControl/index.tsx`, 
new hunk
   around lines 79-45), note that `valuesRenderer` maps `contours` to 
`ContourOption`
   components and passes `onShift={onShiftContour}` (lines 34-45 in the read 
snippet), while
   `onShiftContour` is declared as `(hoverIndex: number, dragIndex: number)` 
and implemented
   with `setContours(arrayMove(contours, dragIndex, hoverIndex));` at PR diff 
line 94.
   
   3. When the user drags an existing contour pill to reorder (e.g., dragging 
item at index 0
   over the pill at index 2), `OptionWrapper`
   
(`superset-frontend/src/explore/components/controls/DndColumnSelectControl/OptionWrapper.tsx:65-85`)
   registers each pill with `useSortable` data `{ type, dragIndex: index, 
onShiftOptions }`.
   On drag end, `resolveDragEnd` in
   
`superset-frontend/src/explore/components/ExploreContainer/ExploreDndContext.tsx:153-177`
   detects a same-list reorder and calls the active pill’s reorder callback as
   `reorderCallback(activeData.dragIndex, overData.dragIndex)`, so 
`onShiftContour` receives
   `(fromIndex, toIndex)` even though its parameters are named `(hoverIndex, 
dragIndex)`.
   
   4. Inside `onShiftContour`, the call `setContours(arrayMove(contours, 
dragIndex,
   hoverIndex));` at line 94 uses `dragIndex` (the destination index) as 
`arrayMove`’s
   `fromIndex` and `hoverIndex` (the source index) as `toIndex`. This reverses 
the move
   direction: dragging the pill at index 0 over the pill at index 2 moves the 
pill originally
   at index 2 to index 0 instead of moving the dragged pill to index 2, 
producing inverted
   contour pill reordering in the Explore ContourControl UI.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c34549fb155b488c84ddb6e4b1ceacac&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c34549fb155b488c84ddb6e4b1ceacac&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/explore/components/controls/ContourControl/index.tsx
   **Line:** 94:94
   **Comment:**
        *Incorrect Variable Usage: The reorder callback still receives indices 
in the legacy `(hoverIndex, dragIndex)` semantic order, but `arrayMove` expects 
`(fromIndex, toIndex)`. Using `arrayMove(contours, dragIndex, hoverIndex)` with 
the current parameter naming reverses the move direction, so dragging item A 
onto B can move B to A instead. Swap the arguments passed to `arrayMove` (or 
rename/reorder the callback parameters) so the source index is first and 
destination index is second.
   
   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.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41637&comment_hash=a38f3fdaf8640a6e26b2e1c271304ec68dda30cbd75138352d62735d818992f6&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41637&comment_hash=a38f3fdaf8640a6e26b2e1c271304ec68dda30cbd75138352d62735d818992f6&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