From aa6f16878fb7c72324038602d753ad05f5745e65 Mon Sep 17 00:00:00 2001 From: Domas Date: Thu, 1 Jun 2023 13:10:00 +0300 Subject: [PATCH] TempoQueryEDitor: Respect onRunQuery updates (#69362) make tempo query editor respect onRunQuery changes --- .../app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx b/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx index 06b73580b4b..b2126bbe2b7 100644 --- a/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx +++ b/public/app/plugins/datasource/tempo/traceql/TraceQLEditor.tsx @@ -28,6 +28,10 @@ export function TraceQLEditor(props: Props) { const setupAutocompleteFn = useAutocomplete(props.datasource); const theme = useTheme2(); const styles = getStyles(theme, placeholder); + // work around the problem that `onEditorDidMount` is called once + // and wouldn't get new version of onRunQuery + const onRunQueryRef = useRef(onRunQuery); + onRunQueryRef.current = onRunQuery; return ( { if (!props.readOnly) { setupAutocompleteFn(editor, monaco, setupRegisterInteractionCommand(editor)); - setupActions(editor, monaco, onRunQuery); + setupActions(editor, monaco, () => onRunQueryRef.current()); setupPlaceholder(editor, monaco, styles); } setupAutoSize(editor);