add is not operand on numeric fields (#16299)

closes https://github.com/twentyhq/twenty/issues/16162
This commit is contained in:
nitin
2025-12-04 18:55:24 +05:30
committed by GitHub
parent 2f36c2e82e
commit f0f648181e
8 changed files with 47 additions and 0 deletions
@@ -17,6 +17,7 @@ describe('getOperandsForFilterType', () => {
const numberOperands = [
RecordFilterOperand.IS,
RecordFilterOperand.IS_NOT,
RecordFilterOperand.GREATER_THAN_OR_EQUAL,
RecordFilterOperand.LESS_THAN_OR_EQUAL,
];
@@ -74,6 +74,7 @@ export const FILTER_OPERANDS_MAP = {
],
NUMBER: [
RecordFilterOperand.IS,
RecordFilterOperand.IS_NOT,
RecordFilterOperand.GREATER_THAN_OR_EQUAL,
RecordFilterOperand.LESS_THAN_OR_EQUAL,
...emptyOperands,
@@ -139,6 +139,11 @@ describe('buildValueFromFilter', () => {
value: '5',
expected: 5,
},
{
operand: ViewFilterOperand.IS_NOT,
value: '5',
expected: undefined,
},
{
operand: ViewFilterOperand.GREATER_THAN_OR_EQUAL,
value: '5',
@@ -159,6 +159,8 @@ const computeValueFromFilterNumber = (
return Number(value);
case ViewFilterOperand.IS:
return Number(value);
case ViewFilterOperand.IS_NOT:
return undefined;
case ViewFilterOperand.IS_EMPTY:
return undefined;
default:
@@ -28,6 +28,7 @@ export const FILTER_OPERANDS_MAP = {
],
NUMBER: [
ViewFilterOperand.IS,
ViewFilterOperand.IS_NOT,
ViewFilterOperand.GREATER_THAN_OR_EQUAL,
ViewFilterOperand.LESS_THAN_OR_EQUAL,
...emptyOperands,
@@ -64,6 +65,7 @@ export const FILTER_OPERANDS_MAP = {
UUID: [ViewFilterOperand.IS, ViewFilterOperand.IS_NOT],
NUMERIC: [
ViewFilterOperand.IS,
ViewFilterOperand.IS_NOT,
ViewFilterOperand.GREATER_THAN_OR_EQUAL,
ViewFilterOperand.LESS_THAN_OR_EQUAL,
...emptyOperands,
@@ -484,6 +484,31 @@ describe('evaluateFilterConditions', () => {
expect(evaluateFilterConditions({ filters: [filter2] })).toBe(false);
expect(evaluateFilterConditions({ filters: [filter3] })).toBe(false);
});
it('should handle IsNot operand correctly', () => {
const filter1 = createFilter(
ViewFilterOperand.IS_NOT,
25,
25,
'NUMBER',
);
const filter2 = createFilter(
ViewFilterOperand.IS_NOT,
20,
25,
'NUMBER',
);
const filter3 = createFilter(
ViewFilterOperand.IS_NOT,
30,
25,
'NUMBER',
);
expect(evaluateFilterConditions({ filters: [filter1] })).toBe(false);
expect(evaluateFilterConditions({ filters: [filter2] })).toBe(true);
expect(evaluateFilterConditions({ filters: [filter3] })).toBe(true);
});
});
describe('string and array operands', () => {
@@ -349,6 +349,9 @@ function evaluateNumberFilter(filter: ResolvedFilter): boolean {
case ViewFilterOperand.IS:
return Number(leftValue) === Number(rightValue);
case ViewFilterOperand.IS_NOT:
return Number(leftValue) !== Number(rightValue);
default:
throw new Error(
`Operand ${filter.operand} not supported for number filter`,
@@ -416,6 +416,14 @@ export const turnRecordFilterIntoRecordGqlOperationFilter = ({
eq: parseFloat(recordFilter.value),
} as FloatFilter,
};
case RecordFilterOperand.IS_NOT:
return {
not: {
[correspondingFieldMetadataItem.name]: {
eq: parseFloat(recordFilter.value),
} as FloatFilter,
},
};
default:
throw new Error(
`Unknown operand ${recordFilter.operand} for ${filterType} filter`,