From c7dc556b0b84cae205501ff39b4567ac119de0b5 Mon Sep 17 00:00:00 2001 From: mbarto Date: Wed, 26 Apr 2017 17:40:06 +0200 Subject: [PATCH] Fixes #1764: allows overriding actions in plugins (#1765) --- web/client/components/plugins/PluginsContainer.jsx | 5 ++++- web/client/components/security/UserMenu.jsx | 2 +- web/client/plugins/containers/ToolsContainer.jsx | 2 +- web/client/plugins/login/index.js | 2 +- web/client/utils/PluginsUtils.js | 5 ++++- web/client/utils/__tests__/PluginUtils-test.js | 8 ++++++++ 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/web/client/components/plugins/PluginsContainer.jsx b/web/client/components/plugins/PluginsContainer.jsx index bc7859af25..12be177440 100644 --- a/web/client/components/plugins/PluginsContainer.jsx +++ b/web/client/components/plugins/PluginsContainer.jsx @@ -39,6 +39,9 @@ const PluginsContainer = React.createClass({ monitoredState: React.PropTypes.object, defaultMode: React.PropTypes.string }, + contextTypes: { + store: React.PropTypes.object + }, getDefaultProps() { return { mode: 'desktop', @@ -65,7 +68,7 @@ const PluginsContainer = React.createClass({ this.loadPlugins(newProps.pluginsState); }, getState(path) { - return get(this.props.monitoredState, path) || get(this.props.params, path); + return get(this.props.monitoredState, path) || get(this.props.params, path) || this.context[path]; }, getPluginDescriptor(plugin) { return PluginsUtils.getPluginDescriptor(this.getState, this.props.plugins, diff --git a/web/client/components/security/UserMenu.jsx b/web/client/components/security/UserMenu.jsx index 67203b913d..4bfb5da40b 100644 --- a/web/client/components/security/UserMenu.jsx +++ b/web/client/components/security/UserMenu.jsx @@ -95,7 +95,7 @@ const UserMenu = React.createClass({ if (itemArray.length > 0) { itemArray.push(); } - itemArray.push( ); + itemArray.push( this.props.onLogout()}> ); } return ( diff --git a/web/client/plugins/containers/ToolsContainer.jsx b/web/client/plugins/containers/ToolsContainer.jsx index bfcfe24f1d..61ece2ff1b 100644 --- a/web/client/plugins/containers/ToolsContainer.jsx +++ b/web/client/plugins/containers/ToolsContainer.jsx @@ -135,7 +135,7 @@ const ToolsContainer = React.createClass({ const toolCfg = this.getToolConfig(tool); return this.addTooltip( - {(tool.cfg && tool.cfg.glyph) ? : tool.icon}{help} {tool.text} , diff --git a/web/client/plugins/login/index.js b/web/client/plugins/login/index.js index cebb57d6cf..94d85bc743 100644 --- a/web/client/plugins/login/index.js +++ b/web/client/plugins/login/index.js @@ -6,7 +6,7 @@ * LICENSE file in the root directory of this source tree. */ const React = require('react'); -const {connect} = require('react-redux'); +const {connect} = require('../../utils/PluginsUtils'); const {geoStoreLoginSubmit, loginFail, logoutWithReload, geoStoreChangePassword, resetError} = require('../../actions/security'); const {setControlProperty} = require('../../actions/controls'); const {Glyphicon} = require('react-bootstrap'); diff --git a/web/client/utils/PluginsUtils.js b/web/client/utils/PluginsUtils.js index 8276d49922..0e6ce5eb0e 100644 --- a/web/client/utils/PluginsUtils.js +++ b/web/client/utils/PluginsUtils.js @@ -36,9 +36,12 @@ const isPluginConfigured = (pluginsConfig, plugin) => { /*eslint-disable */ const parseExpression = (state = {}, context = {}, value) => { - const searchExpression = /^\{(.*?)\}$/; + const searchExpression = /^\{(.*)\}$/; const expression = searchExpression.exec(value); const request = url.parse(location.href, true); + const dispatch = (action) => { + return () => state("store").dispatch(action.apply(null, arguments)); + }; if (expression !== null) { return eval(expression[1]); } diff --git a/web/client/utils/__tests__/PluginUtils-test.js b/web/client/utils/__tests__/PluginUtils-test.js index d4e098d492..d7d25ecc80 100644 --- a/web/client/utils/__tests__/PluginUtils-test.js +++ b/web/client/utils/__tests__/PluginUtils-test.js @@ -101,4 +101,12 @@ describe('PluginsUtils', () => { it('handleExpression', () => { expect(PluginsUtils.handleExpression({state1: "test1"}, {context1: "test2"}, "{state.state1 + ' ' + context.context1}")).toBe("test1 test2"); }); + it('dispatch', () => { + const expr = PluginsUtils.handleExpression(() => ({ + dispatch: (action) => action + }), {context1: "test2"}, "{dispatch(() => 'test')}"); + + expect(expr).toExist(); + expect(expr()).toBe("test"); + }); });