Skip to content

Commit

Permalink
Fix filter with default value false is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto authored and ogustavo-pereira committed Nov 23, 2021
1 parent 179eef2 commit 4554832
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 4554832

Please sign in to comment.