From 53eb856d2086a9254897becaf03e5ce264e25a8e Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Thu, 9 Jul 2020 11:21:45 +0200 Subject: [PATCH] Explore: Run query on splitOpen action (#26161) --- public/app/features/explore/ExploreToolbar.tsx | 2 +- .../explore/RichHistory/RichHistoryCard.tsx | 2 +- public/app/features/explore/state/actions.ts | 13 ++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/public/app/features/explore/ExploreToolbar.tsx b/public/app/features/explore/ExploreToolbar.tsx index 2a050592f13..c3d6bec7053 100644 --- a/public/app/features/explore/ExploreToolbar.tsx +++ b/public/app/features/explore/ExploreToolbar.tsx @@ -91,7 +91,7 @@ type Props = StateProps & DispatchProps & OwnProps; export class UnConnectedExploreToolbar extends PureComponent { onChangeDatasource = async (option: { value: any }) => { - this.props.changeDatasource(this.props.exploreId, option.value); + this.props.changeDatasource(this.props.exploreId, option.value, { importQueries: true }); }; onClearAll = () => { diff --git a/public/app/features/explore/RichHistory/RichHistoryCard.tsx b/public/app/features/explore/RichHistory/RichHistoryCard.tsx index b04153862ba..89ebaeb36d1 100644 --- a/public/app/features/explore/RichHistory/RichHistoryCard.tsx +++ b/public/app/features/explore/RichHistory/RichHistoryCard.tsx @@ -163,7 +163,7 @@ export function RichHistoryCard(props: Props) { const onRunQuery = async () => { const queriesToRun = query.queries; if (query.datasourceName !== datasourceInstance?.name) { - await changeDatasource(exploreId, query.datasourceName); + await changeDatasource(exploreId, query.datasourceName, { importQueries: true }); setQueries(exploreId, queriesToRun); } else { setQueries(exploreId, queriesToRun); diff --git a/public/app/features/explore/state/actions.ts b/public/app/features/explore/state/actions.ts index b4db347e723..8ceae57c4b1 100644 --- a/public/app/features/explore/state/actions.ts +++ b/public/app/features/explore/state/actions.ts @@ -122,7 +122,11 @@ export function addQueryRow(exploreId: ExploreId, index: number): ThunkResult { +export function changeDatasource( + exploreId: ExploreId, + datasourceName: string, + options?: { importQueries: boolean } +): ThunkResult { return async (dispatch, getState) => { let newDataSourceInstance: DataSourceApi; @@ -150,7 +154,9 @@ export function changeDatasource(exploreId: ExploreId, datasourceName: string): }) ); - await dispatch(importQueries(exploreId, queries, currentDataSourceInstance, newDataSourceInstance)); + if (options?.importQueries) { + await dispatch(importQueries(exploreId, queries, currentDataSourceInstance, newDataSourceInstance)); + } if (getState().explore[exploreId].isLive) { dispatch(changeRefreshInterval(exploreId, RefreshPicker.offOption.value)); @@ -268,7 +274,7 @@ export function loadExploreDatasourcesAndSetDatasource( const exploreDatasources = getExploreDatasources(); if (exploreDatasources.length >= 1) { - await dispatch(changeDatasource(exploreId, datasourceName)); + await dispatch(changeDatasource(exploreId, datasourceName, { importQueries: true })); dispatch(runQueries(exploreId)); } else { dispatch(loadDatasourceMissingAction({ exploreId })); @@ -729,6 +735,7 @@ export function splitOpen(options?: { datasourceUid: const dataSourceSettings = getDatasourceSrv().getDataSourceSettingsByUid(options.datasourceUid); await dispatch(changeDatasource(ExploreId.right, dataSourceSettings.name)); await dispatch(setQueriesAction({ exploreId: ExploreId.right, queries })); + await dispatch(runQueries(ExploreId.right)); } else { rightState.queries = leftState.queries.slice(); rightState.urlState = urlState;