-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Filter value are conserved when possible #3198
Conversation
9348cfb
to
1b6d85c
Compare
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.
We need a couple of test cases since the filtering is a critical part.
packages/grid/_modules_/grid/components/panel/filterPanel/GridFilterForm.tsx
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/components/panel/filterPanel/GridFilterForm.tsx
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/components/panel/filterPanel/GridFilterForm.tsx
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/components/panel/filterPanel/GridFilterForm.tsx
Outdated
Show resolved
Hide resolved
771a3ee
to
765ad2a
Compare
765ad2a
to
e01ba2d
Compare
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.
It's working correctly. My only comments are to improve the tests. We could add a test case using singleSelect
since it does a bit of additional work to sanitize the options.
packages/grid/_modules_/grid/components/panel/filterPanel/GridFilterForm.tsx
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/components/panel/filterPanel/GridFilterForm.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
I had to remove the sanitization for |
packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
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.
Removing the sanitization created one regression:
I had to remove the sanitization for singleSelect because we have a test "should work if valueOptions is not provided". So if I make sanitization, it will be a kind of breaking change.
This is test is meant to ensure that the grid won't crash if the valueOptions
is undefined. Although, if it's defined and there's no corresponding value it can still be sanitized.
@@ -71,30 +139,36 @@ describe('<DataGrid /> - Filter', () => { | |||
operatorValue?: string; | |||
value?: any; | |||
field?: string; | |||
imperativeFilterModel?: boolean; |
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 can be removed.
@m4theushw Nice catch this regression :) I did not notice that the test was for the special case of |
// sanitize if valueOptions are provided | ||
itemValue = getValueFromValueOptions(item.value, currentValueOptions); | ||
if (itemValue !== item.value) { | ||
applyValue({ ...item, value: itemValue }); |
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.
Just a small detail. For a brief moment, filterValueState
will contain an invalid value if we don't return.
applyValue({ ...item, value: itemValue }); | |
applyValue({ ...item, value: itemValue }); | |
return; |
Fix #3188
The behavior
If column type changes, we try to keep the same operator (if available in the new column)
If the operator changes, we reset the filter Value if Input components are different.
Limitation
The singleSelect type is special because the input component is the same as the text input, but it behaves differently. That's why it has a specific case in column cahnge. Moreover, it implies to check if the value is available in the value options