fix(filter): should not filter out zero (#5106)

* fix(filter): should not filter out zero

* chore: make e2e test pass
This commit is contained in:
Zeke Zhang 2024-08-23 11:30:55 +08:00 committed by GitHub
parent eb550a9e19
commit b79087a3ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 2 deletions

View File

@ -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,

View File

@ -144,7 +144,7 @@ export const transformToFilter = (
key = `${key}.${collectionField.targetKey || 'id'}`;
}
if (!value) {
if (!value && value !== 0 && value !== false) {
return null;
}
@ -167,7 +167,7 @@ export const useAssociatedFields = () => {
};
export const isAssocField = (field?: FieldOptions) => {
return ['o2o', 'oho', 'obo', 'm2o', 'createdBy', 'updatedBy', 'o2m', 'm2m', 'linkTo', 'chinaRegion'].includes(
return ['o2o', 'oho', 'obo', 'm2o', 'createdBy', 'updatedBy', 'o2m', 'm2m', 'linkTo', 'chinaRegion', 'mbm'].includes(
field?.interface,
);
};

View File

@ -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);
});
});