Skip to content

Commit 42df532

Browse files
committed
Support for external close action for identify
1 parent 0ae6ea7 commit 42df532

4 files changed

Lines changed: 64 additions & 11 deletions

File tree

web/client/actions/mapInfo.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const CLEAR_WARNING = 'CLEAR_WARNING';
2828
const FEATURE_INFO_CLICK = 'FEATURE_INFO_CLICK';
2929
const TOGGLE_MAPINFO_STATE = 'TOGGLE_MAPINFO_STATE';
3030
const UPDATE_CENTER_TO_MARKER = 'UPDATE_CENTER_TO_MARKER';
31+
const CLOSE_IDENTIFY = 'IDENTIFY:CLOSE_IDENTIFY';
3132

3233
/**
3334
* Private
@@ -207,6 +208,9 @@ function updateCenterToMarker(status) {
207208
status
208209
};
209210
}
211+
const closeIdentify = () => ({
212+
type: CLOSE_IDENTIFY
213+
});
210214

211215
module.exports = {
212216
ERROR_FEATURE_INFO,
@@ -226,6 +230,8 @@ module.exports = {
226230
FEATURE_INFO_CLICK,
227231
TOGGLE_MAPINFO_STATE,
228232
UPDATE_CENTER_TO_MARKER,
233+
CLOSE_IDENTIFY,
234+
closeIdentify,
229235
getFeatureInfo,
230236
changeMapInfoState,
231237
newMapInfoRequest,

web/client/epics/__tests__/identify-test.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
const expect = require('expect');
1010

1111
const {ZOOM_TO_POINT} = require('../../actions/map');
12-
const {FEATURE_INFO_CLICK, UPDATE_CENTER_TO_MARKER, loadFeatureInfo} = require('../../actions/mapInfo');
13-
const {zoomToVisibleAreaEpic} = require('../identify');
12+
const { FEATURE_INFO_CLICK, UPDATE_CENTER_TO_MARKER, PURGE_MAPINFO_RESULTS, loadFeatureInfo, closeIdentify} = require('../../actions/mapInfo');
13+
const { zoomToVisibleAreaEpic, closeFeatureInfoOnEdit} = require('../identify');
14+
const { CLOSE_ANNOTATIONS } = require('../../actions/annotations');
1415
const {testEpic} = require('./epicTestUtils');
1516
const {registerHook} = require('../../utils/MapUtils');
1617

@@ -130,5 +131,43 @@ describe('identify Epics', () => {
130131

131132
testEpic(zoomToVisibleAreaEpic, 1, sentActions, expectedAction, state);
132133
});
134+
it('closeFeatureInfoOnEdit', (done) => {
135+
136+
const sentActions = closeIdentify();
137+
138+
const expectedAction = actions => {
139+
expect(actions.length).toBe(1);
140+
actions.map((action) => {
141+
switch (action.type) {
142+
case CLOSE_ANNOTATIONS:
143+
done();
144+
break;
145+
default:
146+
expect(true).toBe(false);
147+
}
148+
});
149+
};
150+
151+
testEpic(closeFeatureInfoOnEdit, 1, sentActions, expectedAction, { annotations: { editing: true } });
152+
});
153+
it('closeFeatureInfoOnEdit', (done) => {
154+
155+
const sentActions = closeIdentify();
156+
157+
const expectedAction = actions => {
158+
expect(actions.length).toBe(1);
159+
actions.map((action) => {
160+
switch (action.type) {
161+
case PURGE_MAPINFO_RESULTS:
162+
done();
163+
break;
164+
default:
165+
expect(true).toBe(false);
166+
}
167+
});
168+
};
169+
170+
testEpic(closeFeatureInfoOnEdit, 1, sentActions, expectedAction);
171+
});
133172

134173
});

web/client/epics/identify.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88
const Rx = require('rxjs');
9+
const {get} = require('lodash');
910

10-
const {LOAD_FEATURE_INFO, ERROR_FEATURE_INFO, GET_VECTOR_INFO, FEATURE_INFO_CLICK, updateCenterToMarker} = require('../actions/mapInfo');
11+
const { LOAD_FEATURE_INFO, ERROR_FEATURE_INFO, GET_VECTOR_INFO, FEATURE_INFO_CLICK, CLOSE_IDENTIFY, updateCenterToMarker, purgeMapInfoResults} = require('../actions/mapInfo');
1112
const {closeFeatureGrid} = require('../actions/featuregrid');
1213
const {CHANGE_MOUSE_POINTER, CLICK_ON_MAP, zoomToPoint} = require('../actions/map');
14+
const { closeAnnotations } = require('../actions/annotations');
1315
const {MAP_CONFIG_LOADED} = require('../actions/config');
1416
const {stopGetFeatureInfoSelector} = require('../selectors/mapinfo');
1517
const {centerToMarkerSelector} = require('../selectors/layers');
@@ -30,6 +32,17 @@ module.exports = {
3032
.switchMap(() => {
3133
return Rx.Observable.of(closeFeatureGrid());
3234
}),
35+
/**
36+
* Check if something is editing in feature info.
37+
* If so, as to the proper tool to close (annotations)
38+
* Otherwise it closes by itself.
39+
*/
40+
closeFeatureInfoOnEdit: (action$, {getState = () => {}} = {}) =>
41+
action$.ofType(CLOSE_IDENTIFY).switchMap( () =>
42+
get(getState(), "annotations.editing")
43+
? Rx.Observable.of(closeAnnotations())
44+
: Rx.Observable.of(purgeMapInfoResults())
45+
),
3346
changeMapPointer: (action$, store) =>
3447
action$.ofType(CHANGE_MOUSE_POINTER)
3548
.filter(() => !(store.getState()).map)

web/client/plugins/Identify.jsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ const {createSelector} = require('reselect');
1414

1515
const {mapSelector} = require('../selectors/map');
1616
const {layersSelector} = require('../selectors/layers');
17-
const {on} = require('../actions/controls');
1817

19-
const {getFeatureInfo, getVectorInfo, purgeMapInfoResults, showMapinfoMarker, hideMapinfoMarker, showMapinfoRevGeocode, hideMapinfoRevGeocode, noQueryableLayers, clearWarning, toggleMapInfoState} = require('../actions/mapInfo');
20-
const {closeAnnotations} = require('../actions/annotations');
18+
const {getFeatureInfo, getVectorInfo, showMapinfoMarker, hideMapinfoMarker, showMapinfoRevGeocode, hideMapinfoRevGeocode, noQueryableLayers, clearWarning, toggleMapInfoState} = require('../actions/mapInfo');
2119
const {changeMousePointer} = require('../actions/map');
22-
const {changeMapInfoFormat, updateCenterToMarker} = require('../actions/mapInfo');
20+
const {changeMapInfoFormat, updateCenterToMarker, closeIdentify} = require('../actions/mapInfo');
2321
const {currentLocaleSelector} = require('../selectors/locale');
2422

2523
const {compose, defaultProps} = require('recompose');
@@ -54,9 +52,6 @@ const selector = createSelector([
5452
}));
5553
// result panel
5654

57-
const conditionalToggle = on.bind(null, purgeMapInfoResults(), (state) =>
58-
!(state.annotations && state.annotations.editing)
59-
, closeAnnotations);
6055

6156
const DefaultViewer = compose(
6257
switchControlledDefaultViewer,
@@ -168,7 +163,7 @@ const IdentifyPlugin = compose(
168163
connect(selector, {
169164
sendRequest: getFeatureInfo,
170165
localRequest: getVectorInfo,
171-
purgeResults: conditionalToggle,
166+
purgeResults: closeIdentify,
172167
changeMousePointer,
173168
showMarker: showMapinfoMarker,
174169
noQueryableLayers,

0 commit comments

Comments
 (0)