Skip to content

Commit

Permalink
Externalized maptype selectors (#1817)
Browse files Browse the repository at this point in the history
* Externalized maptype selectors to improve testability and reusability

* add documentation for selectors
  • Loading branch information
offtherailz authored May 12, 2017
1 parent c4112e5 commit ab6ea7e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docma-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
"web/client/actions/maptype.js",
"web/client/actions/search.js",

"web/client/selectors/index.jsdoc",
"web/client/selectors/map.js",
"web/client/selectors/maptype.js",

"web/client/reducers/index.jsdoc",
"web/client/reducers/controls.js",
"web/client/reducers/globeswitcher.js",
Expand Down
12 changes: 8 additions & 4 deletions web/client/plugins/GlobeViewSwitcher.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const assign = require('object-assign');
const globeswitcher = require('../reducers/globeswitcher');
const epics = require('../epics/globeswitcher');
const {toggle3d} = require('../actions/globeswitcher');
const {mapTypeSelector, isCesium} = require('../selectors/maptype');
const {createSelector} = require('reselect');
const GlobeViewSwitcherButton = require('../components/buttons/GlobeViewSwitcherButton');

/**
Expand All @@ -23,12 +25,14 @@ const GlobeViewSwitcherButton = require('../components/buttons/GlobeViewSwitcher
* @prop {string} cfg.id identifier of the Plugin
*
*/
const GlobeViewSwitcher = connect( ({maptype = {}} = {}) => ({
active: maptype && maptype.mapType === "cesium",

let globeSelector = createSelector([mapTypeSelector, isCesium], (mapType = "leaflet", cesium) => ({
active: cesium,
options: {
originalMapType: maptype && maptype.mapType || "leaflet"
originalMapType: mapType
}
}), {
}));
const GlobeViewSwitcher = connect(globeSelector, {
onClick: (pressed, options) => toggle3d(pressed, options.originalMapType)
})(GlobeViewSwitcherButton);

Expand Down
27 changes: 27 additions & 0 deletions web/client/selectors/__tests__/maptype-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2017, 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 expect = require('expect');
const {mapTypeSelector, isCesium} = require('../maptype');

describe('Test maptype', () => {
it('test mapTypeSelector', () => {
const mapType = mapTypeSelector({maptype: {mapType: "cesium"}});

expect(mapType).toExist();
expect(mapType).toBe("cesium");
});

it('test isCesium', () => {
const bool = isCesium({maptype: {mapType: "cesium"}});
expect(bool).toExist();
expect(bool).toBe(true);
expect(isCesium({maptype: {mapType: "leaflet"}})).toBe(false);
});
});
29 changes: 29 additions & 0 deletions web/client/selectors/maptype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2017, 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.
*/

/**
* selects maptype from state
* @memberof selectors.maptype
* @param {object} state the state
* @return {string} the maptype in the state
*/
const mapTypeSelector = (state) => state && state.maptype && state.maptype.mapType;

/**
* Check if the mapType is cesium
* @function
* @memberof selectors.maptype
* @param {object} state the state
* @return {boolean}
*/
const isCesium = state => mapTypeSelector(state) === "cesium";

module.exports = {
mapTypeSelector,
isCesium
};

0 comments on commit ab6ea7e

Please sign in to comment.