Make plugin injection more dynamic

This commit is contained in:
Pierre BURGY 2016-08-26 14:35:59 +02:00
parent a1c344ab15
commit 3d370d2a82
3 changed files with 14 additions and 6 deletions

View File

@ -14,19 +14,27 @@ export class Content extends React.Component { // eslint-disable-line react/pref
render() {
let plugin;
// Detect plugin according to params
this.props.plugins.map(p => {
plugin = p;
return p;
if (this.props.params.plugin === p.id) {
plugin = p;
}
});
const Elem = plugin.mainComponent;
let content;
if (!plugin) {
content = <p>Unknown plugin.</p>
} else {
const Elem = plugin.mainComponent;
content = <Elem plugin={plugin}></Elem>;
}
return (
<div className={styles.content}>
<div className="alert alert-success" role="alert">
<strong>Welcome!</strong> You successfully loaded the admin panel.
</div>
<Elem></Elem>
{content}
</div>
);
}

View File

@ -26,7 +26,7 @@ export class HomePage extends React.Component { // eslint-disable-line react/pre
<LeftMenu {...this.props}></LeftMenu>
<div className={styles.homePageRightWrapper}>
<Header></Header>
<Content></Content>
<Content {...this.props}></Content>
</div>
</div>
);

View File

@ -55,7 +55,7 @@ export default function createRoutes(store) {
},
}, {
path: '*',
name: 'notfound',
name: '404',
getComponent(nextState, cb) {
System.import('containers/NotFoundPage')
.then(loadModule(cb))