2018-11-20 17:09:47 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
|
|
|
|
|
|
import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader';
|
|
|
|
|
import { EditorTabBody } from './EditorTabBody';
|
|
|
|
|
import 'app/features/alerting/AlertTabCtrl';
|
2018-12-19 13:09:53 +01:00
|
|
|
import { PanelModel } from '../panel_model';
|
2018-11-20 17:09:47 +01:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
angularPanel?: AngularComponent;
|
2018-12-19 13:09:53 +01:00
|
|
|
panel: PanelModel;
|
2018-11-20 17:09:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class AlertTab extends PureComponent<Props> {
|
|
|
|
|
element: any;
|
|
|
|
|
component: AngularComponent;
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
if (this.shouldLoadAlertTab()) {
|
|
|
|
|
this.loadAlertTab();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps: Props) {
|
|
|
|
|
if (this.shouldLoadAlertTab()) {
|
|
|
|
|
this.loadAlertTab();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shouldLoadAlertTab() {
|
|
|
|
|
return this.props.angularPanel && this.element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
if (this.component) {
|
|
|
|
|
this.component.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadAlertTab() {
|
|
|
|
|
const { angularPanel } = this.props;
|
|
|
|
|
|
|
|
|
|
const scope = angularPanel.getScope();
|
|
|
|
|
|
|
|
|
|
// When full page reloading in edit mode the angular panel has on fully compiled & instantiated yet
|
|
|
|
|
if (!scope.$$childHead) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.forceUpdate();
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const panelCtrl = scope.$$childHead.ctrl;
|
|
|
|
|
const loader = getAngularLoader();
|
|
|
|
|
const template = '<alert-tab />';
|
|
|
|
|
|
|
|
|
|
const scopeProps = {
|
|
|
|
|
ctrl: panelCtrl,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.component = loader.load(this.element, scopeProps, template);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-12-19 13:09:53 +01:00
|
|
|
const { alert } = this.props.panel;
|
|
|
|
|
|
|
|
|
|
const stateHistory = {
|
|
|
|
|
title: 'State history',
|
|
|
|
|
render: () => {
|
|
|
|
|
return <div>State history</div>;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteAlert = {
|
|
|
|
|
title: 'Delete button',
|
|
|
|
|
render: () => {
|
|
|
|
|
return <div>Hello</div>;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const toolbarItems = alert ? [deleteAlert, stateHistory] : [];
|
|
|
|
|
|
2018-11-20 17:09:47 +01:00
|
|
|
return (
|
2018-12-19 13:09:53 +01:00
|
|
|
<EditorTabBody heading="Alert" toolbarItems={toolbarItems}>
|
2018-11-20 17:09:47 +01:00
|
|
|
<div ref={element => (this.element = element)} />
|
|
|
|
|
</EditorTabBody>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|