2018-10-14 08:39:34 -05:00
|
|
|
// Libraries
|
|
|
|
import React, { ComponentClass, PureComponent } from 'react';
|
|
|
|
|
|
|
|
// Services
|
|
|
|
import { getTimeSrv } from '../time_srv';
|
|
|
|
|
|
|
|
// Components
|
|
|
|
import { PanelHeader } from './PanelHeader';
|
|
|
|
import { DataPanel } from './DataPanel';
|
|
|
|
|
|
|
|
// Types
|
2018-06-19 07:51:57 -05:00
|
|
|
import { PanelModel } from '../panel_model';
|
|
|
|
import { DashboardModel } from '../dashboard_model';
|
2018-10-14 08:39:34 -05:00
|
|
|
import { TimeRange, PanelProps } from 'app/types';
|
2018-06-19 07:51:57 -05:00
|
|
|
|
2018-07-01 10:34:42 -05: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-10-14 08:39:34 -05:00
|
|
|
export interface State {
|
|
|
|
refreshCounter: number;
|
|
|
|
timeRange?: TimeRange;
|
|
|
|
}
|
2018-07-05 15:10:39 -05:00
|
|
|
|
2018-10-14 08:39:34 -05:00
|
|
|
export class PanelChrome extends PureComponent<Props, State> {
|
2018-06-19 07:51:57 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-10-14 08:39:34 -05:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
refreshCounter: 0,
|
|
|
|
};
|
2018-07-05 15:10:39 -05:00
|
|
|
}
|
|
|
|
|
2018-10-14 08:39:34 -05:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.panel.events.on('refresh', this.onRefresh);
|
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-10-14 08:39:34 -05:00
|
|
|
this.setState({
|
|
|
|
refreshCounter: this.state.refreshCounter + 1,
|
|
|
|
timeRange: timeRange,
|
|
|
|
});
|
|
|
|
};
|
2018-07-09 15:24:15 -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() {
|
|
|
|
const { panel, dashboard } = this.props;
|
|
|
|
const { datasource, targets } = panel;
|
2018-10-14 09:31:20 -05:00
|
|
|
const { refreshCounter, timeRange } = this.state;
|
2018-10-14 08:39:34 -05:00
|
|
|
const PanelComponent = this.props.component;
|
2018-06-19 07:51:57 -05:00
|
|
|
|
|
|
|
return (
|
2018-07-09 11:17:51 -05:00
|
|
|
<div className="panel-container">
|
2018-10-14 08:39:34 -05: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
|
|
|
|
datasource={datasource}
|
|
|
|
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 05:41:09 -05:00
|
|
|
{({ loading, data }) => {
|
|
|
|
return <PanelComponent loading={loading} data={data} />;
|
|
|
|
}}
|
|
|
|
</DataPanel>
|
|
|
|
</div>
|
2018-06-19 07:51:57 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|