Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1764: allows overriding actions in plugins #1765

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});
});