Skip to content

Commit

Permalink
UIPQB-64 change boolean operator view from $and to AND in query string (
Browse files Browse the repository at this point in the history
  • Loading branch information
vashjs authored Nov 26, 2023
1 parent 63943b7 commit 20122c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/QueryBuilder/QueryBuilder/helpers/query.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { COLUMN_KEYS } from '../../../constants/columnKeys';
import { valueBuilder } from './valueBuilder';
import { BOOLEAN_OPERATORS, OPERATORS } from '../../../constants/operators';
import { BOOLEAN_OPERATORS, BOOLEAN_OPERATORS_MAP, OPERATORS } from '../../../constants/operators';
import { getOperatorOptions } from './selectOptions';

export const DEFAULT_PREVIEW_INTERVAL = 5000;

export const getQueryStr = (rows, fieldOptions) => {
return rows.reduce((str, row) => {
return rows.reduce((str, row, index) => {
const bool = row[COLUMN_KEYS.BOOLEAN].current;
const field = row[COLUMN_KEYS.FIELD].current;
const operator = row[COLUMN_KEYS.OPERATOR].current;
Expand All @@ -19,8 +19,9 @@ export const getQueryStr = (rows, fieldOptions) => {
return '';
}

if (bool) {
str += ` ${bool || ''} ${baseQuery}`;
// if there is a boolean operator and it's not the first row - add it to the query
if (bool && index > 0) {
str += ` ${BOOLEAN_OPERATORS_MAP[bool] || ''} ${baseQuery}`;
} else {
str += baseQuery;
}
Expand Down
4 changes: 4 additions & 0 deletions src/constants/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export const OPERATORS = {
export const BOOLEAN_OPERATORS = {
AND: '$and',
};

export const BOOLEAN_OPERATORS_MAP = {
[BOOLEAN_OPERATORS.AND]: 'AND',
};

0 comments on commit 20122c7

Please sign in to comment.