justinpark commented on code in PR #24388:
URL: https://github.com/apache/superset/pull/24388#discussion_r1231323786


##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx:
##########
@@ -239,16 +236,23 @@ export default function PluginFilterSelect(props: 
PluginFilterSelectProps) {
   const options = useMemo(() => {
     const allOptions = [...data];
     const uniqueOptions = uniqWith(allOptions, isEqual);
-    const selectOptions: { label: string; value: DataRecordValue }[] = [];
+    const selectOptions: SelectOptionsType = [];
     uniqueOptions.forEach(row => {
       const [value] = groupby.map(col => row[col]);
       selectOptions.push({
         label: labelFormatter(value, datatype),
         value,
       });
     });
+    if (search && !multiSelect && !hasOption(search, selectOptions, true)) {
+      selectOptions.unshift({
+        label: search,
+        value: search,
+        isNewOption: true,
+      });
+    }

Review Comment:
   I personally prefer to have a separate useMemo block for this part since the 
operation cost of `uniqueOptions` can be high (i.e. airbnb case has > 10k) so 
processing `uniqWith` and `uniqueOptions.forEach` when search value only 
updated can be inefficient.
   
   ```suggestion
     const uniqueSelectedOptions = useMemo(() => {
     ...
       return selectOptions;
     });
     const options = useMemo(() => {
       if (search && !multiSelect && !hasOption(search, uniqueSelectedOptions, 
true)) {
         uniqueSelectedOptions.unshift({
           label: search,
           value: search,
           isNewOption: true,
         });
       }
     return uniqueSelectedOptions;
   }, [uniqueSelectedOptions, multiSelect, search]);
   ```



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