Commit a3f1a1c6 by Johannes Schill

wip: panel-header: Remove the TimeData type

parent 8117a755
...@@ -14,7 +14,7 @@ import { applyPanelTimeOverrides, getResolution, calculateInterval } from 'app/f ...@@ -14,7 +14,7 @@ import { applyPanelTimeOverrides, getResolution, calculateInterval } from 'app/f
// Types // Types
import { PanelModel } from '../panel_model'; import { PanelModel } from '../panel_model';
import { DashboardModel } from '../dashboard_model'; import { DashboardModel } from '../dashboard_model';
import { TimeData, PanelProps } from 'app/types'; import { TimeRange, PanelProps } from 'app/types';
export interface Props { export interface Props {
panel: PanelModel; panel: PanelModel;
...@@ -25,7 +25,8 @@ export interface Props { ...@@ -25,7 +25,8 @@ export interface Props {
export interface State { export interface State {
refreshCounter: number; refreshCounter: number;
renderCounter: number; renderCounter: number;
timeData: TimeData; timeInfo: string;
timeRange: TimeRange;
interval: { interval: {
interval: string; interval: string;
intervalMs: number; intervalMs: number;
...@@ -41,10 +42,8 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -41,10 +42,8 @@ export class PanelChrome extends PureComponent<Props, State> {
this.state = { this.state = {
refreshCounter: 0, refreshCounter: 0,
renderCounter: 0, renderCounter: 0,
timeData: {
timeInfo: '', timeInfo: '',
timeRange: this.timeSrv.timeRange(), timeRange: this.timeSrv.timeRange(),
},
interval: { interval: {
interval: undefined, interval: undefined,
intervalMs: undefined, intervalMs: undefined,
...@@ -67,9 +66,10 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -67,9 +66,10 @@ export class PanelChrome extends PureComponent<Props, State> {
if (!this.isVisible) { if (!this.isVisible) {
return; return;
} }
const currTimeData = this.state.timeData;
const { timeRange } = this.state;
const { panel } = this.props; const { panel } = this.props;
const timeData = applyPanelTimeOverrides(panel, currTimeData); const timeData = applyPanelTimeOverrides(panel, timeRange);
const resolution = getResolution(panel); const resolution = getResolution(panel);
const interval = calculateInterval(panel, panel.datasource, timeData.timeRange, resolution); const interval = calculateInterval(panel, panel.datasource, timeData.timeRange, resolution);
...@@ -77,8 +77,8 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -77,8 +77,8 @@ export class PanelChrome extends PureComponent<Props, State> {
this.setState(prevState => ({ this.setState(prevState => ({
...prevState, ...prevState,
refreshCounter: this.state.refreshCounter + 1, refreshCounter: this.state.refreshCounter + 1,
timeData,
interval, interval,
...timeData,
})); }));
}; };
...@@ -96,7 +96,7 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -96,7 +96,7 @@ export class PanelChrome extends PureComponent<Props, State> {
render() { render() {
const { panel, dashboard } = this.props; const { panel, dashboard } = this.props;
const { refreshCounter, timeData, renderCounter } = this.state; const { refreshCounter, timeRange, timeInfo, renderCounter } = this.state;
const { datasource, targets } = panel; const { datasource, targets } = panel;
const PanelComponent = this.props.component; const PanelComponent = this.props.component;
...@@ -104,12 +104,12 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -104,12 +104,12 @@ export class PanelChrome extends PureComponent<Props, State> {
console.log('panelChrome render'); console.log('panelChrome render');
return ( return (
<div className="panel-container"> <div className="panel-container">
<PanelHeader panel={panel} dashboard={dashboard} timeInfo={timeData.timeInfo} /> <PanelHeader panel={panel} dashboard={dashboard} timeInfo={timeInfo} />
<div className="panel-content"> <div className="panel-content">
<DataPanel <DataPanel
datasource={datasource} datasource={datasource}
queries={targets} queries={targets}
timeRange={timeData.timeRange} timeRange={timeRange}
isVisible={this.isVisible} isVisible={this.isVisible}
refreshCounter={refreshCounter} refreshCounter={refreshCounter}
> >
...@@ -119,7 +119,7 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -119,7 +119,7 @@ export class PanelChrome extends PureComponent<Props, State> {
<PanelComponent <PanelComponent
loading={loading} loading={loading}
timeSeries={timeSeries} timeSeries={timeSeries}
timeRange={timeData.timeRange} timeRange={timeRange}
options={panel.getOptions()} options={panel.getOptions()}
renderCounter={renderCounter} renderCounter={renderCounter}
/> />
......
...@@ -4,7 +4,6 @@ import store from 'app/core/store'; ...@@ -4,7 +4,6 @@ import store from 'app/core/store';
// Models // Models
import { DashboardModel } from 'app/features/dashboard/dashboard_model'; import { DashboardModel } from 'app/features/dashboard/dashboard_model';
import { PanelModel } from 'app/features/dashboard/panel_model'; import { PanelModel } from 'app/features/dashboard/panel_model';
import { TimeData } from 'app/types';
import { TimeRange } from 'app/types/series'; import { TimeRange } from 'app/types/series';
// Utils // Utils
...@@ -101,9 +100,14 @@ export const toggleLegend = (panel: PanelModel) => { ...@@ -101,9 +100,14 @@ export const toggleLegend = (panel: PanelModel) => {
refreshPanel(panel); refreshPanel(panel);
}; };
export const applyPanelTimeOverrides = (panel: PanelModel, timeData: TimeData): TimeData => { export const applyPanelTimeOverrides = (
const { timeRange } = timeData; panel: PanelModel,
const newTimeData = { ...timeData }; timeRange: TimeRange
): { timeInfo: string; timeRange: TimeRange } => {
const newTimeData = {
timeInfo: '',
timeRange: timeRange,
};
if (panel.timeFrom) { if (panel.timeFrom) {
const timeFromInterpolated = templateSrv.replace(panel.timeFrom, panel.scopedVars); const timeFromInterpolated = templateSrv.replace(panel.timeFrom, panel.scopedVars);
......
...@@ -10,7 +10,6 @@ import { ...@@ -10,7 +10,6 @@ import {
calculateInterval as calculateIntervalUtil, calculateInterval as calculateIntervalUtil,
getResolution, getResolution,
} from 'app/features/dashboard/utils/panel'; } from 'app/features/dashboard/utils/panel';
import { TimeData } from 'app/types';
class MetricsPanelCtrl extends PanelCtrl { class MetricsPanelCtrl extends PanelCtrl {
scope: any; scope: any;
...@@ -154,12 +153,7 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -154,12 +153,7 @@ class MetricsPanelCtrl extends PanelCtrl {
} }
applyPanelTimeOverrides() { applyPanelTimeOverrides() {
const timeData: TimeData = { const newTimeData = applyPanelTimeOverridesUtil(this.panel, this.range);
timeInfo: '',
timeRange: this.range,
};
const newTimeData = applyPanelTimeOverridesUtil(this.panel, timeData);
this.timeInfo = newTimeData.timeInfo; this.timeInfo = newTimeData.timeInfo;
this.range = newTimeData.timeRange; this.range = newTimeData.timeRange;
} }
......
...@@ -9,7 +9,6 @@ import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys'; ...@@ -9,7 +9,6 @@ import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys';
import { Invitee, OrgUser, User, UsersState, UserState } from './user'; import { Invitee, OrgUser, User, UsersState, UserState } from './user';
import { DataSource, DataSourcesState } from './datasources'; import { DataSource, DataSourcesState } from './datasources';
import { import {
TimeData,
TimeRange, TimeRange,
LoadingState, LoadingState,
TimeSeries, TimeSeries,
...@@ -67,7 +66,6 @@ export { ...@@ -67,7 +66,6 @@ export {
OrgUser, OrgUser,
User, User,
UsersState, UsersState,
TimeData,
TimeRange, TimeRange,
LoadingState, LoadingState,
PanelProps, PanelProps,
......
...@@ -18,11 +18,6 @@ export interface TimeRange { ...@@ -18,11 +18,6 @@ export interface TimeRange {
raw: RawTimeRange; raw: RawTimeRange;
} }
export interface TimeData {
timeRange: TimeRange;
timeInfo: string;
}
export type TimeSeriesValue = string | number | null; export type TimeSeriesValue = string | number | null;
export type TimeSeriesPoints = TimeSeriesValue[][]; export type TimeSeriesPoints = TimeSeriesValue[][];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment