ktmud commented on a change in pull request #18856:
URL: https://github.com/apache/superset/pull/18856#discussion_r821063926



##########
File path: superset-frontend/src/components/Select/utils.ts
##########
@@ -61,27 +60,25 @@ export function findValue<OptionType extends 
OptionTypeBase>(
   return (Array.isArray(value) ? value : [value]).map(find);
 }
 
-export function hasOption<VT extends string | number>(
-  value: VT,
-  options?: VT | VT[] | { value: VT } | { value: VT }[],
-) {
+export function getValue(option: string | number | { value: string | number }) 
{
+  return typeof option === 'object' ? option.value : option;
+}
+
+type LabeledValue<V> = { label?: ReactNode; value?: V };
+
+export function hasOption<V>(
+  value: V,
+  options?: V | LabeledValue<V> | (V | LabeledValue<V>)[],
+  checkLabel = false,
+): boolean {
   const optionsArray = ensureIsArray(options);
   return (
-    optionsArray.find(x =>
-      typeof x === 'object' ? x.value === value : x === value,
+    optionsArray.find(
+      x =>
+        x === value ||
+        (typeof x === 'object' &&
+          (('value' in x && x.value === value) ||
+            (checkLabel && 'label' in x && x.label === value))),

Review comment:
       See my comment in 
https://github.com/apache/superset/pull/18799#discussion_r818903790




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