Commit 205e2acd by Torkel Ödegaard

Added data source type to explore state

parent a6f6ed41
......@@ -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<any>;
/**
* 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;
}
......@@ -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 {
......
// 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<R> = ThunkAction<R, StoreState, undefined, ThunkableAction>;
/**
......@@ -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);
}
......
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
......
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;
......
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