[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 315778227b)

Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com>
pull/94984/head
grafana-delivery-bot[bot] 8 months ago committed by GitHub
parent df57ba1b70
commit 060846d056
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 26
      public/app/core/utils/explore.test.ts
  2. 3
      public/app/core/utils/explore.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', () => {

@ -12,6 +12,7 @@ import {
DefaultTimeZone,
getNextRefId,
IntervalValues,
locationUtil,
LogsDedupStrategy,
LogsSortOrder,
rangeUtil,
@ -94,7 +95,7 @@ export async function getExploreUrl(args: GetExploreUrlArguments): Promise<strin
const exploreState = JSON.stringify({
[generateExploreId()]: { range: toURLRange(timeRange.raw), queries: interpolatedQueries, datasource: dsRef?.uid },
});
return urlUtil.renderUrl('/explore', { panes: exploreState, schemaVersion: 1 });
return locationUtil.assureBaseUrl(urlUtil.renderUrl('/explore', { panes: exploreState, schemaVersion: 1 }));
}
export function requestIdGenerator(exploreId: string) {

Loading…
Cancel
Save