From f274195d817385a7c3848c5fe619e7360ba4ab38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 13 Nov 2018 15:05:07 +0100 Subject: [PATCH] wip: refactoring interval and time override handling --- .../dashboard/dashgrid/PanelChrome.tsx | 35 ++++++------------- public/app/features/dashboard/time_srv.ts | 3 +- public/app/features/dashboard/utils/panel.ts | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/public/app/features/dashboard/dashgrid/PanelChrome.tsx b/public/app/features/dashboard/dashgrid/PanelChrome.tsx index 79af541769a..3bfa1d365b7 100644 --- a/public/app/features/dashboard/dashgrid/PanelChrome.tsx +++ b/public/app/features/dashboard/dashgrid/PanelChrome.tsx @@ -9,7 +9,7 @@ import { PanelHeader } from './PanelHeader/PanelHeader'; import { DataPanel } from './DataPanel'; // Utils -import { applyPanelTimeOverrides, getResolution, calculateInterval } from 'app/features/dashboard/utils/panel'; +import { applyPanelTimeOverrides } from 'app/features/dashboard/utils/panel'; // Types import { PanelModel } from '../panel_model'; @@ -25,12 +25,8 @@ export interface Props { export interface State { refreshCounter: number; renderCounter: number; - timeInfo: string; - timeRange: TimeRange; - interval: { - interval: string; - intervalMs: number; - }; + timeInfo?: string; + timeRange?: TimeRange; } export class PanelChrome extends PureComponent { @@ -42,12 +38,6 @@ export class PanelChrome extends PureComponent { this.state = { refreshCounter: 0, renderCounter: 0, - timeInfo: '', - timeRange: this.timeSrv.timeRange(), - interval: { - interval: undefined, - intervalMs: undefined, - }, }; } @@ -68,25 +58,20 @@ export class PanelChrome extends PureComponent { } const { panel } = this.props; - const timeRange = this.timeSrv.timeRange(); - const timeData = applyPanelTimeOverrides(panel, timeRange); - const resolution = getResolution(panel); - const interval = calculateInterval(panel, panel.datasource, timeData.timeRange, resolution); + const timeData = applyPanelTimeOverrides(panel, this.timeSrv.timeRange()); - this.setState(prevState => ({ - ...prevState, + this.setState({ refreshCounter: this.state.refreshCounter + 1, - interval, - ...timeData, - })); + timeRange: timeData.timeRange, + timeInfo: timeData.timeInfo, + }); }; onRender = () => { console.log('onRender'); - this.setState(prevState => ({ - ...prevState, + this.setState({ renderCounter: this.state.renderCounter + 1, - })); + }); }; get isVisible() { diff --git a/public/app/features/dashboard/time_srv.ts b/public/app/features/dashboard/time_srv.ts index 03b4a408125..ac717de15c9 100644 --- a/public/app/features/dashboard/time_srv.ts +++ b/public/app/features/dashboard/time_srv.ts @@ -20,7 +20,7 @@ export class TimeSrv { private autoRefreshBlocked: boolean; /** @ngInject */ - constructor(private $rootScope, private $timeout, private $location, private timer, private contextSrv) { + constructor($rootScope, private $timeout, private $location, private timer, private contextSrv) { // default time this.time = { from: '6h', to: 'now' }; @@ -189,7 +189,6 @@ export class TimeSrv { this.$location.search(urlParams); } - this.$rootScope.appEvent('time-range-changed', this.time); this.$timeout(this.refreshDashboard.bind(this), 0); } diff --git a/public/app/features/dashboard/utils/panel.ts b/public/app/features/dashboard/utils/panel.ts index 6a3d3449986..831d4e0396f 100644 --- a/public/app/features/dashboard/utils/panel.ts +++ b/public/app/features/dashboard/utils/panel.ts @@ -1,4 +1,4 @@ -// Store +// Store import store from 'app/core/store'; // Models