mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-22 18:06:35 +00:00
feat: enhance query context to support detection of values wrapped in quotes
This commit is contained in:
parent
62d8dd929a
commit
85caefa945
@ -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,
|
||||
{
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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("'"))
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user