Commit 205e2acd by Torkel Ödegaard

Added data source type to explore state

parent a6f6ed41
...@@ -25,6 +25,24 @@ export interface DataQueryOptions { ...@@ -25,6 +25,24 @@ export interface DataQueryOptions {
scopedVars: object; 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 { export interface DataSourceApi {
name: string; name: string;
meta: PluginMeta; meta: PluginMeta;
...@@ -54,6 +72,11 @@ export interface DataSourceApi { ...@@ -54,6 +72,11 @@ export interface DataSourceApi {
* Test & verify datasource settings & connection details * Test & verify datasource settings & connection details
*/ */
testDatasource(): Promise<any>; testDatasource(): Promise<any>;
/**
* Get hints for query improvements
*/
getQueryHints(query: DataQuery, results: any[], ...rest: any): QueryHint[];
} }
export interface DataSourceSettings { export interface DataSourceSettings {
...@@ -82,4 +105,3 @@ export interface DataSourceSelectItem { ...@@ -82,4 +105,3 @@ export interface DataSourceSelectItem {
meta: PluginMeta; meta: PluginMeta;
sort: string; sort: string;
} }
...@@ -19,9 +19,9 @@ import { ...@@ -19,9 +19,9 @@ import {
} from './state/actions'; } from './state/actions';
// Types // Types
import { RawTimeRange, DataQuery } from '@grafana/ui';
import { StoreState } from 'app/types'; 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'; import { Emitter } from 'app/core/utils/emitter';
function getFirstHintFromTransactions(transactions: QueryTransaction[]): QueryHint { function getFirstHintFromTransactions(transactions: QueryTransaction[]): QueryHint {
......
// Libraries
import _ from 'lodash'; import _ from 'lodash';
import { ThunkAction } from 'redux-thunk'; import { ThunkAction } from 'redux-thunk';
import { RawTimeRange, TimeRange } from '@grafana/ui';
// Services & Utils
import store from 'app/core/store';
import { import {
LAST_USED_DATASOURCE_KEY, LAST_USED_DATASOURCE_KEY,
clearQueryKeys, clearQueryKeys,
...@@ -14,10 +16,12 @@ import { ...@@ -14,10 +16,12 @@ import {
serializeStateToUrlParam, serializeStateToUrlParam,
} from 'app/core/utils/explore'; } from 'app/core/utils/explore';
// Actions
import { updateLocation } from 'app/core/actions'; import { updateLocation } from 'app/core/actions';
import store from 'app/core/store';
// Types
import { StoreState } from 'app/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 { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
import { import {
ExploreId, ExploreId,
...@@ -26,11 +30,10 @@ import { ...@@ -26,11 +30,10 @@ import {
ResultType, ResultType,
QueryOptions, QueryOptions,
QueryTransaction, QueryTransaction,
QueryHint,
QueryHintGetter,
} from 'app/types/explore'; } from 'app/types/explore';
import { Emitter } from 'app/core/core';
import { Emitter } from 'app/core/core';
import { RawTimeRange, TimeRange } from '@grafana/ui';
import { import {
Action as ThunkableAction, Action as ThunkableAction,
ActionTypes, ActionTypes,
...@@ -45,6 +48,7 @@ import { ...@@ -45,6 +48,7 @@ import {
ScanStopAction, ScanStopAction,
} from './actionTypes'; } from './actionTypes';
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, ThunkableAction>; type ThunkResult<R> = ThunkAction<R, StoreState, undefined, ThunkableAction>;
/** /**
...@@ -460,7 +464,7 @@ export function queryTransactionSuccess( ...@@ -460,7 +464,7 @@ export function queryTransactionSuccess(
// Get query hints // Get query hints
let hints: QueryHint[]; let hints: QueryHint[];
if (datasourceInstance.getQueryHints as QueryHintGetter) { if (datasourceInstance.getQueryHints) {
hints = datasourceInstance.getQueryHints(transaction.query, result); hints = datasourceInstance.getQueryHints(transaction.query, result);
} }
......
import _ from 'lodash'; import _ from 'lodash';
import { QueryHint } from '@grafana/ui/src/types';
import { QueryHint } from 'app/types/explore';
/** /**
* Number of time series results needed before starting to suggest sum aggregation hints * Number of time series results needed before starting to suggest sum aggregation hints
......
import { Value } from 'slate'; 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 { Emitter } from 'app/core/core';
import { LogsModel } from 'app/core/logs_model'; import { LogsModel } from 'app/core/logs_model';
...@@ -110,7 +110,7 @@ export interface ExploreItemState { ...@@ -110,7 +110,7 @@ export interface ExploreItemState {
/** /**
* Datasource instance that has been selected. Datasource-specific logic can be run on this object. * 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. * Error to be shown when datasource loading or testing failed.
*/ */
...@@ -273,28 +273,6 @@ export interface TypeaheadOutput { ...@@ -273,28 +273,6 @@ export interface TypeaheadOutput {
suggestions: CompletionItemGroup[]; 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 { export interface QueryIntervals {
interval: string; interval: string;
intervalMs: number; intervalMs: number;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment