Share link: Use panel relative time for direct link rendered image (#74438)

* Use relative timerange for share link

* Fix time range
This commit is contained in:
Alex Khomenko 2023-09-07 12:41:21 +03:00 committed by GitHub
parent 8b00d7d7af
commit a14af5e680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,10 @@
import { dateTime, locationUtil, PanelModel, TimeRange, urlUtil } from '@grafana/data'; import { dateTime, locationUtil, TimeRange, urlUtil, rangeUtil } from '@grafana/data';
import { config } from '@grafana/runtime'; import { config } from '@grafana/runtime';
import { createShortLink } from 'app/core/utils/shortLinks'; import { createShortLink } from 'app/core/utils/shortLinks';
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { PanelModel } from '../../state';
export interface BuildParamsArgs { export interface BuildParamsArgs {
useCurrentTimeRange: boolean; useCurrentTimeRange: boolean;
selectedTheme?: string; selectedTheme?: string;
@ -21,9 +23,17 @@ export function buildParams({
orgId = config.bootData.user.orgId, orgId = config.bootData.user.orgId,
}: BuildParamsArgs): URLSearchParams { }: BuildParamsArgs): URLSearchParams {
const searchParams = new URLSearchParams(search); const searchParams = new URLSearchParams(search);
const relative = panel?.timeFrom;
searchParams.set('from', String(range.from.valueOf())); // Use panel's relative time if it's set
searchParams.set('to', String(range.to.valueOf())); if (relative) {
const { from, to } = rangeUtil.describeTextRange(relative);
searchParams.set('from', from);
searchParams.set('to', to);
} else {
searchParams.set('from', String(range.from.valueOf()));
searchParams.set('to', String(range.to.valueOf()));
}
searchParams.set('orgId', String(orgId)); searchParams.set('orgId', String(orgId));
if (!useCurrentTimeRange) { if (!useCurrentTimeRange) {