diff --git a/e2e/suite1/specs/exemplars.spec.ts b/e2e/suite1/specs/exemplars.spec.ts index bd466c56d7b..7a8c77921b7 100644 --- a/e2e/suite1/specs/exemplars.spec.ts +++ b/e2e/suite1/specs/exemplars.spec.ts @@ -46,6 +46,14 @@ describe('Exemplars', () => { e2e.components.DataSourcePicker.input().should('be.visible').click(); e2e().contains(dataSourceName).scrollIntoView().should('be.visible').click(); + + // we need to wait for the query-field being lazy-loaded, in two steps: + // 1. first we wait for the text 'Loading...' to appear + // 1. then we wait for the text 'Loading...' to disappear + const monacoLoadingText = 'Loading...'; + e2e.components.QueryField.container().should('be.visible').should('have.text', monacoLoadingText); + e2e.components.QueryField.container().should('be.visible').should('not.have.text', monacoLoadingText); + e2e.components.TimePicker.openButton().click(); e2e.components.TimePicker.fromField().clear().type('2021-07-10 17:10:00'); e2e.components.TimePicker.toField().clear().type('2021-07-10 17:30:00'); diff --git a/e2e/suite1/specs/query-editor.spec.ts b/e2e/suite1/specs/query-editor.spec.ts index 626228d8e36..e99275ce19b 100644 --- a/e2e/suite1/specs/query-editor.spec.ts +++ b/e2e/suite1/specs/query-editor.spec.ts @@ -13,7 +13,15 @@ e2e.scenario({ cy.contains('gdev-prometheus').scrollIntoView().should('be.visible').click(); const queryText = 'http_requests_total'; - e2e.components.QueryField.container().should('be.visible').type(queryText).type('{backspace}'); + // we need to wait for the query-field being lazy-loaded, in two steps: + // it is a two-step process: + // 1. first we wait for the text 'Loading...' to appear + // 1. then we wait for the text 'Loading...' to disappear + const monacoLoadingText = 'Loading...'; + e2e.components.QueryField.container().should('be.visible').should('have.text', monacoLoadingText); + e2e.components.QueryField.container().should('be.visible').should('not.have.text', monacoLoadingText); + + e2e.components.QueryField.container().type(queryText).type('{backspace}'); cy.contains(queryText.slice(0, -1)).should('be.visible'); diff --git a/packages/grafana-data/src/types/config.ts b/packages/grafana-data/src/types/config.ts index c69f4e4dbd9..14d723dd74f 100644 --- a/packages/grafana-data/src/types/config.ts +++ b/packages/grafana-data/src/types/config.ts @@ -50,7 +50,6 @@ export interface FeatureToggles { tempoServiceGraph: boolean; tempoSearch: boolean; recordedQueries: boolean; - prometheusMonaco: boolean; newNavigation: boolean; fullRangeLogsVolume: boolean; autoLoadFullRangeLogsVolume: boolean; diff --git a/packages/grafana-runtime/src/config.ts b/packages/grafana-runtime/src/config.ts index 3a3671f39cc..cae7cc4854c 100644 --- a/packages/grafana-runtime/src/config.ts +++ b/packages/grafana-runtime/src/config.ts @@ -66,7 +66,6 @@ export class GrafanaBootConfig implements GrafanaConfig { tempoServiceGraph: false, tempoSearch: false, recordedQueries: false, - prometheusMonaco: false, newNavigation: false, fullRangeLogsVolume: false, autoLoadFullRangeLogsVolume: false, diff --git a/public/app/plugins/datasource/prometheus/components/PromExploreQueryEditor.test.tsx b/public/app/plugins/datasource/prometheus/components/PromExploreQueryEditor.test.tsx index ea45b588f86..b3fc96cd575 100644 --- a/public/app/plugins/datasource/prometheus/components/PromExploreQueryEditor.test.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromExploreQueryEditor.test.tsx @@ -6,6 +6,16 @@ import { PrometheusDatasource } from '../datasource'; import { PromQuery } from '../types'; import { LoadingState, PanelData, toUtc, TimeRange } from '@grafana/data'; +// the monaco-based editor uses lazy-loading and that does not work +// well with this test, and we do not need the monaco-related +// functionality in this test anyway, so we mock it out. +jest.mock('./monaco-query-field/MonacoQueryFieldWrapper', () => { + const fakeQueryField = () =>
prometheus query field
; + return { + MonacoQueryFieldWrapper: fakeQueryField, + }; +}); + const setup = (renderMethod: any, propOverrides?: object) => { const datasourceMock: unknown = { languageProvider: { diff --git a/public/app/plugins/datasource/prometheus/components/PromQueryEditorByApp.test.tsx b/public/app/plugins/datasource/prometheus/components/PromQueryEditorByApp.test.tsx index 033f95caf2f..b50796142de 100644 --- a/public/app/plugins/datasource/prometheus/components/PromQueryEditorByApp.test.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromQueryEditorByApp.test.tsx @@ -7,6 +7,16 @@ import { PrometheusDatasource } from '../datasource'; import { testIds as alertingTestIds } from './PromQueryEditorForAlerting'; import { testIds as regularTestIds } from './PromQueryEditor'; +// the monaco-based editor uses lazy-loading and that does not work +// well with this test, and we do not need the monaco-related +// functionality in this test anyway, so we mock it out. +jest.mock('./monaco-query-field/MonacoQueryFieldWrapper', () => { + const fakeQueryField = () =>
prometheus query field
; + return { + MonacoQueryFieldWrapper: fakeQueryField, + }; +}); + function setup(app: CoreApp): RenderResult { const dataSource = ({ createQuery: jest.fn((q) => q), diff --git a/public/app/plugins/datasource/prometheus/components/PromQueryEditorForAlerting.tsx b/public/app/plugins/datasource/prometheus/components/PromQueryEditorForAlerting.tsx index ab81037e949..effb68b1703 100644 --- a/public/app/plugins/datasource/prometheus/components/PromQueryEditorForAlerting.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromQueryEditorForAlerting.tsx @@ -14,7 +14,6 @@ export function PromQueryEditorForAlerting(props: PromQueryEditorProps) { history={[]} range={range} data={data} - placeholder="Enter a PromQL query" data-testid={testIds.editor} /> ); diff --git a/public/app/plugins/datasource/prometheus/components/PromQueryField.test.tsx b/public/app/plugins/datasource/prometheus/components/PromQueryField.test.tsx index 5caf277a0bf..dc0a78aaf62 100644 --- a/public/app/plugins/datasource/prometheus/components/PromQueryField.test.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromQueryField.test.tsx @@ -7,6 +7,16 @@ import { DataSourceInstanceSettings, PanelData, LoadingState, DataFrame } from ' import { PromOptions } from '../types'; import { render, screen } from '@testing-library/react'; +// the monaco-based editor uses lazy-loading and that does not work +// well with this test, and we do not need the monaco-related +// functionality in this test anyway, so we mock it out. +jest.mock('./monaco-query-field/MonacoQueryFieldWrapper', () => { + const fakeQueryField = () =>
prometheus query field
; + return { + MonacoQueryFieldWrapper: fakeQueryField, + }; +}); + describe('PromQueryField', () => { beforeAll(() => { // @ts-ignore diff --git a/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx b/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx index a059c5ed77a..8de4357985f 100644 --- a/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx +++ b/public/app/plugins/datasource/prometheus/components/PromQueryField.tsx @@ -1,12 +1,10 @@ import React, { ReactNode } from 'react'; -import { config } from '@grafana/runtime'; import { Plugin } from 'slate'; import { SlatePrism, TypeaheadInput, TypeaheadOutput, - QueryField, BracesPlugin, DOMUtil, SuggestionsState, @@ -73,7 +71,6 @@ export function willApplySuggestion(suggestion: string, { typeaheadContext, type interface PromQueryFieldProps extends QueryEditorProps { ExtraFieldElement?: ReactNode; - placeholder?: string; 'data-testid'?: string; } @@ -266,18 +263,14 @@ class PromQueryField extends React.PureComponent 0; const chooserText = getChooserText(datasource.lookupsDisabled, syntaxLoaded, hasMetrics); const buttonDisabled = !(syntaxLoaded && hasMetrics); - const isMonacoEditorEnabled = config.featureToggles.prometheusMonaco; - return ( storageKey={LAST_USED_LABELS_KEY} defaultValue={[]}> {(lastUsedLabels, onLastUsedLabelsSave, onLastUsedLabelsDelete) => { @@ -297,30 +290,14 @@ class PromQueryField extends React.PureComponent
- {isMonacoEditorEnabled ? ( - - ) : ( - - )} +
{labelBrowserVisible && ( diff --git a/public/app/plugins/datasource/prometheus/components/monaco-query-field/MonacoQueryField.tsx b/public/app/plugins/datasource/prometheus/components/monaco-query-field/MonacoQueryField.tsx index 2d832a6e736..cadab747763 100644 --- a/public/app/plugins/datasource/prometheus/components/monaco-query-field/MonacoQueryField.tsx +++ b/public/app/plugins/datasource/prometheus/components/monaco-query-field/MonacoQueryField.tsx @@ -4,6 +4,7 @@ import { GrafanaTheme2 } from '@grafana/data'; import { css } from '@emotion/css'; import { useLatest } from 'react-use'; import { promLanguageDefinition } from 'monaco-promql'; +import { selectors } from '@grafana/e2e-selectors'; import { getCompletionProvider, getSuggestOptions } from './monaco-completion-provider'; import { Props } from './MonacoQueryFieldProps'; import { getOverrideServices } from './getOverrideServices'; @@ -101,6 +102,7 @@ const MonacoQueryField = (props: Props) => { return (