add is operand on number field (#16022)
Co-authored-by: martmull <martmull@hotmail.fr>
This commit is contained in:
+1
@@ -16,6 +16,7 @@ describe('getOperandsForFilterType', () => {
|
||||
];
|
||||
|
||||
const numberOperands = [
|
||||
RecordFilterOperand.IS,
|
||||
RecordFilterOperand.GREATER_THAN_OR_EQUAL,
|
||||
RecordFilterOperand.LESS_THAN_OR_EQUAL,
|
||||
];
|
||||
|
||||
+1
@@ -73,6 +73,7 @@ export const FILTER_OPERANDS_MAP = {
|
||||
...emptyOperands,
|
||||
],
|
||||
NUMBER: [
|
||||
RecordFilterOperand.IS,
|
||||
RecordFilterOperand.GREATER_THAN_OR_EQUAL,
|
||||
RecordFilterOperand.LESS_THAN_OR_EQUAL,
|
||||
...emptyOperands,
|
||||
|
||||
+5
@@ -134,6 +134,11 @@ describe('buildValueFromFilter', () => {
|
||||
|
||||
describe('NUMBER field type', () => {
|
||||
const testCases = [
|
||||
{
|
||||
operand: ViewFilterOperand.IS,
|
||||
value: '5',
|
||||
expected: 5,
|
||||
},
|
||||
{
|
||||
operand: ViewFilterOperand.GREATER_THAN_OR_EQUAL,
|
||||
value: '5',
|
||||
|
||||
+2
@@ -157,6 +157,8 @@ const computeValueFromFilterNumber = (
|
||||
return Number(value) - 1;
|
||||
case ViewFilterOperand.IS_NOT_EMPTY:
|
||||
return Number(value);
|
||||
case ViewFilterOperand.IS:
|
||||
return Number(value);
|
||||
case ViewFilterOperand.IS_EMPTY:
|
||||
return undefined;
|
||||
default:
|
||||
|
||||
+2
@@ -27,6 +27,7 @@ export const FILTER_OPERANDS_MAP = {
|
||||
...emptyOperands,
|
||||
],
|
||||
NUMBER: [
|
||||
ViewFilterOperand.IS,
|
||||
ViewFilterOperand.GREATER_THAN_OR_EQUAL,
|
||||
ViewFilterOperand.LESS_THAN_OR_EQUAL,
|
||||
...emptyOperands,
|
||||
@@ -62,6 +63,7 @@ export const FILTER_OPERANDS_MAP = {
|
||||
BOOLEAN: [ViewFilterOperand.IS],
|
||||
UUID: [ViewFilterOperand.IS, ViewFilterOperand.IS_NOT],
|
||||
NUMERIC: [
|
||||
ViewFilterOperand.IS,
|
||||
ViewFilterOperand.GREATER_THAN_OR_EQUAL,
|
||||
ViewFilterOperand.LESS_THAN_OR_EQUAL,
|
||||
...emptyOperands,
|
||||
|
||||
+10
@@ -474,6 +474,16 @@ describe('evaluateFilterConditions', () => {
|
||||
expect(evaluateFilterConditions({ filters: [filter2] })).toBe(true);
|
||||
expect(evaluateFilterConditions({ filters: [filter3] })).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle Is operand correctly', () => {
|
||||
const filter1 = createFilter(ViewFilterOperand.IS, 25, 25, 'NUMBER');
|
||||
const filter2 = createFilter(ViewFilterOperand.IS, 20, 25, 'NUMBER');
|
||||
const filter3 = createFilter(ViewFilterOperand.IS, 30, 25, 'NUMBER');
|
||||
|
||||
expect(evaluateFilterConditions({ filters: [filter1] })).toBe(true);
|
||||
expect(evaluateFilterConditions({ filters: [filter2] })).toBe(false);
|
||||
expect(evaluateFilterConditions({ filters: [filter3] })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('string and array operands', () => {
|
||||
|
||||
+3
@@ -319,6 +319,9 @@ function evaluateNumberFilter(filter: ResolvedFilter): boolean {
|
||||
case ViewFilterOperand.IS_NOT_EMPTY:
|
||||
return isNonEmptyString(leftValue);
|
||||
|
||||
case ViewFilterOperand.IS:
|
||||
return Number(leftValue) === Number(rightValue);
|
||||
|
||||
default:
|
||||
throw new Error(
|
||||
`Operand ${filter.operand} not supported for number filter`,
|
||||
|
||||
Reference in New Issue
Block a user