Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Fix values labels in is any of filter operator #11939

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,15 @@ function GridFilterInputMultipleSingleSelect(props: GridFilterInputMultipleSingl
if (!Array.isArray(item.value)) {
return [];
}
return item.value;
}, [item.value]);

return item.value.reduce<ValueOptions[]>((acc, value) => {
const resolvedValue = resolvedValueOptions.find((v) => getOptionValue(v) === value);
if (resolvedValue != null) {
acc.push(resolvedValue);
}
return acc;
}, [] as ValueOptions[]);
}, [getOptionValue, item.value, resolvedValueOptions]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do in one go?

diff --git a/packages/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx b/packages/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
index 517860549..1d274b335 100644
--- a/packages/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
+++ b/packages/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
@@ -79,11 +79,15 @@ function GridFilterInputMultipleSingleSelect(props: GridFilterInputMultipleSingl
       return [];
     }
 
-    return item.value
-      ?.map((value) =>
-        resolvedValueOptions?.find((resolvedValue) => getOptionValue(resolvedValue) === value),
-      )
-      .filter((value) => value !== undefined) as ValueOptions[];
+    return item.value.reduce<ValueOptions[]>((acc, value) => {
+      const resolvedValue = resolvedValueOptions.find(
+        (v) => getOptionValue(v) === value,
+      );
+      if (resolvedValue != null) {
+        acc.push(resolvedValue);
+      }
+      return acc;
+    }, [] as ValueOptions[]);
   }, [getOptionValue, item.value, resolvedValueOptions]);
 
   const handleChange = React.useCallback<

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The adjustment has been made @MBilalShafi, thanks for the review.


const handleChange = React.useCallback<
NonNullable<AutocompleteProps<ValueOptions, true, false, true>['onChange']>
Expand Down
Loading