Skip to content

Commit 04eefb8

Browse files
committed
fix(timepicker): fixed issue with timepicker and auto refresh and entering manual time when timepicker dropdown is open, fixes grafana#2897
1 parent 8789be7 commit 04eefb8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

public/app/features/dashboard/timeSrv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ define([
9494
_.extend(this.time, time);
9595

9696
// disable refresh if we have an absolute time
97-
if (_.isString(time.to) && time.to.indexOf('now') === -1) {
97+
if (moment.isMoment(time.to)) {
9898
this.old_refresh = this.dashboard.refresh || this.old_refresh;
9999
this.setAutoRefresh(false);
100100
}

public/app/features/dashboard/timepicker/timepicker.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ export class TimePickerCtrl {
3232
constructor(private $scope, private $rootScope, private timeSrv) {
3333
$scope.ctrl = this;
3434

35-
$rootScope.onAppEvent('refresh', () => this.init(), $scope);
3635
$rootScope.onAppEvent('zoom-out', () => this.zoom(2), $scope);
37-
$rootScope.onAppEvent('dash-editor-hidden', () => {
38-
this.isOpen = false;
39-
}, $scope);
36+
$rootScope.onAppEvent('refresh', () => this.init(), $scope);
37+
$rootScope.onAppEvent('dash-editor-hidden', () => this.isOpen = false, $scope);
4038

4139
this.init();
4240
}
@@ -64,9 +62,14 @@ export class TimePickerCtrl {
6462

6563
this.rangeString = rangeUtil.describeTimeRange(timeRaw);
6664
this.absolute = {fromJs: time.from.toDate(), toJs: time.to.toDate()};
67-
this.timeRaw = timeRaw;
6865
this.tooltip = this.dashboard.formatDate(time.from) + ' <br>to<br>';
6966
this.tooltip += this.dashboard.formatDate(time.to);
67+
68+
// do not update time raw when dropdown is open
69+
// as auto refresh will reset the from/to input fields
70+
if (!this.isOpen) {
71+
this.timeRaw = timeRaw;
72+
}
7073
}
7174

7275
zoom(factor) {
@@ -88,6 +91,7 @@ export class TimePickerCtrl {
8891
}
8992

9093
openDropdown() {
94+
this.init();
9195
this.isOpen = true;
9296
this.timeOptions = rangeUtil.getRelativeTimesList(this.panel, this.rangeString);
9397
this.refresh = {

0 commit comments

Comments
 (0)