Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ShareableUrl): Fix link generation when the default time range is selected #244

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ describe('builsShareableUrl()', () => {
});

test.each([
['identity', new URL(BASE_URL), BASE_URL],
['no params', new URL(BASE_URL), `${BASE_URL}&from=1729250533247&to=1729252333247`],
['relative from/to', new URL(`${BASE_URL}&from=now-30m&to=now`), `${BASE_URL}&from=1729250533247&to=1729252333247`],
[
'relative from-x/to-x',
new URL(`${BASE_URL}&from-2=now-20m&to-2=now-10m&from-3=now-15m&to-3=now-5m`),
`${BASE_URL}&from-2=1729251133247&to-2=1729251733247&from-3=1729251433247&to-3=1729252033247`,
`${BASE_URL}&from-2=1729251133247&to-2=1729251733247&from-3=1729251433247&to-3=1729252033247&from=1729250533247&to=1729252333247`,
],
[
'relative diffFrom-x/diffTo-x',
new URL(`${BASE_URL}&diffFrom=now-18m&diffTo=now-12m&diffFrom-2=now-7m&diffTo-2=now-3m`),
`${BASE_URL}&diffFrom=1729251253247&diffTo=1729251613247&diffFrom-2=1729251913247&diffTo-2=1729252153247`,
`${BASE_URL}&diffFrom=1729251253247&diffTo=1729251613247&diffFrom-2=1729251913247&diffTo-2=1729252153247&from=1729250533247&to=1729252333247`,
],
[
'absolute from/to',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { dateMath } from '@grafana/data';
import { getDefaultTimeRange } from 'src/pages/ProfilesExplorerView/domain/getDefaultTimeRange';

export function builsShareableUrl(): URL {
const shareableUrl = new URL(window.location.toString());
const { searchParams } = shareableUrl;

if (!searchParams.get('from')) {
searchParams.set('from', getDefaultTimeRange().from);
}
if (!searchParams.get('to')) {
searchParams.set('to', getDefaultTimeRange().to);
}

['from', 'to', 'from-2', 'to-2', 'from-3', 'to-3', 'diffFrom', 'diffTo', 'diffFrom-2', 'diffTo-2'].forEach((name) => {
const value = searchParams.get(name);
if (value) {
Expand Down
Loading