diff --git a/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx b/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx index f9d4e74b810..c8fbc9e6fdb 100644 --- a/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx +++ b/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { mount, shallow } from 'enzyme'; import { act } from 'react-dom/test-utils'; -import LokiExploreQueryEditor from './LokiExploreQueryEditor'; +import { LokiExploreQueryEditor } from './LokiExploreQueryEditor'; import { LokiOptionFields } from './LokiOptionFields'; import { LokiDatasource } from '../datasource'; import { LokiQuery } from '../types'; diff --git a/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.tsx b/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.tsx index d5010950878..c78ef98047d 100644 --- a/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.tsx +++ b/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.tsx @@ -10,7 +10,7 @@ import { LokiOptionFields } from './LokiOptionFields'; type Props = QueryEditorProps; -export function LokiExploreQueryEditor(props: Props) { +export const LokiExploreQueryEditor = memo((props: Props) => { const { query, data, datasource, history, onChange, onRunQuery, range } = props; return ( @@ -23,6 +23,7 @@ export function LokiExploreQueryEditor(props: Props) { history={history} data={data} range={range} + data-testid={testIds.editor} ExtraFieldElement={ ); -} +}); -export default memo(LokiExploreQueryEditor); +LokiExploreQueryEditor.displayName = 'LokiExploreQueryEditor'; + +export const testIds = { + editor: 'loki-editor-explore', +}; diff --git a/public/app/plugins/datasource/loki/components/LokiQueryEditorByApp.test.tsx b/public/app/plugins/datasource/loki/components/LokiQueryEditorByApp.test.tsx index 1bac9ffcfa0..65e2bdd558e 100644 --- a/public/app/plugins/datasource/loki/components/LokiQueryEditorByApp.test.tsx +++ b/public/app/plugins/datasource/loki/components/LokiQueryEditorByApp.test.tsx @@ -5,7 +5,8 @@ import { noop } from 'lodash'; import { LokiDatasource } from '../datasource'; import { testIds as alertingTestIds } from './LokiQueryEditorForAlerting'; import { testIds as regularTestIds } from './LokiQueryEditor'; -import LokiQueryEditorByApp from './LokiQueryEditorByApp'; +import { testIds as exploreTestIds } from './LokiExploreQueryEditor'; +import { LokiQueryEditorByApp } from './LokiQueryEditorByApp'; function setup(app: CoreApp): RenderResult { const dataSource = { @@ -43,10 +44,10 @@ describe('LokiQueryEditorByApp', () => { expect(queryByTestId(alertingTestIds.editor)).toBeNull(); }); - it('should render regular query editor for explore', () => { + it('should render expore query editor for explore', () => { const { getByTestId, queryByTestId } = setup(CoreApp.Explore); - expect(getByTestId(regularTestIds.editor)).toBeInTheDocument(); + expect(getByTestId(exploreTestIds.editor)).toBeInTheDocument(); expect(queryByTestId(alertingTestIds.editor)).toBeNull(); }); diff --git a/public/app/plugins/datasource/loki/components/LokiQueryEditorByApp.tsx b/public/app/plugins/datasource/loki/components/LokiQueryEditorByApp.tsx index 7dffe3c21d0..e49db26d3e1 100644 --- a/public/app/plugins/datasource/loki/components/LokiQueryEditorByApp.tsx +++ b/public/app/plugins/datasource/loki/components/LokiQueryEditorByApp.tsx @@ -3,6 +3,7 @@ import { CoreApp } from '@grafana/data'; import { LokiQueryEditorProps } from './types'; import { LokiQueryEditor } from './LokiQueryEditor'; import { LokiQueryEditorForAlerting } from './LokiQueryEditorForAlerting'; +import { LokiExploreQueryEditor } from './LokiExploreQueryEditor'; import { LokiQueryEditorSelector } from '../querybuilder/components/LokiQueryEditorSelector'; import { config } from '@grafana/runtime'; @@ -12,6 +13,11 @@ export function LokiQueryEditorByApp(props: LokiQueryEditorProps) { switch (app) { case CoreApp.CloudAlerting: return ; + case CoreApp.Explore: + if (config.featureToggles.lokiQueryBuilder) { + return ; + } + return ; default: if (config.featureToggles.lokiQueryBuilder) { return ; diff --git a/public/app/plugins/datasource/loki/components/__snapshots__/LokiExploreQueryEditor.test.tsx.snap b/public/app/plugins/datasource/loki/components/__snapshots__/LokiExploreQueryEditor.test.tsx.snap index 7a4bb2db700..e41e5c921ef 100644 --- a/public/app/plugins/datasource/loki/components/__snapshots__/LokiExploreQueryEditor.test.tsx.snap +++ b/public/app/plugins/datasource/loki/components/__snapshots__/LokiExploreQueryEditor.test.tsx.snap @@ -51,6 +51,7 @@ exports[`LokiExploreQueryEditor should render component 1`] = ` }, } } + data-testid="loki-editor-explore" datasource={ Object { "getTimeRangeParams": [Function], diff --git a/public/app/plugins/datasource/loki/module.ts b/public/app/plugins/datasource/loki/module.ts index 524838580c7..6a6ad395313 100644 --- a/public/app/plugins/datasource/loki/module.ts +++ b/public/app/plugins/datasource/loki/module.ts @@ -9,6 +9,5 @@ import { ConfigEditor } from './configuration/ConfigEditor'; export const plugin = new DataSourcePlugin(Datasource) .setQueryEditor(LokiQueryEditorByApp) .setConfigEditor(ConfigEditor) - .setExploreQueryField(LokiQueryEditorByApp) .setQueryEditorHelp(LokiCheatSheet) .setAnnotationQueryCtrl(LokiAnnotationsQueryCtrl); diff --git a/public/app/plugins/datasource/prometheus/module.test.ts b/public/app/plugins/datasource/prometheus/module.test.ts index f12182e4fc9..2b0473a3791 100644 --- a/public/app/plugins/datasource/prometheus/module.test.ts +++ b/public/app/plugins/datasource/prometheus/module.test.ts @@ -3,7 +3,6 @@ import { ANNOTATION_QUERY_STEP_DEFAULT } from './datasource'; describe('module', () => { it('should have metrics query field in panels and Explore', () => { - expect(PrometheusDatasourcePlugin.components.ExploreMetricsQueryField).toBeDefined(); expect(PrometheusDatasourcePlugin.components.QueryEditor).toBeDefined(); }); it('should have stepDefaultValuePlaceholder set in annotations ctrl', () => { diff --git a/public/app/plugins/datasource/prometheus/module.ts b/public/app/plugins/datasource/prometheus/module.ts index f4711890cba..f570f7c5150 100644 --- a/public/app/plugins/datasource/prometheus/module.ts +++ b/public/app/plugins/datasource/prometheus/module.ts @@ -14,6 +14,5 @@ class PrometheusAnnotationsQueryCtrl { export const plugin = new DataSourcePlugin(PrometheusDatasource) .setQueryEditor(PromQueryEditorByApp) .setConfigEditor(ConfigEditor) - .setExploreMetricsQueryField(PromQueryEditorByApp) .setAnnotationQueryCtrl(PrometheusAnnotationsQueryCtrl) .setQueryEditorHelp(PromCheatSheet);