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 filter with default value false is not working #6338

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
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 @@ -100,6 +100,20 @@ describe('Query Reducer', () => {
});
});

it('should work with false default value', () => {
const updatedState = queryReducer(
{ filter: {}, displayedFilters: {} },
{
type: 'SHOW_FILTER',
payload: { filterName: 'foo', defaultValue: false },
}
);
expect(updatedState.filter).toEqual({ foo: false });
expect(updatedState.displayedFilters).toEqual({
foo: true,
});
});

it('should work without default value', () => {
const updatedState = queryReducer(
{
Expand Down
15 changes: 8 additions & 7 deletions packages/ra-core/src/reducer/admin/resource/list/queryReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ const queryReducer: Reducer<ListParams> = (
}
return {
...previousState,
filter: action.payload.defaultValue
? set(
previousState.filter,
action.payload.filterName,
action.payload.defaultValue
)
: previousState.filter,
filter:
typeof action.payload.defaultValue !== 'undefined'
? set(
previousState.filter,
action.payload.filterName,
action.payload.defaultValue
)
: previousState.filter,
// we don't use lodash.set() for displayed filters
// to avoid problems with compound filter names (e.g. 'author.name')
displayedFilters: {
Expand Down