villebro commented on a change in pull request #14710:
URL: https://github.com/apache/superset/pull/14710#discussion_r637890386



##########
File path: 
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx
##########
@@ -92,61 +176,46 @@ export default function PluginFilterSelect(props: 
PluginFilterSelectProps) {
   });
 
   const handleChange = (value?: SelectValue | number | string) => {
-    let selectValue: (number | string)[] = ensureIsArray<number | string>(
-      value,
-    );
-    let stateValue: SelectValue | typeof FIRST_VALUE = selectValue.length
-      ? selectValue
-      : null;
+    setValues(ensureIsArray(value));
+  };
 
-    if (value === FIRST_VALUE) {
-      selectValue = forceFirstValue ? [] : firstItem;
-      stateValue = FIRST_VALUE;
+  useEffect(() => {
+    if (isDisabled) {
+      setValues([]);
     }
+  }, [isDisabled]);
 
-    setValues(selectValue);
-
+  useEffect(() => {
     const emptyFilter =
-      enableEmptyFilter && !inverseSelection && selectValue?.length === 0;
+      enableEmptyFilter && !inverseSelection && values?.length === 0;
 
-    setDataMask({
+    dispatchDataMask({
+      type: 'filterState',
       extraFormData: getSelectExtraFormData(
         col,
-        selectValue,
+        values,
         emptyFilter,
         inverseSelection,
       ),
       filterState: {
         // We need to save in state `FIRST_VALUE` as some const and not as 
REAL value,
         // because when FiltersBar check if all filters initialized it 
compares `defaultValue` with this value
         // and because REAL value can be unpredictable for users that have 
different data for same dashboard we use `FIRST_VALUE`
-        value: stateValue,
+        value: values,
       },
     });
-  };
+  }, [col, enableEmptyFilter, inverseSelection, JSON.stringify(values)]);
 
   useEffect(() => {
-    // For currentValue we need set always `FIRST_VALUE` only if we in config 
modal for `defaultToFirstItem` mode
-    handleChange(forceFirstValue ? FIRST_VALUE : filterState.value ?? []);
-  }, [
-    JSON.stringify(filterState.value),
-    defaultToFirstItem,
-    multiSelect,
-    enableEmptyFilter,
-    inverseSelection,
-  ]);
+    // handle changes coming from application, e.g. "Clear all" button
+    if (JSON.stringify(values) !== JSON.stringify(filterState.value)) {
+      handleChange(filterState.value);
+    }
+  }, [JSON.stringify(filterState.value)]);

Review comment:
       This will be removed in a follow-up PR when all state handling is moved 
to the application




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

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