Commit 53eb856d by Andrej Ocenas Committed by GitHub

Explore: Run query on splitOpen action (#26161)

parent 0428f271
...@@ -91,7 +91,7 @@ type Props = StateProps & DispatchProps & OwnProps; ...@@ -91,7 +91,7 @@ type Props = StateProps & DispatchProps & OwnProps;
export class UnConnectedExploreToolbar extends PureComponent<Props> { export class UnConnectedExploreToolbar extends PureComponent<Props> {
onChangeDatasource = async (option: { value: any }) => { onChangeDatasource = async (option: { value: any }) => {
this.props.changeDatasource(this.props.exploreId, option.value); this.props.changeDatasource(this.props.exploreId, option.value, { importQueries: true });
}; };
onClearAll = () => { onClearAll = () => {
......
...@@ -163,7 +163,7 @@ export function RichHistoryCard(props: Props) { ...@@ -163,7 +163,7 @@ export function RichHistoryCard(props: Props) {
const onRunQuery = async () => { const onRunQuery = async () => {
const queriesToRun = query.queries; const queriesToRun = query.queries;
if (query.datasourceName !== datasourceInstance?.name) { if (query.datasourceName !== datasourceInstance?.name) {
await changeDatasource(exploreId, query.datasourceName); await changeDatasource(exploreId, query.datasourceName, { importQueries: true });
setQueries(exploreId, queriesToRun); setQueries(exploreId, queriesToRun);
} else { } else {
setQueries(exploreId, queriesToRun); setQueries(exploreId, queriesToRun);
......
...@@ -122,7 +122,11 @@ export function addQueryRow(exploreId: ExploreId, index: number): ThunkResult<vo ...@@ -122,7 +122,11 @@ export function addQueryRow(exploreId: ExploreId, index: number): ThunkResult<vo
/** /**
* Loads a new datasource identified by the given name. * Loads a new datasource identified by the given name.
*/ */
export function changeDatasource(exploreId: ExploreId, datasourceName: string): ThunkResult<void> { export function changeDatasource(
exploreId: ExploreId,
datasourceName: string,
options?: { importQueries: boolean }
): ThunkResult<void> {
return async (dispatch, getState) => { return async (dispatch, getState) => {
let newDataSourceInstance: DataSourceApi; let newDataSourceInstance: DataSourceApi;
...@@ -150,7 +154,9 @@ export function changeDatasource(exploreId: ExploreId, datasourceName: string): ...@@ -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) { if (getState().explore[exploreId].isLive) {
dispatch(changeRefreshInterval(exploreId, RefreshPicker.offOption.value)); dispatch(changeRefreshInterval(exploreId, RefreshPicker.offOption.value));
...@@ -268,7 +274,7 @@ export function loadExploreDatasourcesAndSetDatasource( ...@@ -268,7 +274,7 @@ export function loadExploreDatasourcesAndSetDatasource(
const exploreDatasources = getExploreDatasources(); const exploreDatasources = getExploreDatasources();
if (exploreDatasources.length >= 1) { if (exploreDatasources.length >= 1) {
await dispatch(changeDatasource(exploreId, datasourceName)); await dispatch(changeDatasource(exploreId, datasourceName, { importQueries: true }));
dispatch(runQueries(exploreId)); dispatch(runQueries(exploreId));
} else { } else {
dispatch(loadDatasourceMissingAction({ exploreId })); dispatch(loadDatasourceMissingAction({ exploreId }));
...@@ -729,6 +735,7 @@ export function splitOpen<T extends DataQuery = any>(options?: { datasourceUid: ...@@ -729,6 +735,7 @@ export function splitOpen<T extends DataQuery = any>(options?: { datasourceUid:
const dataSourceSettings = getDatasourceSrv().getDataSourceSettingsByUid(options.datasourceUid); const dataSourceSettings = getDatasourceSrv().getDataSourceSettingsByUid(options.datasourceUid);
await dispatch(changeDatasource(ExploreId.right, dataSourceSettings.name)); await dispatch(changeDatasource(ExploreId.right, dataSourceSettings.name));
await dispatch(setQueriesAction({ exploreId: ExploreId.right, queries })); await dispatch(setQueriesAction({ exploreId: ExploreId.right, queries }));
await dispatch(runQueries(ExploreId.right));
} else { } else {
rightState.queries = leftState.queries.slice(); rightState.queries = leftState.queries.slice();
rightState.urlState = urlState; rightState.urlState = urlState;
......
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