korbit-ai[bot] commented on code in PR #33834:
URL: https://github.com/apache/superset/pull/33834#discussion_r2157649425


##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx:
##########
@@ -256,25 +256,17 @@ const FilterBar: FC<FiltersBarProps> = ({
   }, [dataMaskSelected, dispatch]);
 
   const handleClearAll = useCallback(() => {
-    const clearDataMaskIds: string[] = [];
-    let dispatchAllowed = false;
     filtersInScope.filter(isNativeFilter).forEach(filter => {
       const { id } = filter;
       if (dataMaskSelected[id]) {
-        if (filter.controlValues?.enableEmptyFilter) {
-          dispatchAllowed = false;
-        }
-        clearDataMaskIds.push(id);
         setDataMaskSelected(draft => {
           if (draft[id].filterState?.value !== undefined) {
             draft[id].filterState!.value = undefined;
           }
+          draft[id].extraFormData = {};
         });
       }
     });
-    if (dispatchAllowed) {
-      clearDataMaskIds.forEach(id => dispatch(clearDataMask(id)));
-    }
   }, [dataMaskSelected, dispatch, filtersInScope, setDataMaskSelected]);

Review Comment:
   ### Function has multiple responsibilities <sub>![category 
Design](https://img.shields.io/badge/Design-0d9488)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The handleClearAll function performs multiple responsibilities: filtering, 
state updates, and data transformation. This violates the Single Responsibility 
Principle.
   
   
   ###### Why this matters
   Complex, multi-responsibility functions are harder to test, maintain, and 
modify. They also make it difficult to reuse individual pieces of functionality.
   
   ###### Suggested change ∙ *Feature Preview*
   Extract the clear logic into smaller, focused functions:
   ```typescript
   const clearFilterState = (draft: DataMaskStateWithId, id: string) => {
     if (draft[id].filterState?.value !== undefined) {
       draft[id].filterState!.value = undefined;
     }
     draft[id].extraFormData = {};
   };
   
   const handleClearAll = useCallback(() => {
     const filtersToReset = filtersInScope
       .filter(isNativeFilter)
       .filter(filter => dataMaskSelected[filter.id]);
       
     setDataMaskSelected(draft => {
       filtersToReset.forEach(filter => clearFilterState(draft, filter.id));
     });
   }, [dataMaskSelected, filtersInScope, setDataMaskSelected]);
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/93626098-2b7a-4074-826e-111455172fbe/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/93626098-2b7a-4074-826e-111455172fbe?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/93626098-2b7a-4074-826e-111455172fbe?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/93626098-2b7a-4074-826e-111455172fbe?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/93626098-2b7a-4074-826e-111455172fbe)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:084f5a21-3cee-4435-8801-895f9f14cf3d -->
   
   
   [](084f5a21-3cee-4435-8801-895f9f14cf3d)



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