diff --git a/.betterer.results b/.betterer.results index e821ba95673..a4cb078f9fd 100644 --- a/.betterer.results +++ b/.betterer.results @@ -3206,10 +3206,6 @@ exports[`better eslint`] = { "public/app/features/query/components/QueryGroupOptions.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/query/components/SavedQueryPicker.tsx:5381": [ - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"], - [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"] - ], "public/app/features/query/state/DashboardQueryRunner/AlertStatesWorker.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], diff --git a/public/app/features/query/components/QueryGroup.tsx b/public/app/features/query/components/QueryGroup.tsx index 42233e2aa06..069678445ec 100644 --- a/public/app/features/query/components/QueryGroup.tsx +++ b/public/app/features/query/components/QueryGroup.tsx @@ -27,7 +27,7 @@ import { DataSourcePicker } from 'app/features/datasources/components/picker/Dat import { dataSource as expressionDatasource } from 'app/features/expressions/ExpressionDatasource'; import { DashboardQueryEditor, isSharedDashboardQuery } from 'app/plugins/datasource/dashboard'; import { GrafanaQuery, GrafanaQueryType } from 'app/plugins/datasource/grafana/types'; -import { QueryGroupDataSource, QueryGroupOptions } from 'app/types'; +import { QueryGroupOptions } from 'app/types'; import { PanelQueryRunner } from '../state/PanelQueryRunner'; import { updateQueries } from '../state/updateQueries'; @@ -57,12 +57,6 @@ interface State { isHelpOpen: boolean; defaultDataSource?: DataSourceApi; scrollElement?: HTMLDivElement; - savedQueryUid?: string | null; - initialState: { - queries: DataQuery[]; - dataSource?: QueryGroupDataSource; - savedQueryUid?: string | null; - }; } export class QueryGroup extends PureComponent { @@ -78,11 +72,6 @@ export class QueryGroup extends PureComponent { isAddingMixed: false, isHelpOpen: false, queries: [], - savedQueryUid: null, - initialState: { - queries: [], - savedQueryUid: null, - }, data: { state: LoadingState.NotStarted, series: [], @@ -113,12 +102,6 @@ export class QueryGroup extends PureComponent { dataSource: ds, dsSettings, defaultDataSource, - savedQueryUid: options.savedQueryUid, - initialState: { - queries: options.queries.map((q) => ({ ...q })), - dataSource: { ...options.dataSource }, - savedQueryUid: options.savedQueryUid, - }, // TODO: Detect the first panel added into a new dashboard better. // This is flaky in case the UID is generated differently isDataSourceModalOpen: @@ -152,7 +135,6 @@ export class QueryGroup extends PureComponent { const dataSource = await this.dataSourceSrv.get(newSettings.name); this.onChange({ queries, - savedQueryUid: null, dataSource: { name: newSettings.name, uid: newSettings.uid, @@ -163,7 +145,6 @@ export class QueryGroup extends PureComponent { this.setState({ queries, - savedQueryUid: null, dataSource: dataSource, dsSettings: newSettings, }); diff --git a/public/app/features/query/components/SavedQueryPicker.tsx b/public/app/features/query/components/SavedQueryPicker.tsx deleted file mode 100644 index 83f827c5f51..00000000000 --- a/public/app/features/query/components/SavedQueryPicker.tsx +++ /dev/null @@ -1,116 +0,0 @@ -// Libraries -import React, { useMemo } from 'react'; -// Components -import { useAsync } from 'react-use'; -import { AsyncState } from 'react-use/lib/useAsyncFn'; - -import { DataSourceInstanceSettings, isUnsignedPluginSignature, SelectableValue } from '@grafana/data'; -import { selectors } from '@grafana/e2e-selectors'; -import { getDataSourceSrv } from '@grafana/runtime/src'; -import { HorizontalGroup, PluginSignatureBadge, Select } from '@grafana/ui'; - -import { getGrafanaSearcher, QueryResponse, SearchQuery } from '../../search/service'; - -export type SavedQueryPickerProps = { - onChange: (savedQueryUid: string | null) => void; - current?: string | null; // type - hideTextValue?: boolean; - onBlur?: () => void; - autoFocus?: boolean; - openMenuOnFocus?: boolean; - placeholder?: string; - tracing?: boolean; - mixed?: boolean; - dashboard?: boolean; - metrics?: boolean; - type?: string | string[]; - annotations?: boolean; - variables?: boolean; - alerting?: boolean; - pluginId?: string; - /** If true,we show only DSs with logs; and if true, pluginId shouldnt be passed in */ - logs?: boolean; - width?: number; - inputId?: string; - filter?: (dataSource: DataSourceInstanceSettings) => boolean; - onClear?: () => void; -}; - -function getSavedQueryPickerOptions(results: AsyncState): Array> { - if (results?.loading) { - return []; - } - - if (!results?.value?.totalRows) { - return []; - } - - const hits = results.value.view.toArray(); - - return hits.map((h) => { - const dsSettings = h.ds_uid?.length ? getDataSourceSrv().getInstanceSettings(h.ds_uid[0]) : undefined; - - return { - value: h.uid, - label: h.name, - imgUrl: dsSettings?.meta.info.logos.small, - meta: dsSettings?.meta, - }; - }); -} - -export const SavedQueryPicker = (props: SavedQueryPickerProps) => { - const { autoFocus, onBlur, onChange, current, openMenuOnFocus, placeholder, width, inputId } = props; - - const searchQuery = useMemo(() => { - // TODO: ensure we fetch all saved queries? - const query: SearchQuery = { - query: '*', - explain: true, - kind: ['query'], - }; - - return query; - }, []); - - const results = useAsync(async () => { - return getGrafanaSearcher().search(searchQuery); - }, [searchQuery]); - - const options = getSavedQueryPickerOptions(results); - - return ( -
-