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


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/DraggableFilter.tsx:
##########
@@ -57,111 +52,56 @@ const DragIcon = styled(Icons.Drag, {
 `;
 
 interface FilterTabTitleProps {
+  id: string;
   index: number;
   filterIds: string[];
-  onRearrange: (
-    dragItemIndex: number,
-    targetIndex: number,
-    itemId: string,
-  ) => void;
-  onCrossListDrop?: (
-    sourceId: string,
-    targetIndex: number,
-    sourceType: 'filter' | 'customization',
-  ) => void;
   dragType?: string;
-}
-
-interface DragItem {
-  index: number;
-  filterIds: string[];
-  type: string;
-  isDivider: boolean;
-  dragType: string;
+  children: ReactNode;
 }
 
 export const DraggableFilter: FC<FilterTabTitleProps> = ({
+  id,
   index,
-  onRearrange,
-  onCrossListDrop,
   filterIds,
   dragType = FILTER_TYPE,
   children,
 }) => {
-  const ref = useRef<HTMLDivElement>(null);
   const itemId = filterIds[0];
   const isDividerItem = isDivider(itemId);
 
-  const [{ isDragging }, drag] = useDrag({
-    item: {
+  const {
+    attributes,
+    listeners,
+    setNodeRef,
+    transform,
+    transition,
+    isDragging,
+  } = useSortable({
+    id,
+    data: {
       filterIds,
-      type: dragType,
       index,
       isDivider: isDividerItem,
       dragType,
     },
-    collect: (monitor: DragSourceMonitor) => ({
-      isDragging: monitor.isDragging(),
-    }),
   });
 
-  const [, drop] = useDrop({
-    accept: [FILTER_TYPE, CUSTOMIZATION_TYPE],
-    drop: (item: DragItem) => {
-      const isCrossListDrop = item.dragType !== dragType;
-
-      if (isCrossListDrop && item.isDivider && onCrossListDrop) {
-        const sourceType: 'filter' | 'customization' =
-          item.dragType === FILTER_TYPE ? 'filter' : 'customization';
-        onCrossListDrop(item.filterIds[0], index, sourceType);
-      }
-    },
-    hover: (item: DragItem, monitor: DropTargetMonitor) => {
-      if (!ref.current) {
-        return;
-      }
-
-      const dragIndex = item.index;
-      const hoverIndex = index;
+  const style: CSSProperties = {
+    transform: CSS.Transform.toString(transform),
+    transition: transition || undefined,
+  };
 
-      if (dragIndex === hoverIndex && item.dragType === dragType) {
-        return;
-      }
-
-      const hoverBoundingRect = ref.current?.getBoundingClientRect();
-      const hoverMiddleY =
-        (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
-      const clientOffset = monitor.getClientOffset();
-      const hoverClientY = (clientOffset as XYCoord).y - hoverBoundingRect.top;
-
-      const isCrossListDrop = item.dragType !== dragType;
-
-      if (isCrossListDrop) {
-        return;
-      }
-
-      if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {
-        return;
-      }
-      if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
-        return;
-      }
-
-      onRearrange(dragIndex, hoverIndex, item.filterIds[0]);
-      item.index = hoverIndex;
-    },
-  });
-  drag(drop(ref));
   return (
-    <Container ref={ref} isDragging={isDragging}>
-      <DragIcon
-        isDragging={isDragging}
-        alt={t('Move')}
-        className="dragIcon"
-        viewBox="4 4 16 16"
-      />
-      <div css={{ flex: 1 }}>{children}</div>
-    </Container>
+    <div ref={setNodeRef} style={style}>
+      <Container isDragging={isDragging} {...attributes} {...listeners}>
+        <DragIcon
+          isDragging={isDragging}
+          alt={t('Move icon')}

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Test selector breakage from i18n</b></div>
   <div id="fix">
   
   The alt text is now translated, which may cause test failures in 
FilterConfigPane.test.tsx where selectors expect the literal 'Move icon' 
string. Consider adding a stable data-testid to the DragIcon component and 
updating tests accordingly.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #8dcabb</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