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] Lower filter debounce delay #9712

Merged
merged 23 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -51,11 +51,6 @@ function GridFilterInputValue(props: GridTypeFilterInputValueProps) {
[applyValue, item, rootProps.filterDebounceMs, filterTimeout],
);

React.useEffect(() => {
const itemValue = item.value ?? '';
setFilterValueState(String(itemValue));
}, [item.value]);
Copy link
Member

Choose a reason for hiding this comment

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

I believe this effect was covering the use case with a controlled filter model, where the filter model could change while the user has the filter panel open.
Without this effect, the filter input will be out of sync with the actual filter model:

With effect: https://codesandbox.io/s/gracious-khayyam-2xqw3n?file=/demo.tsx
Without effect: https://codesandbox.io/s/dreamy-glitter-h8h4yj?file=/demo.tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've adapted the effect to respond to the model changes specifically, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll apply to the other equivalent components if it LGTY.

Copy link
Member

@MBilalShafi MBilalShafi Aug 10, 2023

Choose a reason for hiding this comment

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

The effect was also making sure the value is correctly synced with header filter (which is another rendered instance of GridFilterInputValue), removing it also impacted it too, as it's actually fromInput but it still needs to be synced 😄

Before:
before-hf

After:
after-hf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh good catch, there's so many parts to this thing ^^

I've pushed a fix for that.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, works as expected now!

Copy link
Member

Choose a reason for hiding this comment

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

@romgrk It had another aspect which I missed catching 😄
Since the rendering of GridFilterInputValue is being done from GridHeaderFilterCell, the item change is incorrectly reflected.
I am thinking of disabling this optimization (fromInput) for the headerFilters, let me know if you have better ideas.


return (
<rootProps.slots.baseTextField
id={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ const GridFilterPanel = React.forwardRef<HTMLDivElement, GridFilterPanelProps>(
...other
} = props;

const applyFilter = React.useCallback(
(item: GridFilterItem) => {
apiRef.current.upsertFilterItem(item);
},
[apiRef],
);
const applyFilter = apiRef.current.upsertFilterItem;

romgrk marked this conversation as resolved.
Show resolved Hide resolved
const applyFilterLogicOperator = React.useCallback(
(operator: GridLogicOperator) => {
Expand Down