From c5c4e12e5abeea33f4fad3980f8ce87f0d68f529 Mon Sep 17 00:00:00 2001 From: Rafal Strzalinski Date: Fri, 4 Apr 2025 13:17:48 +0200 Subject: [PATCH 1/2] Fix multiline pause/play --- .../ObservabilityQueryLanguageComponent.tsx | 60 ++++++++++++++++--- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/src/components/App/ObservabilityQueryLanguageComponent.tsx b/src/components/App/ObservabilityQueryLanguageComponent.tsx index 45bde94..0027065 100644 --- a/src/components/App/ObservabilityQueryLanguageComponent.tsx +++ b/src/components/App/ObservabilityQueryLanguageComponent.tsx @@ -169,18 +169,60 @@ export default function ObservabilityQueryLanguageComponent() { const handleGlyphClick = useCallback((lineNumber: number, isPlay: boolean) => { const lines = queryRef.current.split('\n'); - if (lineNumber > 0 && lineNumber <= lines.length) { - const newLines = [...lines]; - const line = newLines[lineNumber - 1]; - if (isPlay) { - newLines[lineNumber - 1] = line.replace('|>', '--|>'); + + const commentPattern = '-- '; + const continuedCommentPattern = '--\\ '; + + let pattern = '|>'; + let replacement = '--|>'; + let shouldComment = true; + + if (!isPlay) { + pattern = '--|>'; + replacement = '|>'; + shouldComment = false; + } + + let currentLine = lineNumber - 1; + + if (lines[currentLine].trim().startsWith(pattern)) { + lines[currentLine] = lines[currentLine].replace(pattern, replacement); + } else { + console.log("No pipe found at line", lineNumber); + return; + } + + for (let n = lineNumber; n < lines.length; n++) { + const line = lines[n]; + + if (line.trim() == "") { + continue; + } + + // stop when we hit the end of the pipe section + if (line.trim().startsWith("--|>") || line.trim().startsWith("|>")) { + break; + } + + if (shouldComment) { + if (line.trim().startsWith(continuedCommentPattern) || line.trim().startsWith(commentPattern)) { + continue; + } + lines[n] = continuedCommentPattern + line; } else { - newLines[lineNumber - 1] = line.replace('--|>', '|>'); + if (!line.trim().startsWith(continuedCommentPattern) && !line.trim().startsWith(commentPattern)) { + continue; + } + lines[n] = line.replace(continuedCommentPattern, ""); } - setQuery(newLines.join('\n')); - setActiveQuery(newLines.join('\n')); } - }, []); // No need for dependencies since we're using ref + + const newQuery = lines.join('\n'); + + setQuery(newQuery); + setActiveQuery(newQuery); + + }, []); const onFilterChange = useCallback((columnName: string, value: string, operator: string) => { From 26b3562eb0bfd9c9f87d4ca91a5bbd277d7466d8 Mon Sep 17 00:00:00 2001 From: Rafal Strzalinski Date: Fri, 4 Apr 2025 13:20:27 +0200 Subject: [PATCH 2/2] linter --- src/components/App/ObservabilityQueryLanguageComponent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/App/ObservabilityQueryLanguageComponent.tsx b/src/components/App/ObservabilityQueryLanguageComponent.tsx index 0027065..7bd39a3 100644 --- a/src/components/App/ObservabilityQueryLanguageComponent.tsx +++ b/src/components/App/ObservabilityQueryLanguageComponent.tsx @@ -195,7 +195,7 @@ export default function ObservabilityQueryLanguageComponent() { for (let n = lineNumber; n < lines.length; n++) { const line = lines[n]; - if (line.trim() == "") { + if (line.trim() === "") { continue; }