From a3f1a1c6b391799feab5181bf0e9ec874dc0761c Mon Sep 17 00:00:00 2001 From: Johannes Schill Date: Mon, 12 Nov 2018 11:23:41 +0100 Subject: [PATCH] wip: panel-header: Remove the TimeData type --- .../dashboard/dashgrid/PanelChrome.tsx | 26 +++++++++---------- public/app/features/dashboard/utils/panel.ts | 12 ++++++--- .../app/features/panel/metrics_panel_ctrl.ts | 8 +----- public/app/types/index.ts | 2 -- public/app/types/series.ts | 5 ---- 5 files changed, 22 insertions(+), 31 deletions(-) diff --git a/public/app/features/dashboard/dashgrid/PanelChrome.tsx b/public/app/features/dashboard/dashgrid/PanelChrome.tsx index b4a3621f87b..ab6f5e3c3b2 100644 --- a/public/app/features/dashboard/dashgrid/PanelChrome.tsx +++ b/public/app/features/dashboard/dashgrid/PanelChrome.tsx @@ -14,7 +14,7 @@ import { applyPanelTimeOverrides, getResolution, calculateInterval } from 'app/f // Types import { PanelModel } from '../panel_model'; import { DashboardModel } from '../dashboard_model'; -import { TimeData, PanelProps } from 'app/types'; +import { TimeRange, PanelProps } from 'app/types'; export interface Props { panel: PanelModel; @@ -25,7 +25,8 @@ export interface Props { export interface State { refreshCounter: number; renderCounter: number; - timeData: TimeData; + timeInfo: string; + timeRange: TimeRange; interval: { interval: string; intervalMs: number; @@ -41,10 +42,8 @@ export class PanelChrome extends PureComponent { this.state = { refreshCounter: 0, renderCounter: 0, - timeData: { - timeInfo: '', - timeRange: this.timeSrv.timeRange(), - }, + timeInfo: '', + timeRange: this.timeSrv.timeRange(), interval: { interval: undefined, intervalMs: undefined, @@ -67,9 +66,10 @@ export class PanelChrome extends PureComponent { if (!this.isVisible) { return; } - const currTimeData = this.state.timeData; + + const { timeRange } = this.state; const { panel } = this.props; - const timeData = applyPanelTimeOverrides(panel, currTimeData); + const timeData = applyPanelTimeOverrides(panel, timeRange); const resolution = getResolution(panel); const interval = calculateInterval(panel, panel.datasource, timeData.timeRange, resolution); @@ -77,8 +77,8 @@ export class PanelChrome extends PureComponent { this.setState(prevState => ({ ...prevState, refreshCounter: this.state.refreshCounter + 1, - timeData, interval, + ...timeData, })); }; @@ -96,7 +96,7 @@ export class PanelChrome extends PureComponent { render() { const { panel, dashboard } = this.props; - const { refreshCounter, timeData, renderCounter } = this.state; + const { refreshCounter, timeRange, timeInfo, renderCounter } = this.state; const { datasource, targets } = panel; const PanelComponent = this.props.component; @@ -104,12 +104,12 @@ export class PanelChrome extends PureComponent { console.log('panelChrome render'); return (
- +
@@ -119,7 +119,7 @@ export class PanelChrome extends PureComponent { diff --git a/public/app/features/dashboard/utils/panel.ts b/public/app/features/dashboard/utils/panel.ts index a9aa4ef1eb7..6a3d3449986 100644 --- a/public/app/features/dashboard/utils/panel.ts +++ b/public/app/features/dashboard/utils/panel.ts @@ -4,7 +4,6 @@ import store from 'app/core/store'; // Models import { DashboardModel } from 'app/features/dashboard/dashboard_model'; import { PanelModel } from 'app/features/dashboard/panel_model'; -import { TimeData } from 'app/types'; import { TimeRange } from 'app/types/series'; // Utils @@ -101,9 +100,14 @@ export const toggleLegend = (panel: PanelModel) => { refreshPanel(panel); }; -export const applyPanelTimeOverrides = (panel: PanelModel, timeData: TimeData): TimeData => { - const { timeRange } = timeData; - const newTimeData = { ...timeData }; +export const applyPanelTimeOverrides = ( + panel: PanelModel, + timeRange: TimeRange +): { timeInfo: string; timeRange: TimeRange } => { + const newTimeData = { + timeInfo: '', + timeRange: timeRange, + }; if (panel.timeFrom) { const timeFromInterpolated = templateSrv.replace(panel.timeFrom, panel.scopedVars); diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 8ac3c36cf0f..6168ddf27d5 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -10,7 +10,6 @@ import { calculateInterval as calculateIntervalUtil, getResolution, } from 'app/features/dashboard/utils/panel'; -import { TimeData } from 'app/types'; class MetricsPanelCtrl extends PanelCtrl { scope: any; @@ -154,12 +153,7 @@ class MetricsPanelCtrl extends PanelCtrl { } applyPanelTimeOverrides() { - const timeData: TimeData = { - timeInfo: '', - timeRange: this.range, - }; - - const newTimeData = applyPanelTimeOverridesUtil(this.panel, timeData); + const newTimeData = applyPanelTimeOverridesUtil(this.panel, this.range); this.timeInfo = newTimeData.timeInfo; this.range = newTimeData.timeRange; } diff --git a/public/app/types/index.ts b/public/app/types/index.ts index 1238a924a04..fc176fed7e2 100644 --- a/public/app/types/index.ts +++ b/public/app/types/index.ts @@ -9,7 +9,6 @@ import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys'; import { Invitee, OrgUser, User, UsersState, UserState } from './user'; import { DataSource, DataSourcesState } from './datasources'; import { - TimeData, TimeRange, LoadingState, TimeSeries, @@ -67,7 +66,6 @@ export { OrgUser, User, UsersState, - TimeData, TimeRange, LoadingState, PanelProps, diff --git a/public/app/types/series.ts b/public/app/types/series.ts index 8f5d29c81aa..5396880611b 100644 --- a/public/app/types/series.ts +++ b/public/app/types/series.ts @@ -18,11 +18,6 @@ export interface TimeRange { raw: RawTimeRange; } -export interface TimeData { - timeRange: TimeRange; - timeInfo: string; -} - export type TimeSeriesValue = string | number | null; export type TimeSeriesPoints = TimeSeriesValue[][];