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
// 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<Props, State> {
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<Props, State> {
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<Props, State> {
this.setState(prevState => ({
...prevState,
refreshCounter: this.state.refreshCounter + 1,
timeData,
interval,
...timeData,
}));
};
......@@ -96,7 +96,7 @@ export class PanelChrome extends PureComponent<Props, State> {
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<Props, State> {
console.log('panelChrome render');
return (
<div className="panel-container">
<PanelHeader panel={panel} dashboard={dashboard} timeInfo={timeData.timeInfo} />
<PanelHeader panel={panel} dashboard={dashboard} timeInfo={timeInfo} />
<div className="panel-content">
<DataPanel
datasource={datasource}
queries={targets}
timeRange={timeData.timeRange}
timeRange={timeRange}
isVisible={this.isVisible}
refreshCounter={refreshCounter}
>
......@@ -119,7 +119,7 @@ export class PanelChrome extends PureComponent<Props, State> {
<PanelComponent
loading={loading}
timeSeries={timeSeries}
timeRange={timeData.timeRange}
timeRange={timeRange}
options={panel.getOptions()}
renderCounter={renderCounter}
/>
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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,
......
......@@ -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[][];
......
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