Skip to content

Commit

Permalink
keep existing filters without viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetanbrl committed Aug 21, 2024
1 parent 7882325 commit 1cfb2b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion web/client/epics/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ const updateFilterFunc = (store) => ({update = {}, append} = {}) => {
// If an advanced filter is present it's filterFields should be composed with the action'
const {id} = selectedLayerSelector(store.getState());
const filterObj = {...get(store.getState(), `featuregrid.advancedFilters["${id}"]`)};
if (filterObj) {
if (filterObj && !isEmpty(filterObj)) {
// TODO: make append with advanced filters work
const attributesFilter = getAttributeFilters(store.getState()) || {};
const columnsFilters = reduce(attributesFilter, (cFilters, value, attribute) => {
Expand Down
25 changes: 20 additions & 5 deletions web/client/selectors/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,27 +214,31 @@ export const isViewportFilterActive = state => get(state, 'featuregrid.viewportF

export const isFilterByViewportSupported = state => mapTypeSelector(state) !== MapLibraries.CESIUM;

export const spatialFieldFilters = state => get(state, 'query.filterObj.spatialField');

export const viewportFilter = createShallowSelectorCreator(isEqual)(
isViewportFilterActive,
mapBboxSelector,
projectionSelector,
state => get(state, 'query.filterObj.spatialField'),
spatialFieldFilters,
describeSelector,
isFilterByViewportSupported,
(viewportFilterIsActive, box, projection, spatialField = [], describeLayer, viewportFilterIsSupported) => {
const attribute = findGeometryProperty(describeLayer)?.name;
const existingFilter = spatialField?.operation ? [spatialField] : spatialField;
return viewportFilterIsActive && viewportFilterIsSupported ? {
spatialField: [
...existingFilter,
// avoid restricted area filter dupplication
...existingFilter.filter(f => !f.viewport && !f.restrictedArea),
{
geometry: {
...bboxToFeatureGeometry(box.bounds),
projection
},
attribute: attribute,
method: "Rectangle",
operation: "INTERSECTS"
operation: "INTERSECTS",
viewport: true
}
]
} : {};
Expand All @@ -243,14 +247,21 @@ export const viewportFilter = createShallowSelectorCreator(isEqual)(

export const restrictedAreaFilter = createShallowSelectorCreator(isEqual)(
restrictedAreaSelector,
spatialFieldFilters,
viewportFilter,
projectionSelector,
describeSelector,
state => restrictedAreaOperatorSelector(state),
(restrictedArea, projection, describeLayer, operator) => {
(restrictedArea, spatialField = [], viewportFilter, projection, describeLayer, operator) => {
const attribute = findGeometryProperty(describeLayer)?.name;
console.log(restrictedArea);
let existingFilter = [];
// if activate, viewportFilter already get existing filter
if(isEmpty(viewportFilter) && !isEmpty(spatialField)) {
existingFilter = spatialField?.operation ? [spatialField] : spatialField
}
return !isEmpty(restrictedArea) ? {
spatialField: [
...existingFilter,
{
geometry: {
...restrictedArea,
Expand All @@ -266,6 +277,10 @@ export const restrictedAreaFilter = createShallowSelectorCreator(isEqual)(
}
)

/**
* Create spatialField filters array.
* Contains filters from viewportFilter, restrictedArea, exsting WFS filter
*/
export const additionnalGridFilters = (state) => {
const restrictedArea = restrictedAreaFilter(state)?.spatialField || [];
const viewport = viewportFilter(state)?.spatialField || [];
Expand Down

0 comments on commit 1cfb2b1

Please sign in to comment.