Files
grafana/public/app/features/dashboard/dashgrid/DashboardPanel.tsx

55 lines
1.4 KiB
TypeScript
Raw Normal View History

import React from 'react';
import {PanelModel} from '../panel_model';
2017-10-10 09:34:14 +02:00
import {PanelContainer} from './PanelContainer';
import {AttachedPanel} from './PanelLoader';
2017-10-16 09:55:55 +02:00
import {DashboardRow} from './DashboardRow';
import {AddPanelPanel} from './AddPanelPanel';
export interface DashboardPanelProps {
2017-10-10 09:34:14 +02:00
panel: PanelModel;
getPanelContainer: () => PanelContainer;
}
export class DashboardPanel extends React.Component<DashboardPanelProps, any> {
2017-10-10 09:34:14 +02:00
element: any;
attachedPanel: AttachedPanel;
constructor(props) {
super(props);
this.state = {};
}
componentDidMount() {
2017-10-16 09:55:55 +02:00
if (!this.element) {
return;
}
2017-10-10 09:34:14 +02:00
const panelContainer = this.props.getPanelContainer();
const dashboard = panelContainer.getDashboard();
const loader = panelContainer.getPanelLoader();
this.attachedPanel = loader.load(this.element, this.props.panel, dashboard);
}
componentWillUnmount() {
if (this.attachedPanel) {
this.attachedPanel.destroy();
}
}
2017-10-16 09:55:55 +02:00
render() {
// special handling for rows
if (this.props.panel.type === 'row') {
2017-10-16 16:09:23 +02:00
return <DashboardRow panel={this.props.panel} getPanelContainer={this.props.getPanelContainer} />;
2017-10-16 09:55:55 +02:00
}
2017-10-13 17:01:38 +02:00
2017-10-16 09:55:55 +02:00
if (this.props.panel.type === 'add-panel') {
return <AddPanelPanel panel={this.props.panel} getPanelContainer={this.props.getPanelContainer} />;
}
2017-10-13 17:01:38 +02:00
return (
2017-11-21 14:30:33 +01:00
<div ref={element => this.element = element} className="panel-height-helper" />
);
}
}