You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2023/01/11 14:13:25 UTC

[GitHub] [superset] michael-s-molina commented on a diff in pull request #22084: feat: Select all for synchronous select

michael-s-molina commented on code in PR #22084:
URL: https://github.com/apache/superset/pull/22084#discussion_r1067039936


##########
superset-frontend/src/components/Select/Select.tsx:
##########
@@ -260,10 +294,110 @@ const Select = forwardRef(
       }
     }, [isLoading, loading]);
 
+    const selectAllMode = useMemo(
+      () => ensureIsArray(selectValue).length === fullSelectOptions.length + 1,
+      [selectValue, fullSelectOptions],
+    );
+
     useEffect(() => {
-      setSelectValue(value);
+      // if all values are selected, add select all to value
+      if (

Review Comment:
   Good point. This is indicative that the effect should be broken into two unrelated operations. Like this:
   
   ```
   useEffect(() => {
     setSelectValue(value);
   }, [value]);
   
   useEffect(() => {
     // if all values are selected, add select all to value
     if (
       !isSingleMode &&
       ensureIsArray(value).length === fullSelectOptions.length &&
       fullSelectOptions.length > 0
     ) {
       setSelectValue(
         labelInValue
           ? ([...ensureIsArray(value), selectAllOption] as AntdLabeledValue[])
           : ([
               ...ensureIsArray(value),
               SELECT_ALL_VALUE,
             ] as AntdLabeledValue[]),
       );
     }
   }, [value, isSingleMode, labelInValue, fullSelectOptions.length]);
   ```



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org