Commit 05f9eb07 by Dominik Prokop

Update datasource before the loading has started

parent c7b556c0
// Types // Types
import { Emitter } from 'app/core/core'; import { Emitter } from 'app/core/core';
import { RawTimeRange, TimeRange, DataQuery, DataSourceSelectItem } from '@grafana/ui/src/types'; import { RawTimeRange, TimeRange, DataQuery, DataSourceSelectItem, DataSourceApi } from '@grafana/ui/src/types';
import { import {
ExploreId, ExploreId,
ExploreItemState, ExploreItemState,
...@@ -41,6 +41,7 @@ export enum ActionTypes { ...@@ -41,6 +41,7 @@ export enum ActionTypes {
ToggleGraph = 'explore/TOGGLE_GRAPH', ToggleGraph = 'explore/TOGGLE_GRAPH',
ToggleLogs = 'explore/TOGGLE_LOGS', ToggleLogs = 'explore/TOGGLE_LOGS',
ToggleTable = 'explore/TOGGLE_TABLE', ToggleTable = 'explore/TOGGLE_TABLE',
UpdateDatasourceInstance = 'explore/UPDATE_DATASOURCE_INSTANCE',
} }
export interface AddQueryRowAction { export interface AddQueryRowAction {
...@@ -270,6 +271,14 @@ export interface ToggleLogsAction { ...@@ -270,6 +271,14 @@ export interface ToggleLogsAction {
}; };
} }
export interface UpdateDatasourceInstanceAction {
type: ActionTypes.UpdateDatasourceInstance;
payload: {
exploreId: ExploreId;
datasourceInstance: DataSourceApi;
};
}
export type Action = export type Action =
| AddQueryRowAction | AddQueryRowAction
| ChangeQueryAction | ChangeQueryAction
...@@ -297,4 +306,5 @@ export type Action = ...@@ -297,4 +306,5 @@ export type Action =
| SplitOpenAction | SplitOpenAction
| ToggleGraphAction | ToggleGraphAction
| ToggleLogsAction | ToggleLogsAction
| ToggleTableAction; | ToggleTableAction
| UpdateDatasourceInstanceAction;
...@@ -21,7 +21,7 @@ import { updateLocation } from 'app/core/actions'; ...@@ -21,7 +21,7 @@ import { updateLocation } from 'app/core/actions';
// Types // Types
import { StoreState } from 'app/types'; import { StoreState } from 'app/types';
import { DataQuery, DataSourceSelectItem, QueryHint } 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,
...@@ -46,9 +46,9 @@ import { ...@@ -46,9 +46,9 @@ import {
LoadDatasourceSuccessAction, LoadDatasourceSuccessAction,
QueryTransactionStartAction, QueryTransactionStartAction,
ScanStopAction, ScanStopAction,
UpdateDatasourceInstanceAction,
} from './actionTypes'; } from './actionTypes';
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, ThunkableAction>; type ThunkResult<R> = ThunkAction<R, StoreState, undefined, ThunkableAction>;
/** /**
...@@ -65,6 +65,7 @@ export function addQueryRow(exploreId: ExploreId, index: number): AddQueryRowAct ...@@ -65,6 +65,7 @@ export function addQueryRow(exploreId: ExploreId, index: number): AddQueryRowAct
export function changeDatasource(exploreId: ExploreId, datasource: string): ThunkResult<void> { export function changeDatasource(exploreId: ExploreId, datasource: string): ThunkResult<void> {
return async dispatch => { return async dispatch => {
const instance = await getDatasourceSrv().get(datasource); const instance = await getDatasourceSrv().get(datasource);
dispatch(updateDatasourceInstance(exploreId, instance));
dispatch(loadDatasource(exploreId, instance)); dispatch(loadDatasource(exploreId, instance));
}; };
} }
...@@ -264,6 +265,22 @@ export const loadDatasourceSuccess = ( ...@@ -264,6 +265,22 @@ export const loadDatasourceSuccess = (
}; };
/** /**
* Updates datasource instance before datasouce loading has started
*/
export function updateDatasourceInstance(
exploreId: ExploreId,
instance: DataSourceApi
): UpdateDatasourceInstanceAction {
return {
type: ActionTypes.UpdateDatasourceInstance,
payload: {
exploreId,
datasourceInstance: instance,
},
};
}
/**
* Main action to asynchronously load a datasource. Dispatches lots of smaller actions for feedback. * Main action to asynchronously load a datasource. Dispatches lots of smaller actions for feedback.
*/ */
export function loadDatasource(exploreId: ExploreId, instance: DataSourceApi): ThunkResult<void> { export function loadDatasource(exploreId: ExploreId, instance: DataSourceApi): ThunkResult<void> {
......
...@@ -176,6 +176,14 @@ export const itemReducer = (state, action: Action): ExploreItemState => { ...@@ -176,6 +176,14 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
}; };
} }
case ActionTypes.UpdateDatasourceInstance: {
const { datasourceInstance } = action.payload;
return {
...state,
datasourceInstance,
};
}
case ActionTypes.LoadDatasourceFailure: { case ActionTypes.LoadDatasourceFailure: {
return { ...state, datasourceError: action.payload.error, datasourceLoading: false }; return { ...state, datasourceError: action.payload.error, datasourceLoading: false };
} }
......
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