Skip to content

Commit a68a2af

Browse files
authoredJun 8, 2021
Merge pull request #6338 from marmelab/fix-default-filter-value-false
Fix filter with default value false is not working
2 parents 14de16c + ddc2674 commit a68a2af

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed
 

‎packages/ra-core/src/reducer/admin/resource/list/queryReducer.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ describe('Query Reducer', () => {
100100
});
101101
});
102102

103+
it('should work with false default value', () => {
104+
const updatedState = queryReducer(
105+
{ filter: {}, displayedFilters: {} },
106+
{
107+
type: 'SHOW_FILTER',
108+
payload: { filterName: 'foo', defaultValue: false },
109+
}
110+
);
111+
expect(updatedState.filter).toEqual({ foo: false });
112+
expect(updatedState.displayedFilters).toEqual({
113+
foo: true,
114+
});
115+
});
116+
103117
it('should work without default value', () => {
104118
const updatedState = queryReducer(
105119
{

‎packages/ra-core/src/reducer/admin/resource/list/queryReducer.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ const queryReducer: Reducer<ListParams> = (
9999
}
100100
return {
101101
...previousState,
102-
filter: action.payload.defaultValue
103-
? set(
104-
previousState.filter,
105-
action.payload.filterName,
106-
action.payload.defaultValue
107-
)
108-
: previousState.filter,
102+
filter:
103+
typeof action.payload.defaultValue !== 'undefined'
104+
? set(
105+
previousState.filter,
106+
action.payload.filterName,
107+
action.payload.defaultValue
108+
)
109+
: previousState.filter,
109110
// we don't use lodash.set() for displayed filters
110111
// to avoid problems with compound filter names (e.g. 'author.name')
111112
displayedFilters: {

0 commit comments

Comments
 (0)