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

93 lines
2.0 KiB
TypeScript
Raw Normal View History

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';
interface Props {
angularPanel?: AngularComponent;
2018-12-19 13:09:53 +01:00
panel: PanelModel;
}
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] : [];
return (
2018-12-19 13:09:53 +01:00
<EditorTabBody heading="Alert" toolbarItems={toolbarItems}>
<div ref={element => (this.element = element)} />
</EditorTabBody>
);
}
}