wuqicyber commented on issue #33951:
URL: https://github.com/apache/superset/issues/33951#issuecomment-3043624518

   > I was able to analyze the drag & drop logic — turns out react-sortable-hoc 
isn’t responsible for it. It’s actually handled by react-dnd.
   > 
   > In OptionsWrapper.tsx, the function onShiftOptions is responsible for 
reordering dimensions. The issue is that it’s being called during onHover, 
which leads to repeated execution before the drop event — causing incorrect 
shuffling.
   > 
   > If we instead move this logic to the drop handler, it works as expected.
   > 
   > Here's the corrected code:
   > 
   > ```
   > 
   > drop: (item: OptionItemInterface) => {
   >   // Instead of repetitive calls on drag, 
   >   // we only execute the shift on drop
   >   const { dragIndex } = item;
   >   const hoverIndex = index;
   > 
   >   if (dragIndex === hoverIndex) return;
   >   onShiftOptions(dragIndex, hoverIndex);
   >   item.dragIndex = hoverIndex;
   > },
   > ```
   > 
   > This prevents premature reordering and executes onShiftOptions only once 
when the drop actually happens.
   > 
   > cc: [@msyavuz](https://github.com/msyavuz) 
[@rusackas](https://github.com/rusackas)
   Thanks for the explanation and the fix — I tried this approach, but it seems 
this only swaps the two items’ positions rather than moving the dragged item to 
the target position.
   
   Do you have any suggestions on how to properly shift the item to the desired 
index instead of just swapping?
   
   


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