From 86918a2fc7187c3fe54691e0465a43fca60bf71a Mon Sep 17 00:00:00 2001 From: Mauro Bartolomeoli Date: Wed, 16 Nov 2016 10:40:03 +0100 Subject: [PATCH] Added template configuration for plugins in the plugins example --- web/client/examples/plugins/app.jsx | 1 + .../plugins/components/PluginConfigurator.jsx | 44 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/web/client/examples/plugins/app.jsx b/web/client/examples/plugins/app.jsx index 06e1e645013..bf5dd0f819a 100644 --- a/web/client/examples/plugins/app.jsx +++ b/web/client/examples/plugins/app.jsx @@ -77,6 +77,7 @@ const startApp = () => { return Object.keys(plugins).map((plugin) => { const pluginName = plugin.substring(0, plugin.length - 6); return (Enter a JSON object to configure plugin properties, @@ -47,7 +67,8 @@ const PluginConfigurator = React.createClass({ mode: {name: "javascript", json: true}, lineNumbers: true }}/>, - + , + ] : null; }, render() { @@ -58,11 +79,26 @@ const PluginConfigurator = React.createClass({ checked={this.props.pluginsCfg.indexOf(this.props.pluginName) !== -1} label={this.props.pluginName} onChange={this.props.onToggle}/> - {this.renderCfg()} ); }, - updateCode: function(newCode) { + showProps() { + if (this.props.pluginImpl) { + const plugin = this.props.pluginImpl; + const pluginProps = plugin.WrappedComponent && plugin.WrappedComponent.propTypes || plugin.propTypes; + + const propsValues = (plugin.WrappedComponent && plugin.WrappedComponent.getDefaultProps && plugin.WrappedComponent.getDefaultProps()) || + (plugin.getDefaultProps && plugin.getDefaultProps()) || {}; + + const props = Object.keys(pluginProps || {}).reduce((previous, current) => { + return assign(previous, {[current]: this.getPropValue(pluginProps[current])}, propsValues); + }, {}); + this.setState({ + code: JSON.stringify(props, null, 4) + }); + } + }, + updateCode(newCode) { this.setState({ code: newCode });