Explore: Improve parsing ranges from URL (#72498)

* Fix parsing absolute range

* Silence warning issued by moment js

* Introduce URLRangeValue to enforce better type-checking

* Fix unit tests

* Allow not passing range to generate ExploreUrl

* Use updated time range format in a test

* Allow empty object to be passed as a data link for backward compatibility

* Update mocks

* Post-merge fixes

* Simplify checking if range is passed as an empty object

* Update docs
This commit is contained in:
Piotr Jamróz
2023-08-17 12:06:52 +02:00
committed by GitHub
parent 654d99fbca
commit ab451d76ac
14 changed files with 155 additions and 126 deletions

View File

@@ -87,7 +87,7 @@ describe('getExploreUrl', () => {
getDataSourceById: jest.fn(),
},
timeSrv: {
timeRangeForUrl: () => '1',
timeRange: () => ({ raw: { from: 'now-1h', to: 'now' } }),
},
} as unknown as GetExploreUrlArguments;

View File

@@ -19,6 +19,7 @@ import {
RawTimeRange,
TimeRange,
TimeZone,
toURLRange,
urlUtil,
} from '@grafana/data';
import { DataSourceSrv, getDataSourceSrv } from '@grafana/runtime';
@@ -76,8 +77,8 @@ export async function getExploreUrl(args: GetExploreUrlArguments): Promise<strin
let url: string | undefined;
if (exploreDatasource) {
const range = timeSrv.timeRangeForUrl();
let state: Partial<ExploreUrlState> = { range };
const range = timeSrv.timeRange().raw;
let state: Partial<ExploreUrlState> = { range: toURLRange(range) };
if (exploreDatasource.interpolateVariablesInQueries) {
const scopedVars = panel.scopedVars || {};
state = {