Skip to content

Commit

Permalink
Fixed #1126 : click on import data reloads the imports list (#1127)
Browse files Browse the repository at this point in the history
* Fixed #1126 : click on import data reloads the imports list

* changed action names

* changed the reducer of importer

* fixed importer reducer
  • Loading branch information
MV88 authored and offtherailz committed Oct 11, 2016
1 parent 451d9c1 commit 82e3c25
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
20 changes: 20 additions & 0 deletions web/client/actions/manager.js
Original file line number Diff line number Diff line change
@@ -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
};
18 changes: 13 additions & 5 deletions web/client/plugins/manager/Manager.jsx
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 { itemSelected } = require('../../actions/manager');
const {Nav, NavItem, Glyphicon} = require('react-bootstrap');
const {connect} = require('react-redux');
const {Message} = require('../../components/I18N/I18N');
Expand All @@ -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: {
Expand All @@ -26,7 +26,8 @@ const Manager = React.createClass({
return {
items: [],
mapType: "openlayers",
selectedTool: "importer"
selectedTool: "importer",
itemSelected: () => {}
};
},
renderToolIcon(tool) {
Expand All @@ -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)}
<span className="nav-msg">{tool.msgId ? <Message msgId={tool.msgId} /> : tool.title || tool.id}</span>
</NavItem>));
Expand Down Expand Up @@ -70,5 +75,8 @@ const Manager = React.createClass({
module.exports = {
ManagerPlugin: connect((state, ownProps) => ({
selectedTool: ownProps.tool
}))(Manager)
}),
{
itemSelected
})(Manager)
};
9 changes: 7 additions & 2 deletions web/client/plugins/manager/ManagerMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand All @@ -47,6 +49,7 @@ const ManagerMenu = React.createClass({
entries: [],
role: "",
onItemClick: () => {},
itemSelected: () => {},
title: <MenuItem header>Manager</MenuItem>,
controls: [],
mapType: "leaflet",
Expand All @@ -63,7 +66,7 @@ const ManagerMenu = React.createClass({
getTools() {
return [{element: <span key="burger-menu-title">{this.props.title}</span>}, ...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 ? <Message msgId={entry.msgId} /> : entry.text,
cfg: {...entry}
};
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 23 additions & 1 deletion web/client/reducers/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

/******************************************************************************/
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit 82e3c25

Please sign in to comment.