mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Hotkeys: Make time range permanent (#43802)
Typing `t a` in Explore or Dashboards will turn a relative time like "Last 1 hour" into an absolute range to make the URL permanent, so that when sharing it others will see the same data. - registered `t a` in key service - new `AbsoluteTimeEvent` dispatch via global event bus - dashboard times handled in TimeSrv - Explore times handled in Explore.tsx and Explore's time reducer I could not find an easy way to combine time handling for Exlore and Dashboard in one place.
This commit is contained in:
@@ -14,7 +14,7 @@ import { getShiftedTimeRange, getZoomedTimeRange } from 'app/core/utils/timePick
|
||||
import { config } from 'app/core/config';
|
||||
import { getRefreshFromUrl } from '../utils/getRefreshFromUrl';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import { ShiftTimeEvent, ShiftTimeEventPayload, ZoomOutEvent } from '../../../types/events';
|
||||
import { AbsoluteTimeEvent, ShiftTimeEvent, ShiftTimeEventPayload, ZoomOutEvent } from '../../../types/events';
|
||||
import { contextSrv, ContextSrv } from 'app/core/services/context_srv';
|
||||
import appEvents from 'app/core/app_events';
|
||||
|
||||
@@ -41,6 +41,10 @@ export class TimeSrv {
|
||||
this.shiftTime(e.payload);
|
||||
});
|
||||
|
||||
appEvents.subscribe(AbsoluteTimeEvent, () => {
|
||||
this.makeAbsoluteTime();
|
||||
});
|
||||
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (this.autoRefreshBlocked && document.visibilityState === 'visible') {
|
||||
this.autoRefreshBlocked = false;
|
||||
@@ -348,6 +352,16 @@ export class TimeSrv {
|
||||
});
|
||||
}
|
||||
|
||||
makeAbsoluteTime() {
|
||||
const params = locationService.getSearch();
|
||||
if (params.get('left')) {
|
||||
return; // explore handles this;
|
||||
}
|
||||
|
||||
const { from, to } = this.timeRange();
|
||||
this.setTime({ from, to });
|
||||
}
|
||||
|
||||
// isRefreshOutsideThreshold function calculates the difference between last refresh and now
|
||||
// if the difference is outside 5% of the current set time range then the function will return true
|
||||
// if the difference is within 5% of the current set time range then the function will return false
|
||||
|
||||
Reference in New Issue
Block a user