mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 11:02:55 +08:00
Dashboards: Links to explore should respect subpath (#94525)
* Links to explore should respect subpath * Change to using assureBaseUrl * Change back to normal single quotes
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user