|
@@ -4,6 +4,8 @@ import { ThunkAction } from 'redux-thunk';
|
|
|
|
|
|
|
|
// Services & Utils
|
|
// Services & Utils
|
|
|
import store from 'app/core/store';
|
|
import store from 'app/core/store';
|
|
|
|
|
+import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
|
|
|
|
+import { Emitter } from 'app/core/core';
|
|
|
import {
|
|
import {
|
|
|
LAST_USED_DATASOURCE_KEY,
|
|
LAST_USED_DATASOURCE_KEY,
|
|
|
clearQueryKeys,
|
|
clearQueryKeys,
|
|
@@ -21,8 +23,14 @@ 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 { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ RawTimeRange,
|
|
|
|
|
+ TimeRange,
|
|
|
|
|
+ DataSourceApi,
|
|
|
|
|
+ DataQuery,
|
|
|
|
|
+ DataSourceSelectItem,
|
|
|
|
|
+ QueryHint,
|
|
|
|
|
+} from '@grafana/ui/src/types';
|
|
|
import {
|
|
import {
|
|
|
ExploreId,
|
|
ExploreId,
|
|
|
ExploreUrlState,
|
|
ExploreUrlState,
|
|
@@ -32,8 +40,6 @@ import {
|
|
|
QueryTransaction,
|
|
QueryTransaction,
|
|
|
} from 'app/types/explore';
|
|
} from 'app/types/explore';
|
|
|
|
|
|
|
|
-import { Emitter } from 'app/core/core';
|
|
|
|
|
-import { RawTimeRange, TimeRange, DataSourceApi } from '@grafana/ui';
|
|
|
|
|
import {
|
|
import {
|
|
|
Action as ThunkableAction,
|
|
Action as ThunkableAction,
|
|
|
ActionTypes,
|
|
ActionTypes,
|
|
@@ -46,6 +52,7 @@ 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>;
|
|
@@ -64,6 +71,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));
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
@@ -136,7 +144,7 @@ export function highlightLogsExpression(exploreId: ExploreId, expressions: strin
|
|
|
*/
|
|
*/
|
|
|
export function initializeExplore(
|
|
export function initializeExplore(
|
|
|
exploreId: ExploreId,
|
|
exploreId: ExploreId,
|
|
|
- datasource: string,
|
|
|
|
|
|
|
+ datasourceName: string,
|
|
|
queries: DataQuery[],
|
|
queries: DataQuery[],
|
|
|
range: RawTimeRange,
|
|
range: RawTimeRange,
|
|
|
containerWidth: number,
|
|
containerWidth: number,
|
|
@@ -156,7 +164,7 @@ export function initializeExplore(
|
|
|
payload: {
|
|
payload: {
|
|
|
exploreId,
|
|
exploreId,
|
|
|
containerWidth,
|
|
containerWidth,
|
|
|
- datasource,
|
|
|
|
|
|
|
+ datasourceName,
|
|
|
eventBridge,
|
|
eventBridge,
|
|
|
exploreDatasources,
|
|
exploreDatasources,
|
|
|
queries,
|
|
queries,
|
|
@@ -166,9 +174,9 @@ export function initializeExplore(
|
|
|
|
|
|
|
|
if (exploreDatasources.length >= 1) {
|
|
if (exploreDatasources.length >= 1) {
|
|
|
let instance;
|
|
let instance;
|
|
|
- if (datasource) {
|
|
|
|
|
|
|
+ if (datasourceName) {
|
|
|
try {
|
|
try {
|
|
|
- instance = await getDatasourceSrv().get(datasource);
|
|
|
|
|
|
|
+ instance = await getDatasourceSrv().get(datasourceName);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error(error);
|
|
console.error(error);
|
|
|
}
|
|
}
|
|
@@ -177,6 +185,7 @@ export function initializeExplore(
|
|
|
if (!instance) {
|
|
if (!instance) {
|
|
|
instance = await getDatasourceSrv().get();
|
|
instance = await getDatasourceSrv().get();
|
|
|
}
|
|
}
|
|
|
|
|
+ dispatch(updateDatasourceInstance(exploreId, instance));
|
|
|
dispatch(loadDatasource(exploreId, instance));
|
|
dispatch(loadDatasource(exploreId, instance));
|
|
|
} else {
|
|
} else {
|
|
|
dispatch(loadDatasourceMissing(exploreId));
|
|
dispatch(loadDatasourceMissing(exploreId));
|
|
@@ -215,11 +224,11 @@ export const loadDatasourceMissing = (exploreId: ExploreId): LoadDatasourceMissi
|
|
|
/**
|
|
/**
|
|
|
* Start the async process of loading a datasource to display a loading indicator
|
|
* Start the async process of loading a datasource to display a loading indicator
|
|
|
*/
|
|
*/
|
|
|
-export const loadDatasourcePending = (exploreId: ExploreId, datasourceName: string): LoadDatasourcePendingAction => ({
|
|
|
|
|
|
|
+export const loadDatasourcePending = (exploreId: ExploreId, requestedDatasourceName: string): LoadDatasourcePendingAction => ({
|
|
|
type: ActionTypes.LoadDatasourcePending,
|
|
type: ActionTypes.LoadDatasourcePending,
|
|
|
payload: {
|
|
payload: {
|
|
|
exploreId,
|
|
exploreId,
|
|
|
- datasourceName,
|
|
|
|
|
|
|
+ requestedDatasourceName,
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -252,7 +261,6 @@ export const loadDatasourceSuccess = (
|
|
|
StartPage,
|
|
StartPage,
|
|
|
datasourceInstance: instance,
|
|
datasourceInstance: instance,
|
|
|
history,
|
|
history,
|
|
|
- initialDatasource: instance.name,
|
|
|
|
|
initialQueries: queries,
|
|
initialQueries: queries,
|
|
|
showingStartPage: Boolean(StartPage),
|
|
showingStartPage: Boolean(StartPage),
|
|
|
supportsGraph,
|
|
supportsGraph,
|
|
@@ -262,6 +270,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.
|
|
|
*/
|
|
*/
|