Commit 5446f49f by Torkel Ödegaard Committed by GitHub

Merge pull request #14977 from grafana/explore-fix-datasource-selector

Fixed data source selection in explore
parents 9c8dea06 79bd7f40
...@@ -123,7 +123,7 @@ export interface LoadDatasourcePendingAction { ...@@ -123,7 +123,7 @@ export interface LoadDatasourcePendingAction {
type: ActionTypes.LoadDatasourcePending; type: ActionTypes.LoadDatasourcePending;
payload: { payload: {
exploreId: ExploreId; exploreId: ExploreId;
datasourceId: number; datasourceName: string;
}; };
} }
......
...@@ -33,7 +33,7 @@ import { ...@@ -33,7 +33,7 @@ import {
} 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 { RawTimeRange, TimeRange, DataSourceApi } from '@grafana/ui';
import { import {
Action as ThunkableAction, Action as ThunkableAction,
ActionTypes, ActionTypes,
...@@ -216,11 +216,11 @@ export const loadDatasourceMissing = (exploreId: ExploreId): LoadDatasourceMissi ...@@ -216,11 +216,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, datasourceId: number): LoadDatasourcePendingAction => ({ export const loadDatasourcePending = (exploreId: ExploreId, datasourceName: string): LoadDatasourcePendingAction => ({
type: ActionTypes.LoadDatasourcePending, type: ActionTypes.LoadDatasourcePending,
payload: { payload: {
exploreId, exploreId,
datasourceId, datasourceName,
}, },
}); });
...@@ -266,12 +266,12 @@ export const loadDatasourceSuccess = ( ...@@ -266,12 +266,12 @@ export const loadDatasourceSuccess = (
/** /**
* 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: any): ThunkResult<void> { export function loadDatasource(exploreId: ExploreId, instance: DataSourceApi): ThunkResult<void> {
return async (dispatch, getState) => { return async (dispatch, getState) => {
const datasourceId = instance.meta.id; const datasourceName = instance.name;
// Keep ID to track selection // Keep ID to track selection
dispatch(loadDatasourcePending(exploreId, datasourceId)); dispatch(loadDatasourcePending(exploreId, datasourceName));
let datasourceError = null; let datasourceError = null;
try { try {
...@@ -280,12 +280,13 @@ export function loadDatasource(exploreId: ExploreId, instance: any): ThunkResult ...@@ -280,12 +280,13 @@ export function loadDatasource(exploreId: ExploreId, instance: any): ThunkResult
} catch (error) { } catch (error) {
datasourceError = (error && error.statusText) || 'Network error'; datasourceError = (error && error.statusText) || 'Network error';
} }
if (datasourceError) { if (datasourceError) {
dispatch(loadDatasourceFailure(exploreId, datasourceError)); dispatch(loadDatasourceFailure(exploreId, datasourceError));
return; return;
} }
if (datasourceId !== getState().explore[exploreId].requestedDatasourceId) { if (datasourceName !== getState().explore[exploreId].requestedDatasourceName) {
// User already changed datasource again, discard results // User already changed datasource again, discard results
return; return;
} }
...@@ -311,7 +312,7 @@ export function loadDatasource(exploreId: ExploreId, instance: any): ThunkResult ...@@ -311,7 +312,7 @@ export function loadDatasource(exploreId: ExploreId, instance: any): ThunkResult
} }
} }
if (datasourceId !== getState().explore[exploreId].requestedDatasourceId) { if (datasourceName !== getState().explore[exploreId].requestedDatasourceName) {
// User already changed datasource again, discard results // User already changed datasource again, discard results
return; return;
} }
......
...@@ -185,7 +185,7 @@ const itemReducer = (state, action: Action): ExploreItemState => { ...@@ -185,7 +185,7 @@ const itemReducer = (state, action: Action): ExploreItemState => {
} }
case ActionTypes.LoadDatasourcePending: { case ActionTypes.LoadDatasourcePending: {
return { ...state, datasourceLoading: true, requestedDatasourceId: action.payload.datasourceId }; return { ...state, datasourceLoading: true, requestedDatasourceName: action.payload.datasourceName };
} }
case ActionTypes.LoadDatasourceSuccess: { case ActionTypes.LoadDatasourceSuccess: {
...@@ -217,6 +217,7 @@ const itemReducer = (state, action: Action): ExploreItemState => { ...@@ -217,6 +217,7 @@ const itemReducer = (state, action: Action): ExploreItemState => {
supportsTable, supportsTable,
datasourceLoading: false, datasourceLoading: false,
datasourceMissing: false, datasourceMissing: false,
datasourceError: null,
logsHighlighterExpressions: undefined, logsHighlighterExpressions: undefined,
modifiedQueries: initialQueries.slice(), modifiedQueries: initialQueries.slice(),
queryTransactions: [], queryTransactions: [],
......
...@@ -186,7 +186,7 @@ export interface ExploreItemState { ...@@ -186,7 +186,7 @@ export interface ExploreItemState {
* Allows the selection to be discarded if something went wrong during the asynchronous * Allows the selection to be discarded if something went wrong during the asynchronous
* loading of the datasource. * loading of the datasource.
*/ */
requestedDatasourceId?: number; requestedDatasourceName?: string;
/** /**
* Time range for this Explore. Managed by the time picker and used by all query runs. * Time range for this Explore. Managed by the time picker and used by all query runs.
*/ */
......
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