Skip to content

Commit

Permalink
Merge pull request #6338 from marmelab/fix-default-filter-value-false
Browse files Browse the repository at this point in the history
Fix filter with default value false is not working
  • Loading branch information
djhi authored Jun 8, 2021
2 parents 14de16c + ddc2674 commit a68a2af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
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

0 comments on commit a68a2af

Please sign in to comment.