2018-10-14 08:39:34 -05:00
|
|
|
// Libraries
|
|
|
|
import React, { ComponentClass, PureComponent } from 'react';
|
|
|
|
|
|
|
|
// Services
|
|
|
|
import { getTimeSrv } from '../time_srv';
|
|
|
|
|
|
|
|
// Components
|
2018-10-25 05:47:09 -05:00
|
|
|
import { PanelHeader } from './PanelHeader/PanelHeader';
|
2018-10-14 08:39:34 -05:00
|
|
|
import { DataPanel } from './DataPanel';
|
|
|
|
|
|
|
|
// Types
|
2018-06-19 07:51:57 -05:00
|
|
|
import { PanelModel } from '../panel_model';
|
|
|
|
import { DashboardModel } from '../dashboard_model';
|
2018-11-06 09:37:51 -06:00
|
|
|
import { TimeRange, PanelProps } from 'app/types';
|
2018-06-19 07:51:57 -05:00
|
|
|
|
2018-11-06 09:37:51 -06:00
|
|
|
export interface Props {
|
2018-06-19 07:51:57 -05:00
|
|
|
panel: PanelModel;
|
|
|
|
dashboard: DashboardModel;
|
2018-07-05 15:10:39 -05:00
|
|
|
component: ComponentClass<PanelProps>;
|
2018-06-19 07:51:57 -05:00
|
|
|
}
|
|
|
|
|
2018-11-06 09:37:51 -06:00
|
|
|
export interface State {
|
2018-10-14 08:39:34 -05:00
|
|
|
refreshCounter: number;
|
2018-11-05 10:46:09 -06:00
|
|
|
renderCounter: number;
|
2018-10-14 08:39:34 -05:00
|
|
|
timeRange?: TimeRange;
|
|
|
|
}
|
2018-07-05 15:10:39 -05:00
|
|
|
|
2018-11-06 09:37:51 -06:00
|
|
|
export class PanelChrome extends PureComponent<Props, State> {
|
2018-06-19 07:51:57 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-11-06 09:37:51 -06:00
|
|
|
|
2018-10-14 08:39:34 -05:00
|
|
|
this.state = {
|
|
|
|
refreshCounter: 0,
|
2018-11-05 10:46:09 -06:00
|
|
|
renderCounter: 0,
|
2018-10-14 08:39:34 -05:00
|
|
|
};
|
2018-07-05 15:10:39 -05:00
|
|
|
}
|
|
|
|
|
2018-11-06 09:37:51 -06:00
|
|
|
componentDidMount() {
|
2018-10-14 08:39:34 -05:00
|
|
|
this.props.panel.events.on('refresh', this.onRefresh);
|
2018-11-05 10:46:09 -06:00
|
|
|
this.props.panel.events.on('render', this.onRender);
|
2018-10-14 09:31:20 -05:00
|
|
|
this.props.dashboard.panelInitialized(this.props.panel);
|
2018-10-14 08:39:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.props.panel.events.off('refresh', this.onRefresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
onRefresh = () => {
|
|
|
|
const timeSrv = getTimeSrv();
|
|
|
|
const timeRange = timeSrv.timeRange();
|
2018-07-09 15:24:15 -05:00
|
|
|
|
2018-11-03 17:36:40 -05:00
|
|
|
this.setState(prevState => ({
|
|
|
|
...prevState,
|
2018-10-14 08:39:34 -05:00
|
|
|
refreshCounter: this.state.refreshCounter + 1,
|
|
|
|
timeRange: timeRange,
|
2018-11-03 17:36:40 -05:00
|
|
|
}));
|
2018-10-14 08:39:34 -05:00
|
|
|
};
|
2018-07-09 15:24:15 -05:00
|
|
|
|
2018-11-05 10:46:09 -06:00
|
|
|
onRender = () => {
|
|
|
|
console.log('onRender');
|
2018-11-03 17:36:40 -05:00
|
|
|
this.setState(prevState => ({
|
|
|
|
...prevState,
|
2018-11-06 09:37:51 -06:00
|
|
|
renderCounter: this.state.renderCounter + 1,
|
2018-11-03 17:36:40 -05:00
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2018-10-14 08:39:34 -05:00
|
|
|
get isVisible() {
|
2018-10-14 09:31:20 -05:00
|
|
|
return !this.props.dashboard.otherPanelInFullscreen(this.props.panel);
|
2018-10-14 08:39:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-11-06 09:44:13 -06:00
|
|
|
const { panel, dashboard } = this.props;
|
2018-11-06 09:37:51 -06:00
|
|
|
const { refreshCounter, timeRange, renderCounter } = this.state;
|
2018-11-06 08:03:56 -06:00
|
|
|
|
2018-11-06 09:37:51 -06:00
|
|
|
const { datasource, targets } = panel;
|
2018-10-14 08:39:34 -05:00
|
|
|
const PanelComponent = this.props.component;
|
2018-11-05 10:46:09 -06:00
|
|
|
|
2018-11-03 17:36:40 -05:00
|
|
|
console.log('panelChrome render');
|
2018-06-19 07:51:57 -05:00
|
|
|
return (
|
2018-07-09 11:17:51 -05:00
|
|
|
<div className="panel-container">
|
2018-11-07 06:55:02 -06:00
|
|
|
<PanelHeader panel={panel} dashboard={dashboard} />
|
2018-10-14 05:41:09 -05:00
|
|
|
<div className="panel-content">
|
2018-10-14 08:39:34 -05:00
|
|
|
<DataPanel
|
2018-11-06 09:37:51 -06:00
|
|
|
datasource={datasource}
|
2018-10-14 08:39:34 -05:00
|
|
|
queries={targets}
|
2018-10-14 09:31:20 -05:00
|
|
|
timeRange={timeRange}
|
2018-10-14 08:39:34 -05:00
|
|
|
isVisible={this.isVisible}
|
|
|
|
refreshCounter={refreshCounter}
|
|
|
|
>
|
2018-10-14 11:19:49 -05:00
|
|
|
{({ loading, timeSeries }) => {
|
2018-11-05 10:46:09 -06:00
|
|
|
console.log('panelcrome inner render');
|
|
|
|
return (
|
|
|
|
<PanelComponent
|
|
|
|
loading={loading}
|
|
|
|
timeSeries={timeSeries}
|
|
|
|
timeRange={timeRange}
|
|
|
|
options={panel.getOptions()}
|
|
|
|
renderCounter={renderCounter}
|
|
|
|
/>
|
|
|
|
);
|
2018-10-14 05:41:09 -05:00
|
|
|
}}
|
|
|
|
</DataPanel>
|
|
|
|
</div>
|
2018-06-19 07:51:57 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|