Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIPQB-80: Add operators for NumberType and adjust operators for IntegerType #82

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion src/QueryBuilder/QueryBuilder/helpers/selectOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 23 additions & 1 deletion src/QueryBuilder/QueryBuilder/helpers/selectOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 },
],
});
});
Expand Down
2 changes: 2 additions & 0 deletions src/QueryBuilder/QueryBuilder/helpers/valueBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
8 changes: 8 additions & 0 deletions src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
expect(valueBuilder({ value, field, operator, fieldOptions })).toBe(value);
});

test('should return the same value for NumberType', () => {
const value = 42.1;

Check failure on line 25 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 4 spaces but found 6

Check failure on line 25 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 4 spaces but found 6
const field = 'decimal_position';

Check failure on line 26 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 4 spaces but found 6

Check failure on line 26 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 4 spaces but found 6
const operator = OPERATORS.EQUAL;

Check failure on line 27 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 4 spaces but found 6

Check failure on line 27 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 4 spaces but found 6

expect(valueBuilder({ value, field, operator, fieldOptions })).toBe(value);

Check failure on line 29 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 4 spaces but found 6

Check failure on line 29 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 4 spaces but found 6
});

Check failure on line 30 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 2 spaces but found 4

Check failure on line 30 in src/QueryBuilder/QueryBuilder/helpers/valueBuilder.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 2 spaces but found 4

test('should return a string enclosed in double quotes for BooleanType', () => {
const value = true;
const field = 'user_active';
Expand Down
8 changes: 8 additions & 0 deletions test/jest/data/entityType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
Loading