mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-18 16:07:10 +00:00
feat: handle parenthesis and conjunction operators
This commit is contained in:
parent
5eaba94528
commit
8669d94e9c
@ -1,3 +1,4 @@
|
||||
/* eslint-disable sonarjs/cognitive-complexity */
|
||||
import {
|
||||
autocompletion,
|
||||
closeCompletion,
|
||||
@ -58,18 +59,8 @@ function HavingFilter(): JSX.Element {
|
||||
const { aggregationOptions } = useQueryBuilderV2Context();
|
||||
const [input, setInput] = useState('');
|
||||
|
||||
const [cursorPos, setCursorPos] = useState(0);
|
||||
|
||||
const editorRef = useRef<EditorView | null>(null);
|
||||
|
||||
console.log('cursorPos', cursorPos);
|
||||
|
||||
// Update cursor position on every editor update
|
||||
const handleUpdate = (update: { view: EditorView }): void => {
|
||||
const pos = update.view.state.selection.main.from;
|
||||
setCursorPos(pos);
|
||||
};
|
||||
|
||||
const [options, setOptions] = useState<{ label: string; value: string }[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
@ -146,6 +137,17 @@ function HavingFilter(): JSX.Element {
|
||||
openCount > closeCount ? [closeBrace, ...conjunctions] : conjunctions,
|
||||
};
|
||||
}
|
||||
// Suggest conjunctions after a closing parenthesis and a space
|
||||
if (
|
||||
tokens.length > 0 &&
|
||||
tokens[tokens.length - 1] === ')' &&
|
||||
text.endsWith(' ')
|
||||
) {
|
||||
return {
|
||||
from: context.pos,
|
||||
options: conjunctions,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
},
|
||||
],
|
||||
@ -182,7 +184,6 @@ function HavingFilter(): JSX.Element {
|
||||
autocompletion: true,
|
||||
completionKeymap: true,
|
||||
}}
|
||||
onUpdate={handleUpdate}
|
||||
ref={editorRef}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user