From b11eeadbd98b41f84171d39e9ba41c7e3ce0f460 Mon Sep 17 00:00:00 2001 From: Johannes Schill Date: Thu, 16 May 2019 11:02:21 +0200 Subject: [PATCH] fix: Initial url update in Explore should replace existing url history #17030 (#17061) --- public/app/features/explore/state/actions.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/public/app/features/explore/state/actions.ts b/public/app/features/explore/state/actions.ts index 838685d5a47..310f310e671 100644 --- a/public/app/features/explore/state/actions.ts +++ b/public/app/features/explore/state/actions.ts @@ -119,7 +119,7 @@ export function addQueryRow(exploreId: ExploreId, index: number): ThunkResult { +export function changeDatasource(exploreId: ExploreId, datasource: string, replaceUrl = false): ThunkResult { return async (dispatch, getState) => { let newDataSourceInstance: DataSourceApi = null; @@ -137,8 +137,7 @@ export function changeDatasource(exploreId: ExploreId, datasource: string): Thun dispatch(updateDatasourceInstanceAction({ exploreId, datasourceInstance: newDataSourceInstance })); await dispatch(loadDatasource(exploreId, newDataSourceInstance)); - - dispatch(runQueries(exploreId)); + dispatch(runQueries(exploreId, false, replaceUrl)); }; } @@ -244,7 +243,7 @@ export function loadExploreDatasourcesAndSetDatasource( dispatch(loadExploreDatasources({ exploreId, exploreDatasources })); if (exploreDatasources.length >= 1) { - dispatch(changeDatasource(exploreId, datasourceName)); + dispatch(changeDatasource(exploreId, datasourceName, true)); } else { dispatch(loadDatasourceMissingAction({ exploreId })); } @@ -513,7 +512,7 @@ export function processQueryResults( /** * Main action to run queries and dispatches sub-actions based on which result viewers are active */ -export function runQueries(exploreId: ExploreId, ignoreUIState = false): ThunkResult { +export function runQueries(exploreId: ExploreId, ignoreUIState = false, replaceUrl = false): ThunkResult { return (dispatch, getState) => { const { datasourceInstance, @@ -533,7 +532,7 @@ export function runQueries(exploreId: ExploreId, ignoreUIState = false): ThunkRe if (!hasNonEmptyQuery(queries)) { dispatch(clearQueriesAction({ exploreId })); - dispatch(stateSave()); // Remember to saves to state and update location + dispatch(stateSave(replaceUrl)); // Remember to save to state and update location return; } @@ -567,7 +566,7 @@ export function runQueries(exploreId: ExploreId, ignoreUIState = false): ThunkRe dispatch(runQueriesForType(exploreId, 'Logs', { interval, format: 'logs' })); } - dispatch(stateSave()); + dispatch(stateSave(replaceUrl)); }; } @@ -691,7 +690,7 @@ const toRawTimeRange = (range: TimeRange): RawTimeRange => { * Saves Explore state to URL using the `left` and `right` parameters. * If split view is not active, `right` will not be set. */ -export function stateSave(): ThunkResult { +export function stateSave(replaceUrl = false): ThunkResult { return (dispatch, getState) => { const { left, right, split } = getState().explore; const urlStates: { [index: string]: string } = {}; @@ -723,7 +722,7 @@ export function stateSave(): ThunkResult { urlStates.right = serializeStateToUrlParam(rightUrlState, true); } - dispatch(updateLocation({ query: urlStates })); + dispatch(updateLocation({ query: urlStates, replace: replaceUrl })); }; }