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

Fix regression on filters using dot separator in source #4545

Merged
merged 6 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
52 changes: 52 additions & 0 deletions examples/simple/src/data.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/simple/src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const messages = {
tags: 'Tags',
title: 'Title',
views: 'Views',
country: 'Country',
authors: 'Authors',
},
},
Expand Down
1 change: 1 addition & 0 deletions examples/simple/src/i18n/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default {
tags: 'Catégories',
title: 'Titre',
views: 'Vues',
country: 'Pays',
authors: 'Auteurs',
},
},
Expand Down
9 changes: 9 additions & 0 deletions examples/simple/src/posts/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const PostFilter = props => (
source="title"
defaultValue="Qui tempore rerum et voluptates"
/>
<TextInput
label="resources.posts.fields.country"
source="informations.country"
defaultValue="France"
/>
<QuickFilter
label="resources.posts.fields.commentable"
source="commentable"
Expand Down Expand Up @@ -151,6 +156,10 @@ const PostList = props => {
label="resources.posts.fields.commentable_short"
sortable={false}
/>
<TextField
label="resources.posts.fields.country"
source="informations.country"
/>
<NumberField source="views" />
<ReferenceArrayField
label="Tags"
Expand Down
19 changes: 11 additions & 8 deletions packages/ra-core/src/controller/useListParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,21 @@ const useListParams = ({

const hideFilter = useCallback((filterName: string) => {
const newFilters = removeKey(filterValues, filterName);
const newDisplayedFilters = removeKey(
displayedFilterValues,
filterName
);
const newDisplayedFilters = {
...displayedFilterValues,
[filterName]: undefined,
};

setFilters(newFilters, newDisplayedFilters);
}, requestSignature); // eslint-disable-line react-hooks/exhaustive-deps

const showFilter = useCallback((filterName: string, defaultValue: any) => {
setFilters(
set(filterValues, filterName, defaultValue),
set(displayedFilterValues, filterName, true)
);
const newFilters = set(filterValues, filterName, defaultValue);
const newDisplayedFilters = {
...displayedFilterValues,
[filterName]: true,
};
setFilters(newFilters, newDisplayedFilters);
}, requestSignature); // eslint-disable-line react-hooks/exhaustive-deps

return [
Expand Down
3 changes: 3 additions & 0 deletions packages/ra-core/src/util/removeKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const deepRemoveKey = (target, path) => {
}

const deepKey = paths[0];
if (target[deepKey] === undefined) {
return target;
}
const deep = deepRemoveKey(target[deepKey], paths.slice(1).join('.'));

if (Object.keys(deep).length === 0) {
Expand Down