Bladeren bron

Merge pull request #12219 from PrincipalsOffice/fix-#12030

Prevent refresh on fixed time window
Torkel Ödegaard 7 jaren geleden
bovenliggende
commit
a6b32305e9
2 gewijzigde bestanden met toevoegingen van 24 en 0 verwijderingen
  1. 18 0
      public/app/features/dashboard/specs/time_srv.test.ts
  2. 6 0
      public/app/features/dashboard/time_srv.ts

+ 18 - 0
public/app/features/dashboard/specs/time_srv.test.ts

@@ -29,6 +29,7 @@ describe('timeSrv', () => {
   beforeEach(() => {
     timeSrv = new TimeSrv(rootScope, jest.fn(), location, timer, { isGrafanaVisibile: jest.fn() });
     timeSrv.init(_dashboard);
+    _dashboard.refresh = false;
   });
 
   describe('timeRange', () => {
@@ -79,6 +80,23 @@ describe('timeSrv', () => {
       expect(time.to.valueOf()).toEqual(new Date('2014-05-20T03:10:22Z').getTime());
     });
 
+    it('should ignore refresh if time absolute', () => {
+      location = {
+        search: jest.fn(() => ({
+          from: '20140410T052010',
+          to: '20140520T031022',
+        })),
+      };
+
+      timeSrv = new TimeSrv(rootScope, jest.fn(), location, timer, { isGrafanaVisibile: jest.fn() });
+
+      // dashboard saved with refresh on
+      _dashboard.refresh = true;
+      timeSrv.init(_dashboard);
+
+      expect(timeSrv.refresh).toBe(false);
+    });
+
     it('should handle formatted dates without time', () => {
       location = {
         search: jest.fn(() => ({

+ 6 - 0
public/app/features/dashboard/time_srv.ts

@@ -85,6 +85,12 @@ export class TimeSrv {
     if (params.to) {
       this.time.to = this.parseUrlParam(params.to) || this.time.to;
     }
+    // if absolute ignore refresh option saved to dashboard
+    if (params.to && params.to.indexOf('now') === -1) {
+      this.refresh = false;
+      this.dashboard.refresh = false;
+    }
+    // but if refresh explicitly set then use that
     if (params.refresh) {
       this.refresh = params.refresh || this.refresh;
     }