diff --git a/CHANGELOG.md b/CHANGELOG.md index cd8ec2a3..fe9ffb34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * [UIPQB-66](https://issues.folio.org/browse/UIPQB-66) Localize dates in results view. * [UIPQB-54](https://issues.folio.org/browse/UIPQB-54) Add support for array fields in query results. * [UIPQB-70](https://issues.folio.org/browse/UIPQB-70) Array fields support verification. +* [UIPQB-80](https://issues.folio.org/browse/UIPQB-80) Add operators for NumberType and adjust operators for IntegerType. ## [1.0.0](https://github.com/folio-org/ui-plugin-query-builder/tree/v1.0.0) (2023-10-12) diff --git a/src/QueryBuilder/QueryBuilder/helpers/selectOptions.js b/src/QueryBuilder/QueryBuilder/helpers/selectOptions.js index d17d5868..504fd5af 100644 --- a/src/QueryBuilder/QueryBuilder/helpers/selectOptions.js +++ b/src/QueryBuilder/QueryBuilder/helpers/selectOptions.js @@ -79,8 +79,12 @@ export const getOperatorOptions = ({ case DATA_TYPES.OpenUUIDType: return getOperatorsWithPlaceholder(UUIDOperators(), intl); + case DATA_TYPES.IntegerType: - return getOperatorsWithPlaceholder(baseLogicalOperators(), intl); + return getOperatorsWithPlaceholder(extendedLogicalOperators(), intl); + + case DATA_TYPES.NumberType: + return getOperatorsWithPlaceholder(extendedLogicalOperators(), intl); case DATA_TYPES.ArrayType: return getOperatorsWithPlaceholder(ArrayOperators(), intl); diff --git a/src/QueryBuilder/QueryBuilder/helpers/selectOptions.test.js b/src/QueryBuilder/QueryBuilder/helpers/selectOptions.test.js index 5969769a..484f8442 100644 --- a/src/QueryBuilder/QueryBuilder/helpers/selectOptions.test.js +++ b/src/QueryBuilder/QueryBuilder/helpers/selectOptions.test.js @@ -115,7 +115,7 @@ describe('select options', () => { }); }); - it('should return base logical operators with placeholder for integer type', () => { + it('should return extended logical operators with placeholder for integer type', () => { const options = getOperatorOptions({ dataType: DATA_TYPES.IntegerType, hasSourceOrValues: false, @@ -129,6 +129,28 @@ describe('select options', () => { { label: OPERATORS.NOT_EQUAL, value: OPERATORS.NOT_EQUAL }, { label: OPERATORS.GREATER_THAN, value: OPERATORS.GREATER_THAN }, { label: OPERATORS.LESS_THAN, value: OPERATORS.LESS_THAN }, + { label: OPERATORS.GREATER_THAN_OR_EQUAL, value: OPERATORS.GREATER_THAN_OR_EQUAL }, + { label: OPERATORS.LESS_THAN_OR_EQUAL, value: OPERATORS.LESS_THAN_OR_EQUAL }, + ], + }); + }); + + it('should return extended logical operators with placeholder for number type', () => { + const options = getOperatorOptions({ + dataType: DATA_TYPES.NumberType, + hasSourceOrValues: false, + intl: intlMock, + }); + + expectFn({ + options, + operators: [ + { label: OPERATORS.EQUAL, value: OPERATORS.EQUAL }, + { label: OPERATORS.NOT_EQUAL, value: OPERATORS.NOT_EQUAL }, + { label: OPERATORS.GREATER_THAN, value: OPERATORS.GREATER_THAN }, + { label: OPERATORS.LESS_THAN, value: OPERATORS.LESS_THAN }, + { label: OPERATORS.GREATER_THAN_OR_EQUAL, value: OPERATORS.GREATER_THAN_OR_EQUAL }, + { label: OPERATORS.LESS_THAN_OR_EQUAL, value: OPERATORS.LESS_THAN_OR_EQUAL }, ], }); }); diff --git a/src/QueryBuilder/QueryBuilder/helpers/valueBuilder.js b/src/QueryBuilder/QueryBuilder/helpers/valueBuilder.js index 43137635..70af8af4 100644 --- a/src/QueryBuilder/QueryBuilder/helpers/valueBuilder.js +++ b/src/QueryBuilder/QueryBuilder/helpers/valueBuilder.js @@ -27,6 +27,8 @@ export const valueBuilder = ({ value, field, operator, fieldOptions }) => { [DATA_TYPES.IntegerType]: () => (isArray ? getCommaSeparatedStr(value) : value), + [DATA_TYPES.NumberType]: () => (isArray ? getCommaSeparatedStr(value) : value), + [DATA_TYPES.RangedUUIDType]: () => getQuotedStr(value), [DATA_TYPES.ArrayType]: () => (isArray ? getCommaSeparatedStr(value) : getQuotedStr(value)), diff --git a/src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js b/src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js index 1d1ea989..9894cb51 100644 --- a/src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js +++ b/src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js @@ -21,6 +21,14 @@ describe('valueBuilder', () => { expect(valueBuilder({ value, field, operator, fieldOptions })).toBe(value); }); + test('should return the same value for NumberType', () => { + const value = 42.1; + const field = 'decimal_position'; + const operator = OPERATORS.EQUAL; + + expect(valueBuilder({ value, field, operator, fieldOptions })).toBe(value); + }); + test('should return a string enclosed in double quotes for BooleanType', () => { const value = true; const field = 'user_active'; diff --git a/test/jest/data/entityType.js b/test/jest/data/entityType.js index 44f2f362..157543f4 100644 --- a/test/jest/data/entityType.js +++ b/test/jest/data/entityType.js @@ -283,6 +283,14 @@ export const entityType = { 'labelAlias': 'Position', 'visibleByDefault': true, }, + { + 'name': 'decimal_position', + 'dataType': { + 'dataType': 'numberType', + }, + 'labelAlias': 'Decimal position', + 'visibleByDefault': true, + }, { 'name': 'item_material_type', 'dataType': {