Skip to content

Commit

Permalink
Fix #3958 hide layer related buttons when removing a layer from the m…
Browse files Browse the repository at this point in the history
…ap (#3980)
  • Loading branch information
kasongoyo authored and offtherailz committed Jul 22, 2019
1 parent c31db91 commit d28f792
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
1 change: 1 addition & 0 deletions web/client/plugins/widgetbuilder/MapBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module.exports = mapBuilder(({
selectedNodes={selectedNodes}
selectedLayers={selectedLayers}
selectedGroups={selectedGroups}
onNodeSelect={onNodeSelect}
toggleLayerSelector={toggleLayerSelector}/></BuilderHeader>)}
>
{enabled ? <Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@


/*
* Copyright 2019, 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.
*/

// dependencies
const React = require('react');
const ReactDOM = require('react-dom');
const expect = require('expect');
const ReactTestUtils = require('react-dom/test-utils');
const handleMapRemoveLayer = require('../handleMapRemoveLayer');
const CMP = handleMapRemoveLayer((props) => <button id="CMP" onClick={() => props.onRemoveSelected()} />);

describe('handleMapRemoveLayer enhancer', function() {
beforeEach((done) => {
document.body.innerHTML = '<div id="container"></div>';
setTimeout(done);
});

afterEach((done) => {
ReactDOM.unmountComponentAtNode(document.getElementById("container"));
document.body.innerHTML = '';
setTimeout(done);
});

it('layer remove must also unselect the layers by triggering onNodeSelect', () => {
const lib = {
onNodeSelect() { }
};
const spyReset = expect.spyOn(lib, 'onNodeSelect');
ReactDOM.render(<CMP selectedLayers={['layer 1']} onNodeSelect={lib.onNodeSelect} />, document.getElementById("container"));
const el = document.querySelector('#CMP');
ReactTestUtils.Simulate.click(el);
expect(spyReset).toHaveBeenCalled();
});
});
18 changes: 18 additions & 0 deletions web/client/plugins/widgetbuilder/enhancers/handleMapRemoveLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2019, 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 { withHandlers } = require('recompose');

const enhancer = withHandlers({
onRemoveSelected: ({ selectedLayers = [], removeLayersById = () => { }, onNodeSelect = () => { } }) => () => {
removeLayersById(selectedLayers);
selectedLayers.forEach(layer => onNodeSelect(layer, 'layer', false));
}
});

module.exports = enhancer;
9 changes: 3 additions & 6 deletions web/client/plugins/widgetbuilder/enhancers/mapToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const { compose, branch, withProps, withHandlers} = require('recompose');
const { compose, branch, withProps } = require('recompose');
const {connect} = require('react-redux');
const { insertWidget, setPage, onEditorChange} = require('../../../actions/widgets');
const manageLayers = require('./manageLayers');
const handleNodeEditing = require('./handleNodeEditing');
const handleRemoveLayer = require('./handleMapRemoveLayer');
const { wizardSelector, wizardStateToProps } = require('../commons');

const mapBuilderConnect = require('./connection/mapBuilderConnect');
Expand All @@ -25,11 +26,7 @@ module.exports = compose(
),
manageLayers,
handleNodeEditing,
withHandlers({
onRemoveSelected: ({selectedLayers = [], removeLayersById = () => { } }) => () => {
removeLayersById(selectedLayers);
}
}),
handleRemoveLayer,
branch(
({editNode}) => !!editNode,
withProps(({ selectedNodes = [], setEditNode = () => { } }) => ({
Expand Down

0 comments on commit d28f792

Please sign in to comment.