mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-20 00:46:46 +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 {
|
import {
|
||||||
autocompletion,
|
autocompletion,
|
||||||
closeCompletion,
|
closeCompletion,
|
||||||
@ -58,18 +59,8 @@ function HavingFilter(): JSX.Element {
|
|||||||
const { aggregationOptions } = useQueryBuilderV2Context();
|
const { aggregationOptions } = useQueryBuilderV2Context();
|
||||||
const [input, setInput] = useState('');
|
const [input, setInput] = useState('');
|
||||||
|
|
||||||
const [cursorPos, setCursorPos] = useState(0);
|
|
||||||
|
|
||||||
const editorRef = useRef<EditorView | null>(null);
|
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 }[]>([]);
|
const [options, setOptions] = useState<{ label: string; value: string }[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -146,6 +137,17 @@ function HavingFilter(): JSX.Element {
|
|||||||
openCount > closeCount ? [closeBrace, ...conjunctions] : conjunctions,
|
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;
|
return null;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -182,7 +184,6 @@ function HavingFilter(): JSX.Element {
|
|||||||
autocompletion: true,
|
autocompletion: true,
|
||||||
completionKeymap: true,
|
completionKeymap: true,
|
||||||
}}
|
}}
|
||||||
onUpdate={handleUpdate}
|
|
||||||
ref={editorRef}
|
ref={editorRef}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user