mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 06:59:26 +08:00
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:
parent
eb550a9e19
commit
b79087a3ee
@ -196,6 +196,32 @@ describe('transformToFilter', () => {
|
|||||||
expect(filter).toEqual(expectedFilter);
|
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', () => {
|
it('should handle null values', () => {
|
||||||
const valuesWithNull = {
|
const valuesWithNull = {
|
||||||
field1: null,
|
field1: null,
|
||||||
|
@ -144,7 +144,7 @@ export const transformToFilter = (
|
|||||||
key = `${key}.${collectionField.targetKey || 'id'}`;
|
key = `${key}.${collectionField.targetKey || 'id'}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!value) {
|
if (!value && value !== 0 && value !== false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ export const useAssociatedFields = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const isAssocField = (field?: FieldOptions) => {
|
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,
|
field?.interface,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -65,4 +65,17 @@ describe('removeNullCondition', () => {
|
|||||||
const result = removeNullCondition(filter);
|
const result = removeNullCondition(filter);
|
||||||
expect(result).toEqual(expected);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user