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


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.tsx:
##########
@@ -460,19 +460,20 @@ function FiltersConfigModal({
     return titles;
   }, [filterIds, chartCustomizationIds, modalSaveLogic, formValuesVersion]);
 
-  const debouncedErrorHandling = useMemo(
+  const debouncedHandleErroredItems = useMemo(
     () =>
       debounce(() => {
         setSaveAlertVisible(false);
         modalSaveLogic.handleErroredItems();
+        setFormValuesVersion(prev => prev + 1);
       }, Constants.SLOW_DEBOUNCE),
-    [modalSaveLogic],
+    [modalSaveLogic, setSaveAlertVisible],
   );
 
-  const handleValuesChange = useCallback(() => {
-    setFormValuesVersion(prev => prev + 1);
-    debouncedErrorHandling();
-  }, [debouncedErrorHandling]);
+  const handleValuesChange = useMemo(
+    () => debouncedHandleErroredItems,
+    [debouncedHandleErroredItems],
+  );

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Debounced state update causes UI lag</b></div>
   <div id="fix">
   
   This refactoring delays the formValuesVersion increment by 500ms, causing 
itemTitles (used in sidebar) and the collapse component reset to lag behind 
form changes, leading to stale UI display.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
     const debouncedHandleErroredItems = useMemo(
       () =>
         debounce(() => {
           setSaveAlertVisible(false);
           modalSaveLogic.handleErroredItems();
         }, Constants.SLOW_DEBOUNCE),
       [modalSaveLogic, setSaveAlertVisible],
       [debouncedHandleErroredItems],
     );
    
     const handleValuesChange = useCallback(
       () => {
         setFormValuesVersion(prev => prev + 1);
         debouncedHandleErroredItems();
       }, [debouncedHandleErroredItems],
     );
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #8113c0</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



##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/ConfigModalSidebar/ConfigModalSidebar.tsx:
##########
@@ -101,12 +116,113 @@ const ConfigModalSidebar: FC<ConfigModalSidebarProps> = 
({
   onCollapseChange,
   onCrossListDrop,
   itemTitles,
+  formValuesVersion,
 }) => {
   const getTitle = useCallback(
     (id: string) => itemTitles?.[id] ?? getItemTitle(id),
     [itemTitles, getItemTitle],
   );
 
+  const [isDragging, setIsDragging] = useState(false);
+
+  const sensors = useSensors(
+    useSensor(PointerSensor, {
+      activationConstraint: { distance: 10 },
+    }),
+    useSensor(KeyboardSensor),
+  );
+
+  const handleDragStart = useCallback(() => {
+    setIsDragging(true);
+  }, []);
+
+  const handleDragEnd = useCallback(
+    (event: DragEndEvent) => {
+      setIsDragging(false);
+      const { active, over } = event;
+
+      if (!over || active.id === over.id) {
+        return;
+      }
+
+      const activeFilterIndex = filterOrderedIds.findIndex(
+        id => id === active.id,
+      );
+      const activeCustomizationIndex = customizationOrderedIds.findIndex(
+        id => id === active.id,
+      );
+      const overFilterIndex = filterOrderedIds.findIndex(id => id === over.id);
+      const overCustomizationIndex = customizationOrderedIds.findIndex(
+        id => id === over.id,
+      );
+

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Unsafe property access in drag handler</b></div>
   <div id="fix">
   
   Accessing active.data.current without checking if active.data exists could 
cause a runtime error if drag data is not set on the draggable item. Use 
optional chaining to safely access the nested property.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```
    -      );
    -      const activeData = active.data.current;
    -      if (
    -        activeFilterIndex === -1 &&
    -        activeCustomizationIndex === -1 &&
    +      );
    +      const activeData = active.data?.current;
    +      if (
    +        activeFilterIndex === -1 &&
    -        activeCustomizationIndex === -1 &&
    +        activeCustomizationIndex === -1 &&
   ```
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #8113c0</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