-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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] Add is any of
filter operator
#2874
Conversation
Is their an issue that was asking for this feature ? If so, can you link it in the description of the PR ? |
4e3005b
to
3363e78
Compare
The idea is to add a field |
@@ -48,8 +48,9 @@ GridColumnsMenuItem.propTypes = { | |||
filterOperators: PropTypes.arrayOf( | |||
PropTypes.shape({ | |||
getApplyFilterFn: PropTypes.func.isRequired, | |||
InputComponent: PropTypes.elementType, | |||
InputComponent: PropTypes.func, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand Why InputComponent
is now considered as a function. Its type is made of the union of two JSXElements.
InputComponent?:
| React.JSXElementConstructor<GridFilterInputValueProps>
| React.JSXElementConstructor<
GridFilterInputMultipleValueProps &
Omit<AutocompleteProps<any[], true, false, true>, 'options' | 'renderInput'>
>;
(in gridFilterOperator.ts
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see any obvious problem in their code
Maybe you can link it locally and have a look if this is a problem in JSDoc (in which case I would not go fix it if I were you) or just a small bug in Typescript-to-Proptypes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is because the two JSX elements have different props and then are considered as different objects. So it provides the common property: they are both function
e655447
to
ddd7976
Compare
Because Do you have an opinion on the expected behavior? Should the filter be applied or not when the user is typing? |
I think it should not, for performances reason. |
in one of
filter operator
ddd7976
to
4c3a11a
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
in one of
filter operatoris one of
filter operator
For |
On the same idea, we will be able to add a "is between" for numbers |
4c3a11a
to
35d3a3f
Compare
35d3a3f
to
55418bf
Compare
To be consistent with the other |
@alexfauquette Then the alternative seems to be to map the values provided to the chips, so it's always an object instead of a value. |
@m4theushw I've been unclear in my previous message. The formating problem is solved. I was briefly describing how I change the state management such that Chip formatting works. So with the new commits, we have:
|
...ges/grid/_modules_/grid/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
Show resolved
Hide resolved
|
||
if (itemValue.length !== item.value.length) { | ||
// remove filtered values | ||
applyValue({ ...item, value: parsedCurrentValueOptions }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing an infinite loop. Maybe we're missing a test case covering the selection of items to filter with a click, not only changing props.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, tests were made only on the operator "is", so I added similar ones on "isAnyOf" to verify if the values are cleaned when changing the column.
I also refactorized how value is sanitized. The AutoComplete requires to have coherent values with options, so I sanitize the value with a useMemo. Such that the sanitization is performed before rendering the AutoComplete component.
If sanitization removes some elements, the DataGrid state is updated by a dedicated hook.
I spend too much time on this little piece of code. I'm taking a break on it, and I come back tomorrow to check on the deployment if it is working as expected, or if bugs are remaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played with filtering, no trivial bug was found this time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! 👌
...ges/grid/_modules_/grid/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
Outdated
Show resolved
Hide resolved
...ges/grid/_modules_/grid/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
Outdated
Show resolved
Hide resolved
const id = useId(); | ||
|
||
const currentColumn = item.columnField ? apiRef.current.getColumn(item.columnField) : null; | ||
const currentValueOptions = React.useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this name?
const currentValueOptions = React.useMemo(() => { | |
const resolvedValueOptions = React.useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it will be more logic, since data are resolved from the apiRef. I've done the modification for the following namings:
- resolvedColumn
- resolvedValueOptions
- resolvedFormattedValueOptions
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
I will wait for #3437 to adapt the documentation |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
#3437 is merged, we can fix the conflicts and merge this one |
These are the results for the performance tests:
|
Closes #2437
The idea is to add the "is one of" filtering condition.
For now, filtering has been imagined as containing a unique value. I'm modifying the pipeline to allow an array of values.
date(relevant?)datetime-local(relevant?)To test the
is any of
:https://deploy-preview-2874--material-ui-x.netlify.app/components/data-grid/filtering/#predefined-filters
The documentation about how to create custom filters operators with multiple values:
https://deploy-preview-2874--material-ui-x.netlify.app/components/data-grid/filtering/#multiple-values-operator