Skip to content

Commit 5cac5b3

Browse files
committed
Fix #3578. Fix issues with layernames containing points
1 parent cbaf5b4 commit 5cac5b3

6 files changed

Lines changed: 96 additions & 35 deletions

File tree

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const {CHANGE_LAYER_PROPERTIES} = require('../../actions/layers');
5454
const {geometryChanged} = require('../../actions/draw');
5555

5656
const {layerSelectedForSearch, UPDATE_QUERY} = require('../../actions/wfsquery');
57-
57+
const {LOAD_FILTER} = require('../../actions/queryform');
5858

5959
const {
6060
setHighlightFeaturesPath,
@@ -1479,18 +1479,24 @@ describe('featuregrid Epics', () => {
14791479
}, newState);
14801480
});
14811481

1482-
it('test onOpenAdvancedSearch to throw drawstatechange if drawStatus is not clean on queryPanel close', (done) => {
1482+
it('test onOpenAdvancedSearch', (done) => {
14831483
const stateFeaturegrid = {
14841484
featuregrid: {
14851485
open: true,
1486-
selectedLayer: "TEST__6",
1486+
// layer id with `.` and `:`
1487+
selectedLayer: "TEST:A.LAYER__6",
14871488
mode: 'EDIT',
14881489
select: [{id: 'polygons.1', _new: 'polygons._new'}],
1489-
changes: []
1490+
changes: [],
1491+
advancedFilters: {
1492+
"TEST:A.LAYER__6": {
1493+
"someFilter": "something"
1494+
}
1495+
}
14901496
},
14911497
layers: {
14921498
flat: [{
1493-
id: "TEST__6",
1499+
id: "TEST:A.LAYER__6",
14941500
name: "V_TEST",
14951501
title: "V_TEST",
14961502
filterObj,
@@ -1508,7 +1514,12 @@ describe('featuregrid Epics', () => {
15081514
expect(actions.length).toBe(4);
15091515
actions.map((action) => {
15101516
switch (action.type) {
1517+
case LOAD_FILTER:
1518+
// load filter, if present
1519+
expect(action.filter).toExist();
1520+
break;
15111521
case CHANGE_DRAWING_STATUS:
1522+
// throw drawstatechange if drawStatus is not clean on queryPanel close
15121523
expect(action.status).toBe('clean');
15131524
break;
15141525
default:

web/client/epics/featuregrid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const createLoadPageFlow = (store) => ({page, size} = {}) => {
171171
};
172172

173173
const createInitialQueryFlow = (action$, store, {url, name, id} = {}) => {
174-
const filterObj = get(store.getState(), `featuregrid.advancedFilters.${id}`);
174+
const filterObj = get(store.getState(), `featuregrid.advancedFilters["${id}"]`);
175175
const createInitialQuery = () => createQuery(url, filterObj || {
176176
featureTypeName: name,
177177
filterType: 'OGC',
@@ -606,7 +606,7 @@ module.exports = {
606606
onOpenAdvancedSearch: (action$, store) =>
607607
action$.ofType(OPEN_ADVANCED_SEARCH).switchMap(() => {
608608
return Rx.Observable.of(
609-
loadFilter(get(store.getState(), `featuregrid.advancedFilters.${selectedLayerIdSelector(store.getState())}`)),
609+
loadFilter(get(store.getState(), `featuregrid.advancedFilters["${selectedLayerIdSelector(store.getState())}"]`)),
610610
closeFeatureGrid(),
611611
setControlProperty('queryPanel', "enabled", true)
612612
)

web/client/selectors/__tests__/featuregrid-test.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ let feature2 = {
6464
let initialState = {
6565
query: {
6666
featureTypes: {
67-
'editing:polygons': {
67+
// use name with chars ":" and "."
68+
'editing:polygons.test': {
6869
geometry: [
6970
{
7071
label: 'geometry',
@@ -259,7 +260,7 @@ let initialState = {
259260
resultError: null,
260261
isNew: false,
261262
filterObj: {
262-
featureTypeName: 'editing:polygons',
263+
featureTypeName: 'editing:polygons.test',
263264
groupFields: [
264265
{
265266
id: 1,
@@ -284,7 +285,7 @@ let initialState = {
284285
hits: false
285286
},
286287
searchUrl: 'http://localhost:8081/geoserver/wfs?',
287-
typeName: 'editing:polygons',
288+
typeName: 'editing:polygons.test',
288289
url: 'http://localhost:8081/geoserver/wfs?',
289290
featureLoading: false
290291
},
@@ -458,14 +459,14 @@ describe('Test featuregrid selectors', () => {
458459
it('test hasSupportedGeometry', () => {
459460
expect(hasSupportedGeometry(initialState)).toBe(true);
460461
let initialStateWithGmlGeometry = assign({}, initialState);
461-
initialStateWithGmlGeometry.query.featureTypes['editing:polygons'].original.featureTypes[0].properties[1].type = 'gml:Geometry';
462-
initialStateWithGmlGeometry.query.featureTypes['editing:polygons'].original.featureTypes[0].properties[1].localType = 'Geometry';
462+
initialStateWithGmlGeometry.query.featureTypes['editing:polygons.test'].original.featureTypes[0].properties[1].type = 'gml:Geometry';
463+
initialStateWithGmlGeometry.query.featureTypes['editing:polygons.test'].original.featureTypes[0].properties[1].localType = 'Geometry';
463464
expect(hasSupportedGeometry(initialStateWithGmlGeometry)).toBe(false);
464-
initialStateWithGmlGeometry.query.featureTypes['editing:polygons'].original.featureTypes[0].properties[1].type = 'gml:GeometryCollection';
465-
initialStateWithGmlGeometry.query.featureTypes['editing:polygons'].original.featureTypes[0].properties[1].localType = 'GeometryCollection';
465+
initialStateWithGmlGeometry.query.featureTypes['editing:polygons.test'].original.featureTypes[0].properties[1].type = 'gml:GeometryCollection';
466+
initialStateWithGmlGeometry.query.featureTypes['editing:polygons.test'].original.featureTypes[0].properties[1].localType = 'GeometryCollection';
466467
expect(hasSupportedGeometry(initialStateWithGmlGeometry)).toBe(false);
467-
initialStateWithGmlGeometry.query.featureTypes['editing:polygons'].original.featureTypes[0].properties[1].type = 'gml:Polygon';
468-
initialStateWithGmlGeometry.query.featureTypes['editing:polygons'].original.featureTypes[0].properties[1].localType = 'Polygon';
468+
initialStateWithGmlGeometry.query.featureTypes['editing:polygons.test'].original.featureTypes[0].properties[1].type = 'gml:Polygon';
469+
initialStateWithGmlGeometry.query.featureTypes['editing:polygons.test'].original.featureTypes[0].properties[1].localType = 'Polygon';
469470
expect(hasSupportedGeometry(initialStateWithGmlGeometry)).toBe(true);
470471

471472
});
@@ -480,7 +481,7 @@ describe('Test featuregrid selectors', () => {
480481
flat: [{
481482
id: "TEST_LAYER",
482483
title: "Test Layer",
483-
name: 'editing:polygons'
484+
name: 'editing:polygons.test'
484485
}]
485486
}, featuregrid: {
486487
open: true,
@@ -489,7 +490,7 @@ describe('Test featuregrid selectors', () => {
489490
select: [feature1, feature2],
490491
changes: [{id: feature2.id, updated: {geometry: null}}]
491492
}};
492-
expect(selectedLayerNameSelector(state)).toBe('editing:polygons');
493+
expect(selectedLayerNameSelector(state)).toBe('editing:polygons.test');
493494
expect(selectedLayerNameSelector({})).toBe('');
494495
});
495496
it('queryOptionsSelector gets viewParams', () => {
@@ -498,7 +499,7 @@ describe('Test featuregrid selectors', () => {
498499
flat: [{
499500
id: "TEST_LAYER",
500501
title: "Test Layer",
501-
name: 'editing:polygons',
502+
name: 'editing:polygons.test',
502503
params: {
503504
viewParams: "a:b"
504505
}
@@ -519,7 +520,7 @@ describe('Test featuregrid selectors', () => {
519520
flat: [{
520521
id: "TEST_LAYER",
521522
title: "Test Layer",
522-
name: 'editing:polygons',
523+
name: 'editing:polygons.test',
523524
params: {
524525
CQL_FILTER: "a:b"
525526
}

web/client/selectors/__tests__/query-test.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ const {
1818
featureLoadingSelector,
1919
isDescribeLoaded,
2020
describeSelector,
21+
featureTypeSelectorCreator,
2122
getFeatureById,
2223
attributesSelector,
2324
isSyncWmsActive,
2425
isFilterActive
2526
} = require('../query');
26-
27+
const STRANGE_LAYER_NAME = "test.workspace:test.layer";
2728
const idFt1 = "idFt1";
2829
const idFt2 = "idFt2";
2930
const modeEdit = "edit";
@@ -53,7 +54,7 @@ let feature2 = {
5354
const initialState = {
5455
query: {
5556
featureTypes: {
56-
'editing:polygons': {
57+
'editing:polygons.layer': {
5758
geometry: [
5859
{
5960
label: 'geometry',
@@ -258,7 +259,8 @@ const initialState = {
258259
open: true,
259260
isNew: false,
260261
filterObj: {
261-
featureTypeName: 'editing:polygons',
262+
// name with point and strange chars
263+
featureTypeName: 'editing:polygons.layer',
262264
groupFields: [
263265
{
264266
id: 1,
@@ -283,7 +285,7 @@ const initialState = {
283285
hits: false
284286
},
285287
searchUrl: 'http://localhost:8081/geoserver/wfs?',
286-
typeName: 'editing:polygons',
288+
typeName: 'editing:polygons.layer',
287289
syncWmsFilter: true,
288290
url: 'http://localhost:8081/geoserver/wfs?',
289291
featureLoading: false
@@ -312,7 +314,7 @@ describe('Test query selectors', () => {
312314
it('test typeNameSelector selector', () => {
313315
const typename = typeNameSelector(initialState);
314316
expect(typename).toExist();
315-
expect(typename).toBe("editing:polygons");
317+
expect(typename).toBe("editing:polygons.layer");
316318
});
317319
it('test isSyncWmsActive selector', () => {
318320
const sync = isSyncWmsActive(initialState);
@@ -322,7 +324,7 @@ describe('Test query selectors', () => {
322324
it('test wfsFilter selector', () => {
323325
const filterObj = wfsFilter(initialState);
324326
expect(filterObj).toExist();
325-
expect(filterObj.featureTypeName).toBe("editing:polygons");
327+
expect(filterObj.featureTypeName).toBe("editing:polygons.layer");
326328
});
327329
it('test resultsSelector selector', () => {
328330
const res = resultsSelector(initialState);
@@ -354,7 +356,7 @@ describe('Test query selectors', () => {
354356
expect(describe.elementFormDefault).toBe("qualified");
355357
});
356358
it('test isDescribeLoaded', () => {
357-
const isLoaded = isDescribeLoaded(initialState, "editing:polygons");
359+
const isLoaded = isDescribeLoaded(initialState, "editing:polygons.layer");
358360
expect(isLoaded).toBe(true);
359361
});
360362
it('test isDescribeLoaded with missing describe', () => {
@@ -365,14 +367,25 @@ describe('Test query selectors', () => {
365367
const isLoaded = isDescribeLoaded({
366368
query: {
367369
featureTypes: {
368-
"editing:polygons": {
370+
"editing:polygons.layer": {
369371
error: "500 internal server error"
370372
}
371373
}
372374
}
373-
}, "editing:polygons");
375+
}, "editing:polygons.layer");
374376
expect(isLoaded).toBe(false);
375377
});
378+
it('featureTypeSelectorCreator', () => {
379+
expect(featureTypeSelectorCreator("editing:polygons.layer")(initialState)).toExist();
380+
});
381+
it('featureTypeSelectorCreator works with layer names with points', () => {
382+
expect(featureTypeSelectorCreator(STRANGE_LAYER_NAME)({
383+
query: {
384+
featureTypes: { [STRANGE_LAYER_NAME]: {
385+
something: "insideThis"
386+
}}}
387+
})).toExist();
388+
});
376389
it('test getFeatureById selector', () => {
377390
const ft = getFeatureById(initialState, "poligoni.7");
378391
expect(ft).toExist();
@@ -385,6 +398,22 @@ describe('Test query selectors', () => {
385398
expect(attr[0].label).toBe("name");
386399
expect(attr[0].valueId).toBe("id");
387400
});
401+
it('test attributesSelector work with featureType names', () => {
402+
const attr = attributesSelector({
403+
query: {
404+
featureTypes: {
405+
[STRANGE_LAYER_NAME]: {
406+
attributes: [{label: "name", valueId: "id"}]
407+
}
408+
},
409+
filterObj: {featureTypeName: STRANGE_LAYER_NAME}
410+
}
411+
});
412+
expect(attr).toExist();
413+
expect(attr.length).toBe(1);
414+
expect(attr[0].label).toBe("name");
415+
expect(attr[0].valueId).toBe("id");
416+
});
388417
it('test featureCollectionResultSelector selector', () => {
389418
const fc = featureCollectionResultSelector(initialState);
390419
expect(fc).toExist();

web/client/selectors/featuregrid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ const getTitle = (layer = {}) => layer.title || layer.name;
1818
const selectedLayerIdSelector = state => get(state, "featuregrid.selectedLayer");
1919
const chartDisabledSelector = state => get(state, "featuregrid.chartDisabled", false);
2020
const getCustomAttributeSettings = (state, att) => get(state, `featuregrid.attributes[${att.name || att.attribute}]`);
21-
const {attributesSelector} = require('./query');
21+
const { attributesSelector, describeSelector } = require('./query');
2222
const selectedFeaturesSelector = state => state && state.featuregrid && state.featuregrid.select;
2323
const changesSelector = state => state && state.featuregrid && state.featuregrid.changes;
2424
const newFeaturesSelector = state => state && state.featuregrid && state.featuregrid.newFeatures;
2525
const selectedFeatureSelector = state => head(selectedFeaturesSelector(state));
2626

2727
const geomTypeSelectedFeatureSelector = state => {
28-
let desc = get(state, `query.featureTypes.${get(state, "query.filterObj.featureTypeName")}.original`);
28+
let desc = describeSelector(state);
2929
if (desc) {
3030
const geomDesc = findGeometryProperty(desc);
3131
return geomDesc && geomDesc.localType;

web/client/selectors/query.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
const {isNil, get, head} = require('lodash');
22

3+
/**
4+
* Selects the featureType name of the query filterObject
5+
* @param {object} state
6+
*/
7+
const queryFeatureTypeName = state => get(state, "query.filterObj.featureTypeName");
8+
/**
9+
* Create a selector for the featureType data (attributes and so on) for the featureType provided as parameter
10+
* @param {string} featureTypeName
11+
* @return {function} a selector to get the featureType data
12+
*/
13+
const featureTypeSelectorCreator = (featureTypeName) => state => get(state, `query.featureTypes["${featureTypeName}"]`);
14+
15+
/**
16+
* Returns the original DescribeFeature JSON object of the passed featureType from the state
17+
* @param {object} state the application state
18+
* @param {string} featureTypeName the featureType name
19+
*/
20+
const layerDescribeSelector = (state, featureTypeName) => get(featureTypeSelectorCreator(featureTypeName)(state), 'original');
21+
322
/**
423
* selects query state
524
* @name query
@@ -11,7 +30,7 @@ module.exports = {
1130
wfsURL: state => state && state.query && state.query.searchUrl,
1231
wfsURLSelector: state => state && state.query && state.query.url,
1332
wfsFilter: state => state && state.query && state.query.filterObj,
14-
attributesSelector: state => get(state, `query.featureTypes.${get(state, "query.filterObj.featureTypeName")}.attributes`),
33+
attributesSelector: state => get(featureTypeSelectorCreator(queryFeatureTypeName(state))(state), `attributes`),
1534
typeNameSelector: state => get(state, "query.typeName"),
1635
resultsSelector: (state) => get(state, "query.result.features"),
1736
featureCollectionResultSelector: state => {
@@ -32,14 +51,15 @@ module.exports = {
3251
totalFeatures: (state) => get(state, "query.result.totalFeatures")
3352
},
3453
isDescribeLoaded: (state, name) => {
35-
const ft = get(state, `query.featureTypes.${name}`);
54+
const ft = featureTypeSelectorCreator(name)(state);
3655
if (ft && ft.attributes && ft.geometry && ft.original) {
3756
return true;
3857
}
3958
return false;
4059
},
41-
describeSelector: (state) => get(state, `query.featureTypes.${get(state, "query.filterObj.featureTypeName")}.original`),
42-
layerDescribeSelector: (state, featureTypeName) =>get(state, `query.featureTypes.[${featureTypeName}].original`),
60+
describeSelector: (state) => layerDescribeSelector(state, queryFeatureTypeName(state)),
61+
featureTypeSelectorCreator,
62+
layerDescribeSelector,
4363
featureLoadingSelector: (state) => get(state, "query.featureLoading"),
4464
isSyncWmsActive: (state) => get(state, "query.syncWmsFilter", false),
4565
/**

0 commit comments

Comments
 (0)