Skip to content

Commit

Permalink
Fixes #1764: allows overriding actions in plugins (#1765)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto authored Apr 26, 2017
1 parent d7c559a commit c7dc556
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
5 changes: 4 additions & 1 deletion web/client/components/plugins/PluginsContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/security/UserMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const UserMenu = React.createClass({
if (itemArray.length > 0) {
itemArray.push(<MenuItem key="divider" divider />);
}
itemArray.push(<MenuItem key="logout" onClick={this.props.onLogout}><Glyphicon glyph="log-out" /> <Message msgId="user.logout"/></MenuItem>);
itemArray.push(<MenuItem key="logout" onClick={() => this.props.onLogout()}><Glyphicon glyph="log-out" /> <Message msgId="user.logout"/></MenuItem>);
}
return (
<DropDown id="loginButton" className={this.props.className} pullRight bsStyle="success" title={this.renderButtonText()} {...this.props.menuProps} >
Expand Down
2 changes: 1 addition & 1 deletion web/client/plugins/containers/ToolsContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const ToolsContainer = React.createClass({
const toolCfg = this.getToolConfig(tool);

return this.addTooltip(
<Tool {...toolCfg} tooltip={tooltip} btnSize={this.props.toolSize} bsStyle={this.props.toolStyle} help={help} key={tool.name || ("tool" + i)} mapType={this.props.mapType}
<Tool {...toolCfg} pluginCfg={tool.cfg} tooltip={tooltip} btnSize={this.props.toolSize} bsStyle={this.props.toolStyle} help={help} key={tool.name || ("tool" + i)} mapType={this.props.mapType}
{...tool.cfg} items={tool.items || []}>
{(tool.cfg && tool.cfg.glyph) ? <Glyphicon glyph={tool.cfg.glyph}/> : tool.icon}{help} {tool.text}
</Tool>,
Expand Down
2 changes: 1 addition & 1 deletion web/client/plugins/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 4 additions & 1 deletion web/client/utils/PluginsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
8 changes: 8 additions & 0 deletions web/client/utils/__tests__/PluginUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

0 comments on commit c7dc556

Please sign in to comment.