diff --git a/packages/grafana-ui/src/types/datasource.ts b/packages/grafana-ui/src/types/datasource.ts index fc404feb623..3e64ed8a18d 100644 --- a/packages/grafana-ui/src/types/datasource.ts +++ b/packages/grafana-ui/src/types/datasource.ts @@ -25,6 +25,24 @@ export interface DataQueryOptions { scopedVars: object; } +export interface QueryFix { + type: string; + label: string; + action?: QueryFixAction; +} + +export interface QueryFixAction { + type: string; + query?: string; + preventSubmit?: boolean; +} + +export interface QueryHint { + type: string; + label: string; + fix?: QueryFix; +} + export interface DataSourceApi { name: string; meta: PluginMeta; @@ -54,6 +72,11 @@ export interface DataSourceApi { * Test & verify datasource settings & connection details */ testDatasource(): Promise; + + /** + * Get hints for query improvements + */ + getQueryHints(query: DataQuery, results: any[], ...rest: any): QueryHint[]; } export interface DataSourceSettings { @@ -82,4 +105,3 @@ export interface DataSourceSelectItem { meta: PluginMeta; sort: string; } - diff --git a/public/app/features/datasources/settings/__snapshots__/DataSourceSettings.test.tsx.snap b/public/app/features/datasources/settings/__snapshots__/DataSourceSettings.test.tsx.snap deleted file mode 100644 index bcd8237ff39..00000000000 --- a/public/app/features/datasources/settings/__snapshots__/DataSourceSettings.test.tsx.snap +++ /dev/null @@ -1,415 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Render should render alpha info text 1`] = ` -
- -
-
-
-
- This plugin is marked as being in alpha state, which means it is in early development phase and updates will include breaking changes. -
- - -
- - -
-
-
-`; - -exports[`Render should render beta info text 1`] = ` -
- -
-
-
-
- This plugin is marked as being in a beta development state. This means it is in currently in active development and could be missing important features. -
- - -
- - -
-
-
-`; - -exports[`Render should render component 1`] = ` -
- -
-
-
- - -
- - -
-
-
-`; - -exports[`Render should render is ready only message 1`] = ` -
- -
-
-
-
- This datasource was added by config and cannot be modified using the UI. Please contact your server admin to update this datasource. -
- - -
- - -
-
-
-`; - -exports[`Render should render loader 1`] = ` -
- - -
-`; diff --git a/public/app/features/explore/QueryRow.tsx b/public/app/features/explore/QueryRow.tsx index 2cfda3c8a49..3bc2b556a63 100644 --- a/public/app/features/explore/QueryRow.tsx +++ b/public/app/features/explore/QueryRow.tsx @@ -19,9 +19,9 @@ import { } from './state/actions'; // Types -import { RawTimeRange, DataQuery } from '@grafana/ui'; import { StoreState } from 'app/types'; -import { QueryTransaction, HistoryItem, QueryHint, ExploreItemState, ExploreId } from 'app/types/explore'; +import { RawTimeRange, DataQuery, QueryHint } from '@grafana/ui'; +import { QueryTransaction, HistoryItem, ExploreItemState, ExploreId } from 'app/types/explore'; import { Emitter } from 'app/core/utils/emitter'; function getFirstHintFromTransactions(transactions: QueryTransaction[]): QueryHint { diff --git a/public/app/features/explore/state/actions.ts b/public/app/features/explore/state/actions.ts index e4d90562332..34169a999a3 100644 --- a/public/app/features/explore/state/actions.ts +++ b/public/app/features/explore/state/actions.ts @@ -1,7 +1,9 @@ +// Libraries import _ from 'lodash'; import { ThunkAction } from 'redux-thunk'; -import { RawTimeRange, TimeRange } from '@grafana/ui'; +// Services & Utils +import store from 'app/core/store'; import { LAST_USED_DATASOURCE_KEY, clearQueryKeys, @@ -14,10 +16,12 @@ import { serializeStateToUrlParam, } from 'app/core/utils/explore'; +// Actions import { updateLocation } from 'app/core/actions'; -import store from 'app/core/store'; + +// Types import { StoreState } from 'app/types'; -import { DataQuery, DataSourceSelectItem } from '@grafana/ui/src/types'; +import { DataQuery, DataSourceSelectItem, QueryHint } from '@grafana/ui/src/types'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { ExploreId, @@ -26,11 +30,10 @@ import { ResultType, QueryOptions, QueryTransaction, - QueryHint, - QueryHintGetter, } from 'app/types/explore'; -import { Emitter } from 'app/core/core'; +import { Emitter } from 'app/core/core'; +import { RawTimeRange, TimeRange } from '@grafana/ui'; import { Action as ThunkableAction, ActionTypes, @@ -45,6 +48,7 @@ import { ScanStopAction, } from './actionTypes'; + type ThunkResult = ThunkAction; /** @@ -460,7 +464,7 @@ export function queryTransactionSuccess( // Get query hints let hints: QueryHint[]; - if (datasourceInstance.getQueryHints as QueryHintGetter) { + if (datasourceInstance.getQueryHints) { hints = datasourceInstance.getQueryHints(transaction.query, result); } diff --git a/public/app/plugins/datasource/prometheus/query_hints.ts b/public/app/plugins/datasource/prometheus/query_hints.ts index ce019e3ddcb..d3216874ab5 100644 --- a/public/app/plugins/datasource/prometheus/query_hints.ts +++ b/public/app/plugins/datasource/prometheus/query_hints.ts @@ -1,6 +1,5 @@ import _ from 'lodash'; - -import { QueryHint } from 'app/types/explore'; +import { QueryHint } from '@grafana/ui/src/types'; /** * Number of time series results needed before starting to suggest sum aggregation hints diff --git a/public/app/types/explore.ts b/public/app/types/explore.ts index 218760f7578..e5ae676ba25 100644 --- a/public/app/types/explore.ts +++ b/public/app/types/explore.ts @@ -1,5 +1,5 @@ import { Value } from 'slate'; -import { RawTimeRange, TimeRange, DataQuery, DataSourceSelectItem } from '@grafana/ui'; +import { RawTimeRange, TimeRange, DataQuery, DataSourceSelectItem, DataSourceApi, QueryHint } from '@grafana/ui'; import { Emitter } from 'app/core/core'; import { LogsModel } from 'app/core/logs_model'; @@ -110,7 +110,7 @@ export interface ExploreItemState { /** * Datasource instance that has been selected. Datasource-specific logic can be run on this object. */ - datasourceInstance: any; + datasourceInstance: DataSourceApi; /** * Error to be shown when datasource loading or testing failed. */ @@ -273,28 +273,6 @@ export interface TypeaheadOutput { suggestions: CompletionItemGroup[]; } -export interface QueryFix { - type: string; - label: string; - action?: QueryFixAction; -} - -export interface QueryFixAction { - type: string; - query?: string; - preventSubmit?: boolean; -} - -export interface QueryHint { - type: string; - label: string; - fix?: QueryFix; -} - -export interface QueryHintGetter { - (query: DataQuery, results: any[], ...rest: any): QueryHint[]; -} - export interface QueryIntervals { interval: string; intervalMs: number;