mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-29 16:14:42 +00:00
feat(constants): introduce antlrQueryConstants for operators and key types
This commit is contained in:
parent
8f4778aa68
commit
af6c24d41d
@ -28,13 +28,13 @@ import {
|
||||
import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { QueryKeyDataSuggestionsProps } from 'types/api/querySuggestions/types';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
import { validateQuery } from 'utils/antlrQueryUtils';
|
||||
import {
|
||||
negationQueryOperatorSuggestions,
|
||||
QUERY_BUILDER_KEY_TYPES,
|
||||
QUERY_BUILDER_OPERATORS_BY_KEY_TYPE,
|
||||
queryOperatorSuggestions,
|
||||
validateQuery,
|
||||
} from 'utils/antlrQueryUtils';
|
||||
} from 'constants/antlrQueryConstants';
|
||||
import {
|
||||
getCurrentValueIndexAtCursor,
|
||||
getQueryContextAtCursor,
|
||||
|
||||
75
frontend/src/constants/antlrQueryConstants.ts
Normal file
75
frontend/src/constants/antlrQueryConstants.ts
Normal file
@ -0,0 +1,75 @@
|
||||
export const OPERATORS = {
|
||||
IN: 'IN',
|
||||
LIKE: 'LIKE',
|
||||
ILIKE: 'ILIKE',
|
||||
REGEXP: 'REGEXP',
|
||||
EXISTS: 'EXISTS',
|
||||
CONTAINS: 'CONTAINS',
|
||||
BETWEEN: 'BETWEEN',
|
||||
NOT: 'NOT',
|
||||
'=': '=',
|
||||
'!=': '!=',
|
||||
'>=': '>=',
|
||||
'>': '>',
|
||||
'<=': '<=',
|
||||
'<': '<',
|
||||
};
|
||||
|
||||
export enum QUERY_BUILDER_KEY_TYPES {
|
||||
STRING = 'string',
|
||||
NUMBER = 'number',
|
||||
BOOLEAN = 'boolean',
|
||||
}
|
||||
|
||||
export const QUERY_BUILDER_OPERATORS_BY_KEY_TYPE = {
|
||||
[QUERY_BUILDER_KEY_TYPES.STRING]: [
|
||||
OPERATORS['='],
|
||||
OPERATORS['!='],
|
||||
OPERATORS.IN,
|
||||
OPERATORS.LIKE,
|
||||
OPERATORS.ILIKE,
|
||||
OPERATORS.CONTAINS,
|
||||
OPERATORS.EXISTS,
|
||||
OPERATORS.REGEXP,
|
||||
OPERATORS.NOT,
|
||||
],
|
||||
[QUERY_BUILDER_KEY_TYPES.NUMBER]: [
|
||||
OPERATORS['='],
|
||||
OPERATORS['!='],
|
||||
OPERATORS['>='],
|
||||
OPERATORS['>'],
|
||||
OPERATORS['<='],
|
||||
OPERATORS['<'],
|
||||
OPERATORS.IN,
|
||||
OPERATORS.EXISTS,
|
||||
OPERATORS.BETWEEN,
|
||||
OPERATORS.NOT,
|
||||
],
|
||||
[QUERY_BUILDER_KEY_TYPES.BOOLEAN]: [
|
||||
OPERATORS['='],
|
||||
OPERATORS['!='],
|
||||
OPERATORS.EXISTS,
|
||||
OPERATORS.NOT,
|
||||
],
|
||||
};
|
||||
|
||||
export const negationQueryOperatorSuggestions = [
|
||||
{ label: OPERATORS['LIKE'], type: 'operator', info: 'Like' },
|
||||
{ label: OPERATORS['ILIKE'], type: 'operator', info: 'Case insensitive like' },
|
||||
{ label: OPERATORS['EXISTS'], type: 'operator', info: 'Exists' },
|
||||
{ label: OPERATORS['BETWEEN'], type: 'operator', info: 'Between' },
|
||||
{ label: OPERATORS['IN'], type: 'operator', info: 'In' },
|
||||
{ label: OPERATORS['REGEXP'], type: 'operator', info: 'Regular expression' },
|
||||
{ label: OPERATORS['CONTAINS'], type: 'operator', info: 'Contains' },
|
||||
];
|
||||
|
||||
export const queryOperatorSuggestions = [
|
||||
{ label: OPERATORS['='], type: 'operator', info: 'Equal to' },
|
||||
{ label: OPERATORS['!='], type: 'operator', info: 'Not equal to' },
|
||||
{ label: OPERATORS['>'], type: 'operator', info: 'Greater than' },
|
||||
{ label: OPERATORS['<'], type: 'operator', info: 'Less than' },
|
||||
{ label: OPERATORS['>='], type: 'operator', info: 'Greater than or equal to' },
|
||||
{ label: OPERATORS['<='], type: 'operator', info: 'Less than or equal to' },
|
||||
{ label: OPERATORS['NOT'], type: 'operator', info: 'Not' },
|
||||
...negationQueryOperatorSuggestions,
|
||||
];
|
||||
@ -1,4 +1,4 @@
|
||||
import { QUERY_BUILDER_KEY_TYPES } from 'utils/antlrQueryUtils';
|
||||
import { QUERY_BUILDER_KEY_TYPES } from 'constants/antlrQueryConstants';
|
||||
|
||||
export interface QueryKeyDataSuggestionsProps {
|
||||
label: string;
|
||||
|
||||
@ -893,79 +893,3 @@ export function getQueryContextAtCursor(
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const OPERATORS = {
|
||||
IN: 'IN',
|
||||
LIKE: 'LIKE',
|
||||
ILIKE: 'ILIKE',
|
||||
REGEXP: 'REGEXP',
|
||||
EXISTS: 'EXISTS',
|
||||
CONTAINS: 'CONTAINS',
|
||||
BETWEEN: 'BETWEEN',
|
||||
NOT: 'NOT',
|
||||
'=': '=',
|
||||
'!=': '!=',
|
||||
'>=': '>=',
|
||||
'>': '>',
|
||||
'<=': '<=',
|
||||
'<': '<',
|
||||
};
|
||||
|
||||
export enum QUERY_BUILDER_KEY_TYPES {
|
||||
STRING = 'string',
|
||||
NUMBER = 'number',
|
||||
BOOLEAN = 'boolean',
|
||||
}
|
||||
|
||||
export const QUERY_BUILDER_OPERATORS_BY_KEY_TYPE = {
|
||||
[QUERY_BUILDER_KEY_TYPES.STRING]: [
|
||||
OPERATORS['='],
|
||||
OPERATORS['!='],
|
||||
OPERATORS.IN,
|
||||
OPERATORS.LIKE,
|
||||
OPERATORS.ILIKE,
|
||||
OPERATORS.CONTAINS,
|
||||
OPERATORS.EXISTS,
|
||||
OPERATORS.REGEXP,
|
||||
OPERATORS.NOT,
|
||||
],
|
||||
[QUERY_BUILDER_KEY_TYPES.NUMBER]: [
|
||||
OPERATORS['='],
|
||||
OPERATORS['!='],
|
||||
OPERATORS['>='],
|
||||
OPERATORS['>'],
|
||||
OPERATORS['<='],
|
||||
OPERATORS['<'],
|
||||
OPERATORS.IN,
|
||||
OPERATORS.EXISTS,
|
||||
OPERATORS.BETWEEN,
|
||||
OPERATORS.NOT,
|
||||
],
|
||||
[QUERY_BUILDER_KEY_TYPES.BOOLEAN]: [
|
||||
OPERATORS['='],
|
||||
OPERATORS['!='],
|
||||
OPERATORS.EXISTS,
|
||||
OPERATORS.NOT,
|
||||
],
|
||||
};
|
||||
|
||||
export const negationQueryOperatorSuggestions = [
|
||||
{ label: OPERATORS['LIKE'], type: 'operator', info: 'Like' },
|
||||
{ label: OPERATORS['ILIKE'], type: 'operator', info: 'Case insensitive like' },
|
||||
{ label: OPERATORS['EXISTS'], type: 'operator', info: 'Exists' },
|
||||
{ label: OPERATORS['BETWEEN'], type: 'operator', info: 'Between' },
|
||||
{ label: OPERATORS['IN'], type: 'operator', info: 'In' },
|
||||
{ label: OPERATORS['REGEXP'], type: 'operator', info: 'Regular expression' },
|
||||
{ label: OPERATORS['CONTAINS'], type: 'operator', info: 'Contains' },
|
||||
];
|
||||
|
||||
export const queryOperatorSuggestions = [
|
||||
{ label: OPERATORS['='], type: 'operator', info: 'Equal to' },
|
||||
{ label: OPERATORS['!='], type: 'operator', info: 'Not equal to' },
|
||||
{ label: OPERATORS['>'], type: 'operator', info: 'Greater than' },
|
||||
{ label: OPERATORS['<'], type: 'operator', info: 'Less than' },
|
||||
{ label: OPERATORS['>='], type: 'operator', info: 'Greater than or equal to' },
|
||||
{ label: OPERATORS['<='], type: 'operator', info: 'Less than or equal to' },
|
||||
{ label: OPERATORS['NOT'], type: 'operator', info: 'Not' },
|
||||
...negationQueryOperatorSuggestions,
|
||||
];
|
||||
|
||||
@ -16,7 +16,7 @@ import {
|
||||
isValueToken,
|
||||
isWrappedUnderQuotes,
|
||||
} from './tokenUtils';
|
||||
import { OPERATORS } from './antlrQueryUtils';
|
||||
import { OPERATORS } from 'constants/antlrQueryConstants';
|
||||
|
||||
// Function to normalize multiple spaces to single spaces when not in quotes
|
||||
function normalizeSpaces(query: string): string {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import FilterQueryLexer from 'parser/FilterQueryLexer';
|
||||
import { IQueryPair } from 'types/antlrQueryTypes';
|
||||
import { OPERATORS } from 'utils/antlrQueryUtils';
|
||||
import { OPERATORS } from 'constants/antlrQueryConstants';
|
||||
|
||||
export function isKeyToken(tokenType: number): boolean {
|
||||
return tokenType === FilterQueryLexer.KEY;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user