diff --git a/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryField.tsx b/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryField.tsx index a27fa4943fc..97e49df416b 100644 --- a/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryField.tsx +++ b/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryField.tsx @@ -1,7 +1,6 @@ // Core Grafana history https://github.com/grafana/grafana/blob/v11.0.0-preview/public/app/plugins/datasource/prometheus/components/monaco-query-field/MonacoQueryField.tsx import { css } from '@emotion/css'; import { parser } from '@prometheus-io/lezer-promql'; -import { debounce } from 'lodash'; import { promLanguageDefinition } from 'monaco-promql'; import { useEffect, useRef } from 'react'; import { useLatest } from 'react-use'; @@ -106,13 +105,12 @@ const MonacoQueryField = (props: Props) => { // we need only one instance of `overrideServices` during the lifetime of the react component const overrideServicesRef = useRef(getOverrideServices()); const containerRef = useRef(null); - const { languageProvider, history, onBlur, onRunQuery, initialValue, placeholder, onChange, datasource } = props; + const { languageProvider, history, onBlur, onRunQuery, initialValue, placeholder, datasource } = props; const lpRef = useLatest(languageProvider); const historyRef = useLatest(history); const onRunQueryRef = useLatest(onRunQuery); const onBlurRef = useLatest(onBlur); - const onChangeRef = useLatest(onChange); const autocompleteDisposeFun = useRef<(() => void) | null>(null); @@ -134,6 +132,8 @@ const MonacoQueryField = (props: Props) => { ref={containerRef} > { editor.onDidContentSizeChange(updateElementHeight); updateElementHeight(); - // Whenever the editor changes, lets save the last value so the next query for this editor will be up-to-date. - // This change is being introduced to fix a bug where you can submit a query via shift+enter: - // If you clicked into another field and haven't un-blurred the active field, - // then the query that is run will be stale, as the reference is only updated - // with the value of the last blurred input. - // This can run quite slowly, so we're debouncing this which should accomplish two things - // 1. Should prevent this function from blocking the current call stack by pushing into the web API callback queue - // 2. Should prevent a bunch of duplicates of this function being called as the user is typing - const updateCurrentEditorValue = debounce(() => { - const editorValue = editor.getValue(); - onChangeRef.current(editorValue); - }, lpRef.current.datasource.getDebounceTimeInMilliseconds()); - - editor.getModel()?.onDidChangeContent(() => { - updateCurrentEditorValue(); - }); - // handle: shift + enter // FIXME: maybe move this functionality into CodeEditor? editor.addCommand( @@ -235,9 +218,8 @@ const MonacoQueryField = (props: Props) => { command: null, }); - /* Something in this configuration of monaco doesn't bubble up [mod]+K, which the - command palette uses. Pass the event out of monaco manually - */ + // Something in this configuration of monaco doesn't bubble up [mod]+K, + // which the command palette uses. Pass the event out of monaco manually editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyK, function () { global.dispatchEvent(new KeyboardEvent('keydown', { key: 'k', metaKey: true })); }); diff --git a/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldLazy.tsx b/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldLazy.tsx index 53aad0b3047..53869e3cf58 100644 --- a/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldLazy.tsx +++ b/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldLazy.tsx @@ -4,8 +4,6 @@ import { Suspense } from 'react'; import MonacoQueryField from './MonacoQueryField'; import { Props } from './MonacoQueryFieldProps'; -// const Field = React.lazy(() => import('./MonacoQueryField')); - export const MonacoQueryFieldLazy = (props: Props) => { return ( diff --git a/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldProps.ts b/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldProps.ts index a0d21761f2c..4ca3fd894ed 100644 --- a/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldProps.ts +++ b/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldProps.ts @@ -16,7 +16,5 @@ export type Props = { placeholder: string; onRunQuery: (value: string) => void; onBlur: (value: string) => void; - // onChange will never initiate a query, it just denotes that a query value has been changed - onChange: (value: string) => void; datasource: PrometheusDatasource; }; diff --git a/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldWrapper.tsx b/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldWrapper.tsx index c95e8341b92..b46234a3b6b 100644 --- a/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldWrapper.tsx +++ b/packages/grafana-prometheus/src/components/monaco-query-field/MonacoQueryFieldWrapper.tsx @@ -23,13 +23,5 @@ export const MonacoQueryFieldWrapper = (props: Props) => { onChange(value); }; - /** - * Handles changes without running any queries - * @param value - */ - const handleChange = (value: string) => { - onChange(value); - }; - - return ; + return ; };