fix(editor): Correctly set condition operator when changed (#8700)

This commit is contained in:
Elias Meire 2024-02-21 14:53:42 +01:00 committed by GitHub
parent 35245694b1
commit 23a1bc40a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 9 deletions

View file

@ -12,16 +12,15 @@ describe('FilterConditions > utils', () => {
expect( expect(
handleOperatorChange({ handleOperatorChange({
condition, condition,
newOperator: getFilterOperator('number:equals'), newOperator: getFilterOperator('number:gt'),
}), }),
).toEqual({ ).toEqual({
id: '1', id: '1',
leftValue: 45, leftValue: 45,
rightValue: 'notANumber', rightValue: 'notANumber',
operator: { operator: {
name: 'filter.operator.equals', operation: 'gt',
operation: 'equals', type: 'number',
type: 'string',
}, },
}); });
}); });
@ -36,16 +35,15 @@ describe('FilterConditions > utils', () => {
expect( expect(
handleOperatorChange({ handleOperatorChange({
condition, condition,
newOperator: getFilterOperator('boolean:equals'), newOperator: getFilterOperator('boolean:notEquals'),
}), }),
).toEqual({ ).toEqual({
id: '1', id: '1',
leftValue: false, leftValue: false,
rightValue: true, rightValue: true,
operator: { operator: {
name: 'filter.operator.equals', operation: 'notEquals',
operation: 'equals', type: 'boolean',
type: 'string',
}, },
}); });
}); });
@ -62,7 +60,15 @@ describe('FilterConditions > utils', () => {
condition, condition,
newOperator: getFilterOperator('boolean:equals'), newOperator: getFilterOperator('boolean:equals'),
}), }),
).toEqual(condition); ).toEqual({
id: '1',
leftValue: '={{ $json.foo }}',
rightValue: '={{ $("nodename").foo }}',
operator: {
operation: 'equals',
type: 'boolean',
},
});
}); });
}); });
}); });

View file

@ -46,6 +46,13 @@ export const handleOperatorChange = ({
condition.rightValue = convertToType(condition.rightValue, newRightType); condition.rightValue = convertToType(condition.rightValue, newRightType);
} }
condition.operator = {
type: newOperator.type,
operation: newOperator.operation,
rightType: newOperator.rightType,
singleValue: newOperator.singleValue,
};
return condition; return condition;
}; };