diff --git a/web/client/actions/manager.js b/web/client/actions/manager.js new file mode 100644 index 0000000000..ce7cd28a90 --- /dev/null +++ b/web/client/actions/manager.js @@ -0,0 +1,20 @@ +/** + * Copyright 2016, GeoSolutions Sas. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +const MANAGER_ITEM_SELECTED = 'MANAGER_ITEM_SELECTED'; + +function itemSelected(toolId) { + return { + type: MANAGER_ITEM_SELECTED, + toolId + }; +} + +module.exports = { + MANAGER_ITEM_SELECTED, itemSelected + }; diff --git a/web/client/plugins/manager/Manager.jsx b/web/client/plugins/manager/Manager.jsx index 3e87863935..20292fd870 100644 --- a/web/client/plugins/manager/Manager.jsx +++ b/web/client/plugins/manager/Manager.jsx @@ -6,7 +6,7 @@ * LICENSE file in the root directory of this source tree. */ const React = require('react'); - +const { itemSelected } = require('../../actions/manager'); const {Nav, NavItem, Glyphicon} = require('react-bootstrap'); const {connect} = require('react-redux'); const {Message} = require('../../components/I18N/I18N'); @@ -16,7 +16,7 @@ const Manager = React.createClass({ propTypes: { navStyle: React.PropTypes.object, items: React.PropTypes.array, - onItemSelected: React.PropTypes.func, + itemSelected: React.PropTypes.func, selectedTool: React.PropTypes.string }, contextTypes: { @@ -26,7 +26,8 @@ const Manager = React.createClass({ return { items: [], mapType: "openlayers", - selectedTool: "importer" + selectedTool: "importer", + itemSelected: () => {} }; }, renderToolIcon(tool) { @@ -40,7 +41,11 @@ const Manager = React.createClass({ eventKey={tool.id} key={tool.id} href="#" - onClick={(event) => {event.preventDefault(); this.context.router.push("/manager/" + tool.id); }}> + onClick={(event) => { + event.preventDefault(); + this.props.itemSelected(tool.id); + this.context.router.push("/manager/" + tool.id); + }}> {this.renderToolIcon(tool)} {tool.msgId ? : tool.title || tool.id} )); @@ -70,5 +75,8 @@ const Manager = React.createClass({ module.exports = { ManagerPlugin: connect((state, ownProps) => ({ selectedTool: ownProps.tool - }))(Manager) + }), + { + itemSelected + })(Manager) }; diff --git a/web/client/plugins/manager/ManagerMenu.jsx b/web/client/plugins/manager/ManagerMenu.jsx index 2e6a67a72b..f8b9f1dee7 100644 --- a/web/client/plugins/manager/ManagerMenu.jsx +++ b/web/client/plugins/manager/ManagerMenu.jsx @@ -8,6 +8,7 @@ const React = require('react'); const {connect} = require('react-redux'); +const { itemSelected } = require('../../actions/manager'); const assign = require('object-assign'); const {DropdownButton, Glyphicon, MenuItem} = require('react-bootstrap'); @@ -32,6 +33,7 @@ const ManagerMenu = React.createClass({ entries: React.PropTypes.array, title: React.PropTypes.node, onItemClick: React.PropTypes.func, + itemSelected: React.PropTypes.func, controls: React.PropTypes.object, mapType: React.PropTypes.string, panelStyle: React.PropTypes.object, @@ -47,6 +49,7 @@ const ManagerMenu = React.createClass({ entries: [], role: "", onItemClick: () => {}, + itemSelected: () => {}, title: Manager, controls: [], mapType: "leaflet", @@ -63,7 +66,7 @@ const ManagerMenu = React.createClass({ getTools() { return [{element: {this.props.title}}, ...this.props.entries.sort((a, b) => a.position - b.position).map((entry) => { return { - action: (context) => {context.router.push(entry.path); return {type: "MANAGER_MENU::SELECT_TOOL"}; }, + action: (context) => {context.router.push(entry.path); return this.props.itemSelected(entry.id); }, text: entry.msgId ? : entry.text, cfg: {...entry} }; @@ -93,7 +96,9 @@ module.exports = { ManagerMenuPlugin: assign(connect((state) => ({ controls: state.controls, role: state.security && state.security.user && state.security.user.role - }))(ManagerMenu), { + }), { + itemSelected + })(ManagerMenu), { OmniBar: { name: "managermenu", position: 1, diff --git a/web/client/reducers/importer.js b/web/client/reducers/importer.js index dfd04ee85e..0b6ae6c9fb 100644 --- a/web/client/reducers/importer.js +++ b/web/client/reducers/importer.js @@ -34,6 +34,11 @@ const { IMPORTER_WORKSPACE_CREATION_ERROR, IMPORTER_WORKSPACE_STATUS_CHANGE } = require('../actions/importer'); + +const { + MANAGER_ITEM_SELECTED +} = require('../actions/manager'); + const assign = require('object-assign'); /******************************************************************************/ @@ -126,7 +131,11 @@ function updateImportTaskLoadingStatus(state, action, loading = true) { /* REDUCER ********************************************************************/ /******************************************************************************/ -function importer(state = {}, action) { +const initialState = { + importerTool: "importer" +}; + +function importer(state = initialState, action) { switch (action.type) { case IMPORTS_LOADING: { if (!action.details) { @@ -141,6 +150,19 @@ function importer(state = {}, action) { } } return state; + case MANAGER_ITEM_SELECTED: { + const toolId = action.toolId; + if (toolId === state.importerTool) { + return assign({}, state, { + loadingError: null, + imports: state.imports, + selectedImport: null, + selectedTask: null, + selectedTransform: null + }); + } + return state; + } case IMPORTS_LIST_LOADED: return assign({}, state, { loadingError: null,