grafana/public/app/features/dashboard/dashgrid/PanelChrome.tsx

85 lines
2.0 KiB
TypeScript
Raw Normal View History

// 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';
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;
component: ComponentClass<PanelProps>;
2018-06-19 07:51:57 -05:00
}
export interface State {
refreshCounter: number;
timeRange?: TimeRange;
}
export class PanelChrome extends PureComponent<Props, State> {
2018-06-19 07:51:57 -05:00
constructor(props) {
super(props);
this.state = {
refreshCounter: 0,
};
}
componentDidMount() {
this.props.panel.events.on('refresh', this.onRefresh);
2018-10-14 09:31:20 -05:00
this.props.dashboard.panelInitialized(this.props.panel);
}
componentWillUnmount() {
this.props.panel.events.off('refresh', this.onRefresh);
}
onRefresh = () => {
const timeSrv = getTimeSrv();
const timeRange = timeSrv.timeRange();
this.setState({
refreshCounter: this.state.refreshCounter + 1,
timeRange: timeRange,
});
};
get isVisible() {
2018-10-14 09:31:20 -05:00
return !this.props.dashboard.otherPanelInFullscreen(this.props.panel);
}
render() {
const { panel, dashboard } = this.props;
const { datasource, targets } = panel;
2018-10-14 09:31:20 -05:00
const { refreshCounter, timeRange } = this.state;
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">
<PanelHeader panel={panel} dashboard={dashboard} />
<div className="panel-content">
<DataPanel
datasource={datasource}
queries={targets}
2018-10-14 09:31:20 -05:00
timeRange={timeRange}
isVisible={this.isVisible}
refreshCounter={refreshCounter}
>
{({ loading, data }) => {
return <PanelComponent loading={loading} data={data} />;
}}
</DataPanel>
</div>
2018-06-19 07:51:57 -05:00
</div>
);
}
}