2020-10-26 07:39:34 +00:00
|
|
|
import React from "react";
|
|
|
|
import { Alert } from "react-bootstrap";
|
|
|
|
import { COMPONENTS } from './components';
|
2020-10-29 18:20:42 +00:00
|
|
|
import { IDynamicRenderSettings } from './interfaces/IDynamicRenderSettings';
|
2020-10-26 07:39:34 +00:00
|
|
|
|
2020-10-29 18:20:42 +00:00
|
|
|
class DynamicRenderer extends React.Component<IDynamicRenderSettings, {}> {
|
2020-10-26 07:39:34 +00:00
|
|
|
|
2020-10-30 18:30:59 +00:00
|
|
|
/**
|
|
|
|
* Function will be called if the Item has been rendered sucessfully.
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
const _this = this;
|
|
|
|
|
|
|
|
if (typeof _this.props.onMount === 'function') {
|
|
|
|
_this.props.onMount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function, that will be called before the network fails.
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
// Call the unmount
|
|
|
|
if (typeof this.props.onUnmount === 'function') {
|
|
|
|
this.props.onUnmount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 07:39:34 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
if (typeof this.props.component === 'string'){
|
|
|
|
if (typeof COMPONENTS[this.props.component] !== "undefined") {
|
|
|
|
return React.createElement(COMPONENTS[this.props.component],{ ...this.props.props});
|
|
|
|
}
|
|
|
|
// component doesn't exist yet
|
|
|
|
return (<>
|
|
|
|
<Alert variant={'danger'}>
|
|
|
|
Componenten with id {this.props.component} not defined in <code>COMPONENTS</code>
|
|
|
|
</Alert>
|
|
|
|
</>);
|
|
|
|
}
|
2020-11-04 21:36:52 +00:00
|
|
|
return React.createElement(this.props.component as any,{ ...this.props.props});
|
2020-10-26 07:39:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DynamicRenderer;
|