Skip to content

Commit 03be8ea

Browse files
authored
Merge pull request #7551 from marmelab/fix-date-parsed-in-filter
Fix parsed date/date-time filter resets component
2 parents 621ab03 + 6d26354 commit 03be8ea

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/ra-ui-materialui/src/list/filter/FilterForm.spec.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,13 @@ describe('<FilterForm />', () => {
152152
nestedToClear: { nestedValue: 'def' },
153153
classicUpdated: 'ghi',
154154
nestedUpdated: { nestedValue: 'jkl' },
155+
published_at: new Date('2022-01-01T03:00:00.000Z'),
156+
clearedDateValue: null,
155157
};
156158
const newFilterValues = {
157159
classicUpdated: 'ghi2',
158160
nestedUpdated: { nestedValue: 'jkl2' },
161+
published_at: '2022-01-01T03:00:00.000Z',
159162
};
160163

161164
expect(
@@ -165,6 +168,8 @@ describe('<FilterForm />', () => {
165168
nestedToClear: { nestedValue: '' },
166169
classicUpdated: 'ghi2',
167170
nestedUpdated: { nestedValue: 'jkl2' },
171+
published_at: '2022-01-01T03:00:00.000Z',
172+
clearedDateValue: '',
168173
});
169174
});
170175
});

packages/ra-ui-materialui/src/list/filter/FilterForm.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,15 @@ const getInputValue = (
237237
key: string,
238238
filterValues: Record<string, any>
239239
) => {
240+
if (formValues[key] === undefined || formValues[key] === null) {
241+
return '';
242+
}
240243
if (Array.isArray(formValues[key])) {
241244
return lodashGet(filterValues, key, '');
242245
}
246+
if (formValues[key] instanceof Date) {
247+
return lodashGet(filterValues, key, '');
248+
}
243249
if (typeof formValues[key] === 'object') {
244250
return Object.keys(formValues[key]).reduce((acc, innerKey) => {
245251
acc[innerKey] = getInputValue(

0 commit comments

Comments
 (0)