From 79bd7f4077dae4312bf407d1b2797b934c03d050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 21 Jan 2019 21:36:30 +0100 Subject: [PATCH] Fixed data source selection in explore --- .../app/features/explore/state/actionTypes.ts | 2 +- public/app/features/explore/state/actions.ts | 17 +++++++++-------- public/app/features/explore/state/reducers.ts | 3 ++- public/app/types/explore.ts | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/public/app/features/explore/state/actionTypes.ts b/public/app/features/explore/state/actionTypes.ts index 850f2137541..4e1d658f072 100644 --- a/public/app/features/explore/state/actionTypes.ts +++ b/public/app/features/explore/state/actionTypes.ts @@ -123,7 +123,7 @@ export interface LoadDatasourcePendingAction { type: ActionTypes.LoadDatasourcePending; payload: { exploreId: ExploreId; - datasourceId: number; + datasourceName: string; }; } diff --git a/public/app/features/explore/state/actions.ts b/public/app/features/explore/state/actions.ts index 34169a999a3..d4c42ffa9c7 100644 --- a/public/app/features/explore/state/actions.ts +++ b/public/app/features/explore/state/actions.ts @@ -33,7 +33,7 @@ import { } from 'app/types/explore'; import { Emitter } from 'app/core/core'; -import { RawTimeRange, TimeRange } from '@grafana/ui'; +import { RawTimeRange, TimeRange, DataSourceApi } from '@grafana/ui'; import { Action as ThunkableAction, ActionTypes, @@ -216,11 +216,11 @@ export const loadDatasourceMissing = (exploreId: ExploreId): LoadDatasourceMissi /** * 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, payload: { exploreId, - datasourceId, + datasourceName, }, }); @@ -266,12 +266,12 @@ export const loadDatasourceSuccess = ( /** * Main action to asynchronously load a datasource. Dispatches lots of smaller actions for feedback. */ -export function loadDatasource(exploreId: ExploreId, instance: any): ThunkResult { +export function loadDatasource(exploreId: ExploreId, instance: DataSourceApi): ThunkResult { return async (dispatch, getState) => { - const datasourceId = instance.meta.id; + const datasourceName = instance.name; // Keep ID to track selection - dispatch(loadDatasourcePending(exploreId, datasourceId)); + dispatch(loadDatasourcePending(exploreId, datasourceName)); let datasourceError = null; try { @@ -280,12 +280,13 @@ export function loadDatasource(exploreId: ExploreId, instance: any): ThunkResult } catch (error) { datasourceError = (error && error.statusText) || 'Network error'; } + if (datasourceError) { dispatch(loadDatasourceFailure(exploreId, datasourceError)); return; } - if (datasourceId !== getState().explore[exploreId].requestedDatasourceId) { + if (datasourceName !== getState().explore[exploreId].requestedDatasourceName) { // User already changed datasource again, discard results return; } @@ -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 return; } diff --git a/public/app/features/explore/state/reducers.ts b/public/app/features/explore/state/reducers.ts index ba87e8818df..8acf52340c9 100644 --- a/public/app/features/explore/state/reducers.ts +++ b/public/app/features/explore/state/reducers.ts @@ -185,7 +185,7 @@ const itemReducer = (state, action: Action): ExploreItemState => { } case ActionTypes.LoadDatasourcePending: { - return { ...state, datasourceLoading: true, requestedDatasourceId: action.payload.datasourceId }; + return { ...state, datasourceLoading: true, requestedDatasourceName: action.payload.datasourceName }; } case ActionTypes.LoadDatasourceSuccess: { @@ -217,6 +217,7 @@ const itemReducer = (state, action: Action): ExploreItemState => { supportsTable, datasourceLoading: false, datasourceMissing: false, + datasourceError: null, logsHighlighterExpressions: undefined, modifiedQueries: initialQueries.slice(), queryTransactions: [], diff --git a/public/app/types/explore.ts b/public/app/types/explore.ts index c69e93ff88e..ce5ea1047dd 100644 --- a/public/app/types/explore.ts +++ b/public/app/types/explore.ts @@ -186,7 +186,7 @@ export interface ExploreItemState { * Allows the selection to be discarded if something went wrong during the asynchronous * loading of the datasource. */ - requestedDatasourceId?: number; + requestedDatasourceName?: string; /** * Time range for this Explore. Managed by the time picker and used by all query runs. */