Skip to content

Commit b3215da

Browse files
committed
Fix #3564. Annotation panel closes when annotation layer removed
1 parent 7b9369b commit b3215da

2 files changed

Lines changed: 85 additions & 4 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
10+
const expect = require('expect');
11+
const {
12+
modeSelector,
13+
annotationsListSelector
14+
} = require('../annotations');
15+
16+
17+
describe('Test annotations selectors', () => {
18+
it('modeSelector', () => {
19+
// list mode
20+
expect(modeSelector({
21+
annotations: { editing: false }
22+
})).toBe('list');
23+
// editing mode
24+
expect(modeSelector({
25+
annotations: {editing: true}
26+
})).toBe('editing');
27+
28+
// detail mode
29+
expect(modeSelector({
30+
layers: {
31+
flat: [{id: 'annotations'}]
32+
},
33+
annotations: {
34+
current: true
35+
}
36+
})).toBe('detail');
37+
38+
// list mode if annotations layer is not present and editing deactivated
39+
expect(modeSelector({
40+
layers: {
41+
flat: [{ id: 'OTHER_LAYER' }]
42+
},
43+
annotations: {
44+
current: true
45+
}
46+
})).toBe('list');
47+
});
48+
49+
it('annotationsListSelector', () => {
50+
// list mode
51+
expect(annotationsListSelector({
52+
annotations: { editing: false }
53+
}).mode).toBe('list');
54+
// editing mode
55+
expect(annotationsListSelector({
56+
annotations: { editing: true }
57+
}).mode).toBe('editing');
58+
59+
// detail mode
60+
expect(annotationsListSelector({
61+
layers: {
62+
flat: [{ id: 'annotations' }]
63+
},
64+
annotations: {
65+
current: true
66+
}
67+
}).mode).toBe('detail');
68+
69+
// list mode if annotations layer is not present and editing deactivated
70+
expect(annotationsListSelector({
71+
layers: {
72+
flat: [{ id: 'OTHER_LAYER' }]
73+
},
74+
annotations: {
75+
current: true
76+
}
77+
}).mode).toBe('list');
78+
});
79+
});

web/client/selectors/annotations.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const removingSelector = (state) => get(state, "annotations.removing");
1919
const closingSelector = (state) => !!get(state, "annotations.closing");
2020
const editingSelector = (state) => get(state, "annotations.editing");
2121
const currentSelector = (state) => get(state, "annotations.current");
22-
const modeSelector = (state) => editingSelector(state) && 'editing' || currentSelector(state) && 'detail' || 'list';
22+
const modeSelector = (state) => editingSelector(state) && 'editing' || annotationsLayerSelector(state) && currentSelector(state) && 'detail' || 'list';
2323

2424
const annotationsInfoSelector = (state) => (assign({}, {
2525
editing: editingSelector(state),
@@ -40,11 +40,12 @@ const annotationsSelector = (state) => ({
4040
const annotationsListSelector = createSelector([
4141
annotationsInfoSelector,
4242
annotationsSelector,
43-
annotationsLayerSelector
44-
], (info, annotations, layer) => (assign({}, {
43+
annotationsLayerSelector,
44+
modeSelector
45+
], (info, annotations, layer, mode) => (assign({}, {
4546
removing: annotations.removing,
4647
closing: !!annotations.closing,
47-
mode: annotations.editing && 'editing' || annotations.current && 'detail' || 'list',
48+
mode,
4849
annotations: layer && layer.features || [],
4950
current: annotations.current || null,
5051
editing: info.editing,
@@ -61,6 +62,7 @@ const annotationSelector = createSelector([annotationsListSelector], (annotation
6162
});
6263

6364
module.exports = {
65+
modeSelector,
6466
annotationsLayerSelector,
6567
annotationsInfoSelector,
6668
annotationsSelector,

0 commit comments

Comments
 (0)