diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx index f0a7171719de..76018fa43eaa 100644 --- a/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx +++ b/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx @@ -12,11 +12,7 @@ import { import { javascript } from '@codemirror/lang-javascript'; import { Color } from '@signozhq/design-tokens'; import { copilot } from '@uiw/codemirror-theme-copilot'; -import CodeMirror, { - EditorView, - keymap, - Extension, -} from '@uiw/react-codemirror'; +import CodeMirror, { EditorView, keymap } from '@uiw/react-codemirror'; import { Button, Card, Collapse, Popover, Space, Tag, Typography } from 'antd'; import { getKeySuggestions } from 'api/querySuggestions/getKeySuggestions'; import { getValueSuggestions } from 'api/querySuggestions/getValueSuggestion'; @@ -62,17 +58,17 @@ const stopEventsExtension = EditorView.domEventHandlers({ }, }); -const disallowMultipleSpaces: Extension = EditorView.inputHandler.of( - (view, from, to, text) => { - const currentLine = view.state.doc.lineAt(from); - const before = currentLine.text.slice(0, from - currentLine.from); - const after = currentLine.text.slice(to - currentLine.from); +// const disallowMultipleSpaces: Extension = EditorView.inputHandler.of( +// (view, from, to, text) => { +// const currentLine = view.state.doc.lineAt(from); +// const before = currentLine.text.slice(0, from - currentLine.from); +// const after = currentLine.text.slice(to - currentLine.from); - const newText = before + text + after; +// const newText = before + text + after; - return /\s{2,}/.test(newText); - }, -); +// return /\s{2,}/.test(newText); +// }, +// ); function QuerySearch({ onChange, @@ -217,7 +213,8 @@ function QuerySearch({ // just wrap in quotes but not brackets (we're already in brackets) if ( (type === 'value' || type === 'keyword') && - !/^[a-zA-Z0-9_][a-zA-Z0-9_.\[\]]*$/.test(value) + !/^[a-zA-Z0-9_][a-zA-Z0-9_.\[\]]*$/.test(value) && + !queryContext?.isValueWrappedInQuotes ) { return wrapStringValueInQuotes(value); } @@ -949,7 +946,6 @@ function QuerySearch({ javascript({ jsx: false, typescript: false }), EditorView.lineWrapping, stopEventsExtension, - disallowMultipleSpaces, keymap.of([ ...completionKeymap, { diff --git a/frontend/src/types/antlrQueryTypes.ts b/frontend/src/types/antlrQueryTypes.ts index a7a3a54cb3d1..7b4f02a96b2f 100644 --- a/frontend/src/types/antlrQueryTypes.ts +++ b/frontend/src/types/antlrQueryTypes.ts @@ -40,6 +40,7 @@ export interface IQueryContext { isInConjunction?: boolean; isInParenthesis?: boolean; isInBracketList?: boolean; // For multi-value operators like IN where values are in brackets + isValueWrappedInQuotes?: boolean; keyToken?: string; operatorToken?: string; valueToken?: string; diff --git a/frontend/src/utils/queryContextUtils.ts b/frontend/src/utils/queryContextUtils.ts index 240e8d809997..2ec89afda39d 100644 --- a/frontend/src/utils/queryContextUtils.ts +++ b/frontend/src/utils/queryContextUtils.ts @@ -13,6 +13,7 @@ import { isNonValueOperatorToken, isOperatorToken, isValueToken, + isWrappedUnderQuotes, } from './tokenUtils'; // Function to normalize multiple spaces to single spaces when not in quotes @@ -714,6 +715,8 @@ export function getQueryContextAtCursor( const operatorToken = currentPair?.operator || ''; const valueToken = currentPair?.value || ''; + const isValueWrappedInQuotes = isWrappedUnderQuotes(valueToken); + // Determine if we're in a multi-value operator context const isForMultiValueOperator = isMultiValueOperator(operatorToken); @@ -739,6 +742,7 @@ export function getQueryContextAtCursor( isInFunction: false, isInParenthesis: isInParenthesisBoundary || false, isInBracketList: isInBracketListBoundary || false, + isValueWrappedInQuotes: isValueWrappedInQuotes, keyToken: isInKeyBoundary ? keyToken : isInOperatorBoundary || finalIsInValue diff --git a/frontend/src/utils/tokenUtils.ts b/frontend/src/utils/tokenUtils.ts index 0ff534b4adc1..c9f32c77450d 100644 --- a/frontend/src/utils/tokenUtils.ts +++ b/frontend/src/utils/tokenUtils.ts @@ -75,3 +75,12 @@ export function isFunctionToken(tokenType: number): boolean { FilterQueryLexer.HASNONE, ].includes(tokenType); } + +export function isWrappedUnderQuotes(token: string): boolean { + if (!token) return false; + const sanitizedToken = token.trim(); + return ( + (sanitizedToken.startsWith('"') && sanitizedToken.endsWith('"')) || + (sanitizedToken.startsWith("'") && sanitizedToken.endsWith("'")) + ); +}