diff --git a/packages/core/client/src/filter-provider/__tests__/utiles.test.ts b/packages/core/client/src/filter-provider/__tests__/utiles.test.ts index 7da0fc2a42..1d6c886f9b 100644 --- a/packages/core/client/src/filter-provider/__tests__/utiles.test.ts +++ b/packages/core/client/src/filter-provider/__tests__/utiles.test.ts @@ -196,6 +196,32 @@ describe('transformToFilter', () => { expect(filter).toEqual(expectedFilter); }); + it('should keep 0 value', () => { + const valuesWithZero = { + field1: 0, + field2: 'value2', + }; + + const expectedFilter = { + $and: [ + { + field1: { + $eq: 0, + }, + }, + { + field2: { + $ne: 'value2', + }, + }, + ], + }; + + const filter = transformToFilter(valuesWithZero, operators, getCollectionJoinField, collectionName); + + expect(filter).toEqual(expectedFilter); + }); + it('should handle null values', () => { const valuesWithNull = { field1: null, diff --git a/packages/core/client/src/filter-provider/utils.ts b/packages/core/client/src/filter-provider/utils.ts index 212cc8c3a3..627635367c 100644 --- a/packages/core/client/src/filter-provider/utils.ts +++ b/packages/core/client/src/filter-provider/utils.ts @@ -144,7 +144,7 @@ export const transformToFilter = ( key = `${key}.${collectionField.targetKey || 'id'}`; } - if (!value) { + if (!value && value !== 0 && value !== false) { return null; } diff --git a/packages/core/client/src/schema-component/antd/filter/__tests__/useFilterActionProps.test.ts b/packages/core/client/src/schema-component/antd/filter/__tests__/useFilterActionProps.test.ts index 2880aeec5c..27a28cdbb0 100644 --- a/packages/core/client/src/schema-component/antd/filter/__tests__/useFilterActionProps.test.ts +++ b/packages/core/client/src/schema-component/antd/filter/__tests__/useFilterActionProps.test.ts @@ -65,4 +65,17 @@ describe('removeNullCondition', () => { const result = removeNullCondition(filter); expect(result).toEqual(expected); }); + + it('should keep 0 value', () => { + const filter = { + field1: 0, + field2: 'value2', + }; + const expected = { + field1: 0, + field2: 'value2', + }; + const result = removeNullCondition(filter); + expect(result).toEqual(expected); + }); });