From 89618e0c0fba3ed4499da61c322229eb3f993e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Jamr=C3=B3z?= Date: Mon, 31 Jul 2023 14:11:44 +0200 Subject: [PATCH] Explore: Do not update URL when time range changes to absolute (#72436) Allow passing updateURL flag to absolute time range event --- public/app/core/services/keybindingSrv.ts | 9 ++++----- public/app/features/dashboard/services/TimeSrv.ts | 13 ++++--------- public/app/types/events.ts | 6 +++++- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index 9553f37d0de..44c30b6a6d8 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -45,7 +45,6 @@ export class KeybindingSrv { this.bind('g e', this.goToExplore); this.bind('g a', this.openAlerting); this.bind('g p', this.goToProfile); - this.bind('t a', this.makeAbsoluteTime); this.bind('esc', this.exit); this.bindGlobalEsc(); } @@ -108,10 +107,6 @@ export class KeybindingSrv { this.locationService.push('/explore'); } - private makeAbsoluteTime() { - appEvents.publish(new AbsoluteTimeEvent()); - } - private showHelpModal() { appEvents.publish(new ShowModalReactEvent({ component: HelpModal })); } @@ -190,6 +185,10 @@ export class KeybindingSrv { } setupTimeRangeBindings(updateUrl = true) { + this.bind('t a', () => { + appEvents.publish(new AbsoluteTimeEvent({ updateUrl })); + }); + this.bind('t z', () => { appEvents.publish(new ZoomOutEvent({ scale: 2, updateUrl })); }); diff --git a/public/app/features/dashboard/services/TimeSrv.ts b/public/app/features/dashboard/services/TimeSrv.ts index 41b7a68b655..073f707feb0 100644 --- a/public/app/features/dashboard/services/TimeSrv.ts +++ b/public/app/features/dashboard/services/TimeSrv.ts @@ -46,8 +46,8 @@ export class TimeSrv { this.shiftTime(e.payload.direction, e.payload.updateUrl); }); - appEvents.subscribe(AbsoluteTimeEvent, () => { - this.makeAbsoluteTime(); + appEvents.subscribe(AbsoluteTimeEvent, (e) => { + this.makeAbsoluteTime(e.payload.updateUrl); }); document.addEventListener('visibilitychange', () => { @@ -364,14 +364,9 @@ export class TimeSrv { ); } - makeAbsoluteTime() { - const params = locationService.getSearch(); - if (params.get('left')) { - return; // explore handles this; - } - + makeAbsoluteTime(updateUrl: boolean) { const { from, to } = this.timeRange(); - this.setTime({ from, to }, true); + this.setTime({ from, to }, updateUrl); } // isRefreshOutsideThreshold function calculates the difference between last refresh and now diff --git a/public/app/types/events.ts b/public/app/types/events.ts index 882cd3df12f..6f3e86e5134 100644 --- a/public/app/types/events.ts +++ b/public/app/types/events.ts @@ -160,7 +160,11 @@ export class ShiftTimeEvent extends BusEventWithPayload { static type = 'shift-time'; } -export class AbsoluteTimeEvent extends BusEventBase { +interface AbsoluteTimeEventPayload { + updateUrl: boolean; +} + +export class AbsoluteTimeEvent extends BusEventWithPayload { static type = 'absolute-time'; }