Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9216: handle fixing not visibility of spatial filter for widgets created by attribute table #9674

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion web/client/actions/__tests__/wfsquery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import expect from 'expect';
import {
LAYER_SELECTED_FOR_SEARCH,
FEATURE_TYPE_SELECTED,
FEATURE_TYPE_LOADED,
FEATURE_TYPE_ERROR,
FEATURE_LOADING,
FEATURE_LOADED,
Expand All @@ -25,6 +26,7 @@ import {
initQueryPanel,
layerSelectedForSearch,
featureTypeSelected,
featureTypeLoaded,
featureTypeError,
featureLoading,
featureLoaded,
Expand All @@ -47,13 +49,36 @@ describe('wfsquery actions', () => {
let {type} = initQueryPanel();
expect(type).toBe(INIT_QUERY_PANEL);
});
it('featureTypeSelected', () => {
it('featureTypeSelected without owner', () => {
let {type, url, typeName, fields} = featureTypeSelected("/geoserver/", "topp:states", [{name: "name", alias: "alias"}]);
expect(type).toBe(FEATURE_TYPE_SELECTED);
expect(url).toBe("/geoserver/");
expect(typeName).toBe("topp:states");
expect(fields).toEqual([{name: "name", alias: "alias"}]);
});

it('featureTypeSelected with owner as parameter', () => {
let {type, url, typeName, fields, owner} = featureTypeSelected("/geoserver/", "topp:states", [{name: "name", alias: "alias"}], "owner");
expect(type).toBe(FEATURE_TYPE_SELECTED);
expect(url).toBe("/geoserver/");
expect(typeName).toBe("topp:states");
expect(fields).toEqual([{name: "name", alias: "alias"}]);
expect(owner).toBe("owner");
});
it('featureTypeLoaded without owner', () => {
let {type, typeName, featureType} = featureTypeLoaded("topp:states", "featureType");
expect(type).toBe(FEATURE_TYPE_LOADED);
expect(typeName).toBe("topp:states");
expect(featureType).toBe("featureType");
});

it('featureTypeLoaded with owner as parameter', () => {
let {type, typeName, featureType, owner} = featureTypeLoaded("topp:states", "featureType", "owner");
expect(type).toBe(FEATURE_TYPE_LOADED);
expect(typeName).toBe("topp:states");
expect(featureType).toBe("featureType");
expect(owner).toBe("owner");
});
it('featureTypeError', () => {
let {type, error, typeName} = featureTypeError("topp:states", "ERROR");
expect(type).toBe(FEATURE_TYPE_ERROR);
Expand All @@ -71,6 +96,12 @@ describe('wfsquery actions', () => {
expect(typeName).toBe("topp:states");
expect(feature).toBe(feature);
});
it('featureLoaded with owner as parameter', () => {
let {type, typeName, feature} = featureLoaded("topp:states", "feature");
expect(type).toBe(FEATURE_LOADED);
expect(typeName).toBe("topp:states");
expect(feature).toBe(feature);
});
it('featureError', () => {
let {type, typeName, error} = featureError("topp:states", "ERROR");
expect(type).toBe(FEATURE_ERROR);
Expand All @@ -95,6 +126,13 @@ describe('wfsquery actions', () => {
expect(searchUrl).toBe("searchUrl");
expect(filterObj).toBe("filterObj");
});
it('createQuery with owner param', () => {
let {type, searchUrl, filterObj, owner} = createQuery("searchUrl", "filterObj", "owner");
expect(type).toBe(QUERY_CREATE);
expect(searchUrl).toBe("searchUrl");
expect(filterObj).toBe("filterObj");
expect(owner).toBe("owner");
});
it('query', () => {
let {type, searchUrl, filterObj} = query("searchUrl", "filterObj");
expect(type).toBe(QUERY);
Expand Down
15 changes: 9 additions & 6 deletions web/client/actions/wfsquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ export function initQueryPanel() {
type: INIT_QUERY_PANEL
};
}
export function featureTypeSelected(url, typeName, fields = []) {
export function featureTypeSelected(url, typeName, fields = [], owner) {
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
return {
type: FEATURE_TYPE_SELECTED,
url,
typeName,
fields
fields,
owner
};
}
export function featureTypeLoaded(typeName, featureType) {
export function featureTypeLoaded(typeName, featureType, owner) {
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
return {
type: FEATURE_TYPE_LOADED,
typeName,
featureType
featureType,
owner
};
}

Expand Down Expand Up @@ -142,11 +144,12 @@ export function loadFeature(baseUrl, typeName) {
});
};
}
export function createQuery(searchUrl, filterObj) {
export function createQuery(searchUrl, filterObj, owner) {
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
return {
type: QUERY_CREATE,
searchUrl,
filterObj
filterObj,
owner
};
}

Expand Down
148 changes: 148 additions & 0 deletions web/client/epics/__tests__/wfsquery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,152 @@ describe('wfsquery Epics', () => {
}, mockState);
});
});


describe('featureTypeSelectedEpic with owner', () => {
const expectedResult = require('../../test-resources/vector/feature-collection-vector.json');
const flatLayers = [{
id: 'layer1',
name: 'layer1 name',
title: 'layer1 title',
description: 'layer1 description',
type: 'vector',
features: expectedResult
}];
const wmsLayer = [{
id: 'layer2',
name: 'poi',
title: 'layer2 title',
description: 'layer2 description',
type: 'wms',
fields: [{
name: "NAME",
alias: "Name Alias",
type: "string"
}]
}];
it('vector layer', (done) => {
const mockState = {
query: {
data: {},
featureTypes: [],
typeName: 'layer1',
url: '/dummy'},
featuregrid: {
timeSync: true,
pagination: {
size: 10
},
open: true,
selectedLayer: "layer1",
changes: [],
mode: 'VIEW'
},
layers: {
flat: flatLayers,
layerMetadata: {
expanded: false,
maskLoading: false
},
settings: {
expanded: false,
node: null,
nodeType: null,
options: {}
}
}
};
mockAxios.onPost().reply(() => {return [200, expectedResult];});
testEpic(addTimeoutEpic(wfsQueryEpic, 500), 4, [
query("base/web/client/test-resources/vector/feature-collection-vector.json", {pagination: {} }),
featureTypeSelected('/dummy', 'layer1', [], "widgets")
], actions => {
expect(actions.length).toBe(4);
actions.map((action) => {
switch (action.type) {
case QUERY_RESULT:
expect(action.result.features).toEqual(expectedResult);
expect(action.result.totalFeatures).toEqual(expectedResult.length);
expect(action.result.numberMatched).toEqual(expectedResult.length);
expect(action.result.numberReturned).toEqual(expectedResult.length);
break;
case FEATURE_LOADING:
break;
case LAYER_LOAD:
break;
default:
expect(false).toBe(true);
}
});
done();
},
mockState
);
});

it('wms layer', (done) => {
const mockState = {
query: {
data: {},
featureTypes: [],
typeName: 'layer1',
url: '/dummy'},
featuregrid: {
timeSync: true,
pagination: {
size: 10
},
open: true,
selectedLayer: "layer1",
changes: [],
mode: 'VIEW'
},
layers: {
flat: wmsLayer,
layerMetadata: {
expanded: false,
maskLoading: false
},
settings: {
expanded: false,
node: null,
nodeType: null,
options: {}
}
}
};
const wfsResults = require('../../test-resources/wfs/describe-pois.json');
mockAxios.onGet().reply(() => [200, wfsResults]);
testEpic(featureTypeSelectedEpic, 2,
featureTypeSelected('/dummy', 'poi', wmsLayer[0].fields), ([changeSpatialAttribute, featureTypeLoaded]) => {
try {
expect(featureTypeLoaded.type).toBe(FEATURE_TYPE_LOADED);
expect(changeSpatialAttribute.type).toBe(CHANGE_SPATIAL_ATTRIBUTE);
expect(featureTypeLoaded.featureType.attributes).toEqual([{
label: "Name Alias",
attribute: "NAME",
type: "string",
valueId: "id",
valueLabel: "name",
values: []
},
{
label: "THUMBNAIL",
attribute: "THUMBNAIL",
type: "string",
valueId: "id",
valueLabel: "name",
values: []
},
{
label: "MAINPAGE", attribute: "MAINPAGE", type: "string", valueId: "id", valueLabel: "name", values: []
}]);

} catch (error) {
done(error);
}
done();
}, mockState);
});
});
});
9 changes: 5 additions & 4 deletions web/client/epics/__tests__/widgetsbuilder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ describe('widgetsbuilder epic', () => {
});
it('handleWidgetsFilterPanel', (done) => {
const startActions = [openFilterEditor()];
testEpic(handleWidgetsFilterPanel, 4, startActions, actions => {
expect(actions.length).toBe(4);
testEpic(handleWidgetsFilterPanel, 3, startActions, actions => {
expect(actions.length).toBe(3);
actions.map((action) => {
switch (action.type) {
case SET_CONTROL_PROPERTY:
Expand All @@ -236,6 +236,7 @@ describe('widgetsbuilder epic', () => {
type: "string",
alias: "X alias"
}]);
expect(action.owner).toEqual("widgets");
break;
case LOAD_FILTER:
break;
Expand Down Expand Up @@ -274,8 +275,8 @@ describe('widgetsbuilder epic', () => {
const startActions = [openFilterEditor(), search("TEST", {

})];
testEpic(handleWidgetsFilterPanel, 8, startActions, actions => {
expect(actions.length).toBe(8);
testEpic(handleWidgetsFilterPanel, 7, startActions, actions => {
expect(actions.length).toBe(7);
actions.map((action) => {
switch (action.type) {
case SET_CONTROL_PROPERTY:
Expand Down
8 changes: 4 additions & 4 deletions web/client/epics/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ const createLoadPageFlow = (store) => ({page, size, reason} = {}) => {

const createInitialQueryFlow = (action$, store, {url, name, id, fields} = {}) => {
const filterObj = get(store.getState(), `featuregrid.advancedFilters["${id}"]`);
const createInitialQuery = () => createQuery(url, filterObj || {
const createInitialQuery = (action) => createQuery(url, filterObj || {
featureTypeName: name,
filterType: 'OGC',
ogcVersion: '1.1.0'
});
}, action.owner);

return Rx.Observable.of(featureTypeSelected(url, name, fields)).merge(
action$.ofType(FEATURE_TYPE_LOADED).filter(({typeName} = {}) => typeName === name)
Expand Down Expand Up @@ -356,8 +356,8 @@ export const featureGridLayerSelectionInitialization = (action$) =>
*/
export const featureGridStartupQuery = (action$, store) =>
action$.ofType(QUERY_CREATE)
.switchMap(() => Rx.Observable.of(changePage(0))
.concat(modeSelector(store.getState()) === MODES.VIEW ? Rx.Observable.of(toggleViewMode()) : Rx.Observable.empty()));
.switchMap(({ owner }) => Rx.Observable.of(changePage(0))
.concat(modeSelector(store.getState()) === MODES.VIEW && owner !== "widgets" ? Rx.Observable.of(toggleViewMode()) : Rx.Observable.empty()));
/**
* Create sorted queries on sort action
* With virtualScroll active reset to page 0 but the grid will reload
Expand Down
2 changes: 1 addition & 1 deletion web/client/epics/wfsquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const featureTypeSelectedEpic = (action$, store) =>
const info = extractInfo(layerDescribeSelector(state, action.typeName), action.fields);
const geometry = info.geometry[0] && info.geometry[0].attribute ? info.geometry[0].attribute : 'the_geom';

return Rx.Observable.of(featureTypeLoaded(action.typeName, info), changeSpatialAttribute(geometry), Rx.Scheduler.async); // async scheduler is needed to allow invokers of `FEATURE_TYPE_SELECTED` to intercept `FEATURE_TYPE_LOADED` action as response.
return Rx.Observable.of(featureTypeLoaded(action.typeName, info, action.owner), changeSpatialAttribute(geometry), Rx.Scheduler.async); // async scheduler is needed to allow invokers of `FEATURE_TYPE_SELECTED` to intercept `FEATURE_TYPE_LOADED` action as response.
}

const selectedLayer = selectedLayerSelector(state);
Expand Down
2 changes: 1 addition & 1 deletion web/client/epics/widgetsbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const handleWidgetsFilterPanel = (action$, {getState = () => {}} = {}) =>
.switchMap(() =>
// open and setup query form
Rx.Observable.of(
featureTypeSelected(...getFTSelectedArgs(getState())),
featureTypeSelected(...getFTSelectedArgs(getState()).concat(["widgets"])),
loadFilter(getEditingWidgetFilter(getState())),
setControlProperty("widgetBuilder", "enabled", false),
setControlProperty('queryPanel', "enabled", true)
Expand Down
Loading