|
@@ -1,8 +1,17 @@
|
|
|
-import React, { ComponentClass } from 'react';
|
|
|
|
|
|
|
+// Libraries
|
|
|
|
|
+import React, { ComponentClass, PureComponent } from 'react';
|
|
|
|
|
+
|
|
|
|
|
+// Services
|
|
|
|
|
+import { getTimeSrv } from '../time_srv';
|
|
|
|
|
+
|
|
|
|
|
+// Components
|
|
|
|
|
+import { PanelHeader } from './PanelHeader';
|
|
|
|
|
+import { DataPanel } from './DataPanel';
|
|
|
|
|
+
|
|
|
|
|
+// Types
|
|
|
import { PanelModel } from '../panel_model';
|
|
import { PanelModel } from '../panel_model';
|
|
|
import { DashboardModel } from '../dashboard_model';
|
|
import { DashboardModel } from '../dashboard_model';
|
|
|
-import { PanelHeader } from './PanelHeader';
|
|
|
|
|
-import { DataPanel, PanelProps } from './DataPanel';
|
|
|
|
|
|
|
+import { TimeRange, PanelProps } from 'app/types';
|
|
|
|
|
|
|
|
export interface Props {
|
|
export interface Props {
|
|
|
panel: PanelModel;
|
|
panel: PanelModel;
|
|
@@ -10,30 +19,59 @@ export interface Props {
|
|
|
component: ComponentClass<PanelProps>;
|
|
component: ComponentClass<PanelProps>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-interface State {}
|
|
|
|
|
-
|
|
|
|
|
-export class PanelChrome extends React.Component<Props, State> {
|
|
|
|
|
- panelComponent: DataPanel;
|
|
|
|
|
|
|
+export interface State {
|
|
|
|
|
+ refreshCounter: number;
|
|
|
|
|
+ timeRange?: TimeRange;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
+export class PanelChrome extends PureComponent<Props, State> {
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
|
|
|
+
|
|
|
|
|
+ this.state = {
|
|
|
|
|
+ refreshCounter: 0,
|
|
|
|
|
+ };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- render() {
|
|
|
|
|
- const { datasource, targets } = this.props.panel;
|
|
|
|
|
- const PanelComponent = this.props.component;
|
|
|
|
|
|
|
+ componentDidMount() {
|
|
|
|
|
+ this.props.dashboard.panelInitialized(this.props.panel);
|
|
|
|
|
+ this.props.panel.events.on('refresh', this.onRefresh);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ componentWillUnmount() {
|
|
|
|
|
+ this.props.panel.events.off('refresh', this.onRefresh);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onRefresh = () => {
|
|
|
|
|
+ const timeSrv = getTimeSrv();
|
|
|
|
|
+ const timeRange = timeSrv.timeRange();
|
|
|
|
|
|
|
|
- // if (!PanelComponent) {
|
|
|
|
|
- // PanelComponent = dataPanels[type] = DataPanelWrapper(this.props.component);
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ refreshCounter: this.state.refreshCounter + 1,
|
|
|
|
|
+ timeRange: timeRange,
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- console.log('PanelChrome render', PanelComponent);
|
|
|
|
|
|
|
+ get isVisible() {
|
|
|
|
|
+ return this.props.dashboard.otherPanelInFullscreen(this.props.panel);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ render() {
|
|
|
|
|
+ const { panel, dashboard } = this.props;
|
|
|
|
|
+ const { datasource, targets } = panel;
|
|
|
|
|
+ const { refreshCounter } = this.state;
|
|
|
|
|
+ const PanelComponent = this.props.component;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="panel-container">
|
|
<div className="panel-container">
|
|
|
- <PanelHeader panel={this.props.panel} dashboard={this.props.dashboard} />
|
|
|
|
|
|
|
+ <PanelHeader panel={panel} dashboard={dashboard} />
|
|
|
<div className="panel-content">
|
|
<div className="panel-content">
|
|
|
- <DataPanel datasource={datasource} queries={targets}>
|
|
|
|
|
|
|
+ <DataPanel
|
|
|
|
|
+ datasource={datasource}
|
|
|
|
|
+ queries={targets}
|
|
|
|
|
+ isVisible={this.isVisible}
|
|
|
|
|
+ refreshCounter={refreshCounter}
|
|
|
|
|
+ >
|
|
|
{({ loading, data }) => {
|
|
{({ loading, data }) => {
|
|
|
return <PanelComponent loading={loading} data={data} />;
|
|
return <PanelComponent loading={loading} data={data} />;
|
|
|
}}
|
|
}}
|