From 40fbea977edb6f218ad4b16004d418ee9708be87 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Fri, 27 Sep 2019 10:17:07 +0200 Subject: [PATCH] Explore: Take root_url setting into account when redirecting from dashboard to explore (#19447) * Explore: Take root_url setting into account when redirecting from dashboard to explore * Explore: Move adding of subath to getExploreUrl function * Explore: Fix explore redirect for key bindings --- public/app/core/services/keybindingSrv.ts | 7 +++++-- public/app/core/utils/explore.ts | 3 ++- public/app/features/panel/metrics_panel_ctrl.ts | 7 ------- public/app/features/panel/specs/metrics_panel_ctrl.test.ts | 3 +++ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index b1700f3d33d..0cdfa731f92 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -3,6 +3,7 @@ import _ from 'lodash'; import coreModule from 'app/core/core_module'; import appEvents from 'app/core/app_events'; import { getExploreUrl } from 'app/core/utils/explore'; +import locationUtil from 'app/core/utils/location_util'; import { store } from 'app/store/store'; import Mousetrap from 'mousetrap'; @@ -220,8 +221,10 @@ export class KeybindingSrv { const panel = dashboard.getPanelById(dashboard.meta.focusPanelId); const datasource = await this.datasourceSrv.get(panel.datasource); const url = await getExploreUrl(panel, panel.targets, datasource, this.datasourceSrv, this.timeSrv); - if (url) { - this.$timeout(() => this.$location.url(url)); + const urlWithoutBase = locationUtil.stripBaseFromUrl(url); + + if (urlWithoutBase) { + this.$timeout(() => this.$location.url(urlWithoutBase)); } } }); diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index 493372f1bca..0f8a0db60c7 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -90,7 +90,8 @@ export async function getExploreUrl( const exploreState = JSON.stringify({ ...state, originPanelId: panel.id }); url = renderUrl('/explore', { left: exploreState }); } - return url; + const finalUrl = config.appSubUrl + url; + return finalUrl; } export function buildQueryTransaction( diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index ee13a440830..5dc612f86c7 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -251,13 +251,6 @@ class MetricsPanelCtrl extends PanelCtrl { } return items; } - - async explore() { - const url = await getExploreUrl(this.panel, this.panel.targets, this.datasource, this.datasourceSrv, this.timeSrv); - if (url) { - this.$timeout(() => this.$location.url(url)); - } - } } export { MetricsPanelCtrl }; diff --git a/public/app/features/panel/specs/metrics_panel_ctrl.test.ts b/public/app/features/panel/specs/metrics_panel_ctrl.test.ts index 061f361880e..3acbb694b74 100644 --- a/public/app/features/panel/specs/metrics_panel_ctrl.test.ts +++ b/public/app/features/panel/specs/metrics_panel_ctrl.test.ts @@ -10,6 +10,9 @@ jest.mock('app/core/config', () => { name: 'test', }, }, + config: { + appSubUrl: 'test', + }, }; });