From 060846d056537304b644548e8a8f101c4ad17d87 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:38:26 +0300 Subject: [PATCH] [v11.3.x] Dashboards: Links to explore should respect subpath (#94975) Dashboards: Links to explore should respect subpath (#94525) * Links to explore should respect subpath * Change to using assureBaseUrl * Change back to normal single quotes (cherry picked from commit 315778227b010f2d929ebbf9d8617154f4f1373c) Co-authored-by: Oscar Kilhed --- public/app/core/utils/explore.test.ts | 26 +++++++++++++++++++++++++- public/app/core/utils/explore.ts | 3 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/public/app/core/utils/explore.test.ts b/public/app/core/utils/explore.test.ts index 82bac2e5764..75da07f4577 100644 --- a/public/app/core/utils/explore.test.ts +++ b/public/app/core/utils/explore.test.ts @@ -1,8 +1,11 @@ -import { DataSourceApi, dateTime, ExploreUrlState, LogsSortOrder } from '@grafana/data'; +import { DataSourceApi, dateTime, ExploreUrlState, GrafanaConfig, locationUtil, LogsSortOrder } from '@grafana/data'; import { serializeStateToUrlParam } from '@grafana/data/src/utils/url'; +import { config } from '@grafana/runtime'; import { DataQuery } from '@grafana/schema'; import { RefreshPicker } from '@grafana/ui'; +import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { DEFAULT_RANGE } from 'app/features/explore/state/utils'; +import { getVariablesUrlParams } from 'app/features/variables/getAllVariableValuesForUrl'; import { DatasourceSrvMock, MockDataSourceApi } from '../../../test/mocks/datasource_srv'; @@ -152,6 +155,27 @@ describe('getExploreUrl', () => { expect(interpolateMockLoki).toBeCalled(); expect(interpolateMockProm).toBeCalled(); }); + + describe('subpath', () => { + beforeAll(() => { + locationUtil.initialize({ + config: { appSubUrl: '/subpath' } as GrafanaConfig, + getVariablesUrlParams: jest.fn(), + getTimeRangeForUrl: jest.fn(), + }); + }); + afterAll(() => { + // Reset locationUtil + locationUtil.initialize({ + config, + getTimeRangeForUrl: getTimeSrv().timeRangeForUrl, + getVariablesUrlParams: getVariablesUrlParams, + }); + }); + it('should work with sub path', async () => { + expect(await getExploreUrl(args)).toMatch(/subpath\/explore/g); + }); + }); }); describe('hasNonEmptyQuery', () => { diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index af320c4c6ec..cb22e191a77 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -12,6 +12,7 @@ import { DefaultTimeZone, getNextRefId, IntervalValues, + locationUtil, LogsDedupStrategy, LogsSortOrder, rangeUtil, @@ -94,7 +95,7 @@ export async function getExploreUrl(args: GetExploreUrlArguments): Promise