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

feat: lowercase operators support in the where clause is updated #3657

Merged
merged 12 commits into from
Oct 6, 2023
12 changes: 12 additions & 0 deletions frontend/src/constants/queryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,35 @@ export const QUERY_BUILDER_SEARCH_VALUES = {

export const OPERATORS = {
IN: 'IN',
in: 'in',
NIN: 'NOT_IN',
not_in: 'not_in',
LIKE: 'LIKE',
like: 'like',
NLIKE: 'NOT_LIKE',
not_like: 'not_like',
REGEX: 'REGEX',
regex: 'regex',
NREGEX: 'NOT_REGEX',
nregex: 'not_regex',
'=': '=',
'!=': '!=',
EXISTS: 'EXISTS',
exists: 'exists',
NOT_EXISTS: 'NOT_EXISTS',
not_exists: 'not_exists',
CONTAINS: 'CONTAINS',
contains: 'contains',
NOT_CONTAINS: 'NOT_CONTAINS',
not_contains: 'not_contains',
'>=': '>=',
'>': '>',
'<=': '<=',
'<': '<',
HAS: 'HAS',
has: 'has',
NHAS: 'NHAS',
nhas: 'nhas',
};

export const QUERY_BUILDER_OPERATORS_BY_TYPES = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { parse } from 'papaparse';
import { orderByValueDelimiter } from '../OrderByFilter/utils';

// eslint-disable-next-line no-useless-escape
export const tagRegexp = /^\s*(.*?)\s*(IN|NOT_IN|LIKE|NOT_LIKE|REGEX|NOT_REGEX|=|!=|EXISTS|NOT_EXISTS|CONTAINS|NOT_CONTAINS|>=|>|<=|<|HAS|NHAS)\s*(.*)$/g;
export const tagRegexp = /^\s*(.*?)\s*(IN|in|NOT_IN|not_in|LIKE|like|NOT_LIKE|not_like|REGEX|regex|NOT_REGEX|not_regex|=|!=|EXISTS|exists|NOT_EXISTS|not_exists|CONTAINS|contains|NOT_CONTAINS|not_contains|>=|>|<=|<|HAS|has|NHAS|nhas)\s*(.*)$/g;

export function isInNInOperator(value: string): boolean {
return value === OPERATORS.IN || value === OPERATORS.NIN;
Expand All @@ -22,6 +22,7 @@ export function getTagToken(tag: string): ITagToken {

if (match) {
const [, matchTagKey, matchTagOperator, matchTagValue] = match;

return {
tagKey: matchTagKey,
tagOperator: matchTagOperator,
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/hooks/queryBuilder/useOperatorType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,35 @@ export type OperatorType =

const operatorTypeMapper: Record<string, OperatorType> = {
[OPERATORS.IN]: 'MULTIPLY_VALUE',
[OPERATORS.in]: 'MULTIPLY_VALUE',
[OPERATORS.NIN]: 'MULTIPLY_VALUE',
[OPERATORS.not_in]: 'MULTIPLY_VALUE',
[OPERATORS.EXISTS]: 'NON_VALUE',
[OPERATORS.exists]: 'NON_VALUE',
[OPERATORS.NOT_EXISTS]: 'NON_VALUE',
[OPERATORS.not_exists]: 'NON_VALUE',
[OPERATORS['<=']]: 'SINGLE_VALUE',
[OPERATORS['<']]: 'SINGLE_VALUE',
[OPERATORS['>=']]: 'SINGLE_VALUE',
[OPERATORS['>']]: 'SINGLE_VALUE',
[OPERATORS.LIKE]: 'SINGLE_VALUE',
[OPERATORS.like]: 'SINGLE_VALUE',
[OPERATORS.NLIKE]: 'SINGLE_VALUE',
[OPERATORS.not_like]: 'SINGLE_VALUE',
[OPERATORS.REGEX]: 'SINGLE_VALUE',
[OPERATORS.regex]: 'SINGLE_VALUE',
[OPERATORS.NREGEX]: 'SINGLE_VALUE',
[OPERATORS.nregex]: 'SINGLE_VALUE',
[OPERATORS.CONTAINS]: 'SINGLE_VALUE',
[OPERATORS.contains]: 'SINGLE_VALUE',
[OPERATORS.NOT_CONTAINS]: 'SINGLE_VALUE',
[OPERATORS.not_contains]: 'SINGLE_VALUE',
[OPERATORS['=']]: 'SINGLE_VALUE',
[OPERATORS['!=']]: 'SINGLE_VALUE',
[OPERATORS.HAS]: 'SINGLE_VALUE',
[OPERATORS.has]: 'SINGLE_VALUE',
[OPERATORS.NHAS]: 'SINGLE_VALUE',
[OPERATORS.nhas]: 'SINGLE_VALUE',
};

export const useOperatorType = (operator: string): OperatorType =>
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/hooks/queryBuilder/useOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ export const useOptions = (
if (isMulti) {
return {
...option,
selected: tagValue
.filter((i) => i.trim().replace(/^\s+/, '') === option.value)
.includes(option.value),
selected: Array.isArray(tagValue)
? tagValue
?.filter((i) => i.trim().replace(/^\s+/, '') === option.value)
?.includes(option.value)
: String(tagValue).includes(option.value),
};
}
return option;
Expand Down