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;
export class UnConnectedExploreToolbar extends PureComponent<Props> {
onChangeDatasource = async (option: { value: any }) => {
this.props.changeDatasource(this.props.exploreId, option.value);
this.props.changeDatasource(this.props.exploreId, option.value, { importQueries: true });
};
onClearAll = () => {
......
......@@ -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);
......
......@@ -122,7 +122,11 @@ export function addQueryRow(exploreId: ExploreId, index: number): ThunkResult<vo
/**
* 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) => {
let newDataSourceInstance: DataSourceApi;
......@@ -150,7 +154,9 @@ export function changeDatasource(exploreId: ExploreId, datasourceName: string):
})
);
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<T extends DataQuery = any>(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;
......
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