Skip to content

Commit 6f97bce

Browse files
authored
Fix #3562. Fixed API map load action sequence (#3566)
1 parent 108f4b5 commit 6f97bce

7 files changed

Lines changed: 181 additions & 8 deletions

File tree

web/client/components/development/Debug.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const urlQuery = url.parse(window.location.href, true).query;
1616

1717
class Debug extends React.Component {
1818
render() {
19-
if (__DEVTOOLS__ && urlQuery.debug && !window.devToolsExtension) {
19+
if (urlQuery && urlQuery.debug && __DEVTOOLS__ && !window.devToolsExtension) {
2020
const DevTools = require('./DevTools');
2121
return (
2222
<DevTools/>

web/client/containers/Embedded.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const url = require('url');
1515
const urlQuery = url.parse(window.location.href, true).query;
1616
const PluginsUtils = require('../utils/PluginsUtils');
1717
const ConfigUtils = require('../utils/ConfigUtils');
18-
const {initMap} = require('../actions/map');
1918

2019
const PluginsContainer = connect((state) => ({
2120
mode: urlQuery.mode || (state.browser && state.browser.mobile ? 'mobile' : 'desktop'),
@@ -55,6 +54,4 @@ class Embedded extends React.Component {
5554
}
5655
}
5756

58-
module.exports = connect(() => ({}), {
59-
onInit: initMap
60-
})(Embedded);
57+
module.exports = Embedded;

web/client/jsapi/MapStore2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const ConfigUtils = require('../utils/ConfigUtils');
1414
const {connect} = require('react-redux');
1515

1616
const {configureMap, loadMapConfig} = require('../actions/config');
17+
const { initMap } = require('../actions/map');
1718
const {generateActionTrigger} = require('../epics/jsapi');
1819

1920
const url = require('url');
@@ -93,7 +94,7 @@ let stateChangeListeners = [];
9394
const getInitialActions = (options) => {
9495
if (!options.initialState || !options.initialState.defaultState.map) {
9596
if (options.configUrl) {
96-
return [loadMapConfig.bind(null, options.configUrl || defaultConfig, options.mapId)];
97+
return [initMap, loadMapConfig.bind(null, options.configUrl || defaultConfig, options.mapId)];
9798
}
9899
return [configureMap.bind(null, options.config || defaultConfig, options.mapId)];
99100
}
@@ -183,7 +184,8 @@ const MapStore2 = {
183184
const appStore = require('../stores/StandardStore').bind(null, initialState || {}, {
184185
version: require('../reducers/version')
185186
}, {
186-
jsAPIEpic: actionTrigger.epic
187+
jsAPIEpic: actionTrigger.epic,
188+
...(options.epics || {})
187189
});
188190
const initialActions = [...getInitialActions(options), loadVersion.bind(null, options.versionURL)];
189191
const appConfig = {
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright 2019, GeoSolutions Sas.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
const ReactDOM = require('react-dom');
10+
const {findIndex} = require('lodash');
11+
const ConfigUtils = require('../../utils/ConfigUtils');
12+
const { INIT_MAP } = require('../../actions/map');
13+
const { MAP_CONFIG_LOADED } = require('../../actions/config');
14+
const { CHANGE_BROWSER_PROPERTIES } = require('../../actions/browser');
15+
16+
const { LOCAL_CONFIG_LOADED } = require('../../actions/localConfig');
17+
18+
19+
const expect = require('expect');
20+
const MapStore2 = require('../MapStore2');
21+
22+
const testConfig = {
23+
versionURL: 'base/web/client/test-resources/version.txt',
24+
configUrl: 'base/web/client/test-resources/geostore/data/1#',
25+
originalUrl: 'base/web/client/test-resources/geostore/extjs/search/category/MAP/1.json#'
26+
};
27+
describe('MapStore2 API', () => {
28+
beforeEach((done) => {
29+
document.body.innerHTML = '<div id="container"></div>';
30+
ConfigUtils.setLocalConfigurationFile('base/web/client/test-resources/localConfig.json');
31+
ConfigUtils.setConfigProp('translationsPath', "base/web/client/translations");
32+
setTimeout(done);
33+
});
34+
afterEach((done) => {
35+
ReactDOM.unmountComponentAtNode(document.getElementById("container"));
36+
ConfigUtils.setLocalConfigurationFile('localConfig.json');
37+
ConfigUtils.setConfigProp('translationsPath', "translations");
38+
document.body.innerHTML = '';
39+
setTimeout(done);
40+
});
41+
it('MapStore2 rendering with defaults', (done) => {
42+
43+
MapStore2.create('container', {
44+
epics: {
45+
testEpic1: action$ => action$
46+
.filter(a => a.type === CHANGE_BROWSER_PROPERTIES).do( () => {
47+
// CHANGE BROWSER PROPERTIES IS THE FIRST ACTION
48+
done();
49+
}).ignoreElements()
50+
},
51+
...testConfig
52+
});
53+
});
54+
it('initMap action called before map load action', (done) => {
55+
56+
MapStore2.create('container', {
57+
epics: {
58+
testEpic1: action$ => action$
59+
.bufferCount(5).do((actions) => {
60+
expect(findIndex(actions, a => a.type === INIT_MAP)).toBeLessThan(findIndex(actions, a => a.type === MAP_CONFIG_LOADED));
61+
done();
62+
}).ignoreElements()
63+
},
64+
...testConfig
65+
});
66+
});
67+
it('onAction', (done) => {
68+
69+
MapStore2.create('container', {
70+
...testConfig
71+
});
72+
MapStore2.onAction(MAP_CONFIG_LOADED, () => done());
73+
});
74+
it('offAction', (done) => {
75+
MapStore2.create('container', {
76+
epics: {
77+
testEpic1: action$ => action$
78+
.bufferCount(5).do((actions) => {
79+
// the action has been emitted but the listener has not been called
80+
expect(findIndex(actions, a => a.type === LOCAL_CONFIG_LOADED)).toBeLessThan(5);
81+
done();
82+
}).ignoreElements()
83+
},
84+
...testConfig
85+
});
86+
const listenerToDeactivate = () => expect(true).toBe(false);
87+
MapStore2.onAction(LOCAL_CONFIG_LOADED, listenerToDeactivate);
88+
MapStore2.offAction(LOCAL_CONFIG_LOADED, listenerToDeactivate);
89+
});
90+
it('onStateChange', (done) => {
91+
92+
MapStore2.create('container', {
93+
...testConfig
94+
});
95+
let counter = 0;
96+
MapStore2.onStateChange( state => {
97+
if (state.map) {
98+
// this has been triggered more than once before the map to be loaded
99+
expect(counter).toBeGreaterThan(0);
100+
done();
101+
} else {
102+
counter++;
103+
}
104+
});
105+
});
106+
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"map": {
3+
"projection": "EPSG:900913",
4+
"units": "m",
5+
"center": {"x": 1250000.000000, "y": 5370000.000000, "crs": "EPSG:900913"},
6+
"zoom":5,
7+
"maxExtent": [
8+
-20037508.34, -20037508.34,
9+
20037508.34, 20037508.34
10+
],
11+
"layers": [
12+
{
13+
"type": "osm",
14+
"title": "Open Street Map",
15+
"name": "mapnik",
16+
"source": "osm",
17+
"group": "background",
18+
"visibility": true
19+
},
20+
{
21+
"type": "tileprovider",
22+
"title": "NASAGIBS Night 2012",
23+
"provider": "NASAGIBS.ViirsEarthAtNight2012",
24+
"name": "Night2012",
25+
"source": "nasagibs",
26+
"group": "background",
27+
"visibility": false
28+
},
29+
{
30+
"type": "tileprovider",
31+
"title": "OpenTopoMap",
32+
"provider": "OpenTopoMap",
33+
"name": "OpenTopoMap",
34+
"source": "OpenTopoMap",
35+
"group": "background",
36+
"visibility": false
37+
},
38+
{
39+
"format": "image/jpeg",
40+
"group": "background",
41+
"name": "s2cloudless:s2cloudless",
42+
"opacity": 1,
43+
"title": "Sentinel 2 Cloudless",
44+
"type": "wms",
45+
"url": [
46+
"https://1maps.geo-solutions.it/geoserver/wms", "https://2maps.geo-solutions.it/geoserver/wms", "https://3maps.geo-solutions.it/geoserver/wms", "https://4maps.geo-solutions.it/geoserver/wms", "https://5maps.geo-solutions.it/geoserver/wms", "https://6maps.geo-solutions.it/geoserver/wms"
47+
],
48+
"source": "s2cloudless",
49+
"visibility": false,
50+
"singleTile": false
51+
},
52+
{
53+
"source": "ol",
54+
"group": "background",
55+
"title": "Empty Background",
56+
"fixed": true,
57+
"type": "empty",
58+
"visibility": false,
59+
"args": [
60+
"Empty Background", {
61+
"visibility": false
62+
}
63+
]
64+
}
65+
]
66+
}
67+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TEST

web/client/utils/DebugUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var warningFilterKey = function(warning) {
2424
var DebugUtils = {
2525
createDebugStore: function(reducer, initialState, userMiddlewares, enhancer) {
2626
let finalCreateStore;
27-
if (__DEVTOOLS__ && urlQuery.debug) {
27+
if (urlQuery && urlQuery.debug && __DEVTOOLS__) {
2828
let logger = require('redux-logger')();
2929
let immutable = require('redux-immutable-state-invariant')();
3030
let middlewares = [immutable, thunkMiddleware, logger].concat(userMiddlewares || []);

0 commit comments

Comments
 (0)