From 230be872949d55d716fc679d728fc8df77fa2408 Mon Sep 17 00:00:00 2001 From: Rohit Gautam Date: Mon, 18 Nov 2024 14:03:07 +0545 Subject: [PATCH 1/9] fix: disable counter api to call when filter is invalid --- .../widgets/enhancers/wpsCounter.js | 3 +- web/client/utils/XMLUtils.js | 30 +++++++++++++++++++ web/client/utils/__tests__/XMLUtils-test.js | 10 ++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/web/client/components/widgets/enhancers/wpsCounter.js b/web/client/components/widgets/enhancers/wpsCounter.js index b239bf2f87..cde2a6f371 100644 --- a/web/client/components/widgets/enhancers/wpsCounter.js +++ b/web/client/components/widgets/enhancers/wpsCounter.js @@ -21,6 +21,7 @@ const sameOptions = (o1 = {}, o2 = {}) => && o1.aggregationAttribute === o2.aggregationAttribute && o1.viewParams === o2.viewParams; import { getWpsUrl } from '../../../utils/LayersUtils'; +import { validXMLFilter } from '../../../utils/XMLUtils'; /** * Stream of props -> props to retrieve data from WPS aggregate process on params changes. @@ -30,7 +31,7 @@ import { getWpsUrl } from '../../../utils/LayersUtils'; */ const dataStreamFactory = ($props) => $props - .filter(({layer = {}, options}) => layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute) + .filter(({layer = {}, options, filter}) => layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute && validXMLFilter(filter)) .distinctUntilChanged( ({layer = {}, options = {}, filter}, newProps) => (newProps.layer && layer.name === newProps.layer.name && layer.loadingError === newProps.layer.loadingError) diff --git a/web/client/utils/XMLUtils.js b/web/client/utils/XMLUtils.js index 564b43d18c..3bf29ab19a 100644 --- a/web/client/utils/XMLUtils.js +++ b/web/client/utils/XMLUtils.js @@ -166,3 +166,33 @@ export const objectToAttributes = (obj = {}, xmlns) => keys(obj).filter(key => o })); export const assignNamespace = (nodes, xmlns) => nodes.filter(node => !!node).map(node => ({...node, xmlns})); + + +/** + * Checks if any element in the XML string contains the text "undefined". + * + * @param {string} xmlString - The XML string to check. + * @returns {boolean} - Returns `false` if any contains "undefined", otherwise `true`. + * + * @example + * validFilter('undefined'); // false + * validFilter('valid'); // true + */ +export function validXMLFilter(xmlString) { + const parser = new DOMParser(); + const xmlDoc = parser.parseFromString(xmlString, "application/xml"); + + // Find all elements (you can have multiple elements) + const andElements = xmlDoc.getElementsByTagName("ogc:And"); + + // Iterate through the elements and check for "undefined" + for (let i = 0; i < andElements.length; i++) { + const andElement = andElements[i]; + + // If we find an element with text "undefined", return false + if (andElement.textContent === "undefined") { + return false; + } + } + return true; +} diff --git a/web/client/utils/__tests__/XMLUtils-test.js b/web/client/utils/__tests__/XMLUtils-test.js index f867057cdd..be34455944 100644 --- a/web/client/utils/__tests__/XMLUtils-test.js +++ b/web/client/utils/__tests__/XMLUtils-test.js @@ -14,7 +14,8 @@ import { escapeText, escapeAttributeValue, removeEmptyNodes, - writeXML + writeXML, + validXMLFilter } from '../XMLUtils'; const namespaces = { @@ -155,4 +156,11 @@ describe('XMLUtils tests', () => { `; expect(writeXML(removeEmptyNodes(tree), values(namespaces))).toBe(xml); }); + + it.only('Check valid XML filter', () => { + const xmlFilter = 'filters>'; + expect(validXMLFilter(xmlFilter)).toBe(true); + const invalidXMLFilter = 'undefined'; + expect(validXMLFilter(invalidXMLFilter)).toBe(false); + }); }); From b9c24f163eaf293e81316ac3f27f87dc5291ee90 Mon Sep 17 00:00:00 2001 From: Rohit Gautam Date: Mon, 18 Nov 2024 14:03:07 +0545 Subject: [PATCH 2/9] fix: disable counter api to call when filter is invalid --- .../widgets/enhancers/wpsCounter.js | 3 +- web/client/utils/XMLUtils.js | 30 +++++++++++++++++++ web/client/utils/__tests__/XMLUtils-test.js | 10 ++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/web/client/components/widgets/enhancers/wpsCounter.js b/web/client/components/widgets/enhancers/wpsCounter.js index b239bf2f87..cde2a6f371 100644 --- a/web/client/components/widgets/enhancers/wpsCounter.js +++ b/web/client/components/widgets/enhancers/wpsCounter.js @@ -21,6 +21,7 @@ const sameOptions = (o1 = {}, o2 = {}) => && o1.aggregationAttribute === o2.aggregationAttribute && o1.viewParams === o2.viewParams; import { getWpsUrl } from '../../../utils/LayersUtils'; +import { validXMLFilter } from '../../../utils/XMLUtils'; /** * Stream of props -> props to retrieve data from WPS aggregate process on params changes. @@ -30,7 +31,7 @@ import { getWpsUrl } from '../../../utils/LayersUtils'; */ const dataStreamFactory = ($props) => $props - .filter(({layer = {}, options}) => layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute) + .filter(({layer = {}, options, filter}) => layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute && validXMLFilter(filter)) .distinctUntilChanged( ({layer = {}, options = {}, filter}, newProps) => (newProps.layer && layer.name === newProps.layer.name && layer.loadingError === newProps.layer.loadingError) diff --git a/web/client/utils/XMLUtils.js b/web/client/utils/XMLUtils.js index 564b43d18c..3bf29ab19a 100644 --- a/web/client/utils/XMLUtils.js +++ b/web/client/utils/XMLUtils.js @@ -166,3 +166,33 @@ export const objectToAttributes = (obj = {}, xmlns) => keys(obj).filter(key => o })); export const assignNamespace = (nodes, xmlns) => nodes.filter(node => !!node).map(node => ({...node, xmlns})); + + +/** + * Checks if any element in the XML string contains the text "undefined". + * + * @param {string} xmlString - The XML string to check. + * @returns {boolean} - Returns `false` if any contains "undefined", otherwise `true`. + * + * @example + * validFilter('undefined'); // false + * validFilter('valid'); // true + */ +export function validXMLFilter(xmlString) { + const parser = new DOMParser(); + const xmlDoc = parser.parseFromString(xmlString, "application/xml"); + + // Find all elements (you can have multiple elements) + const andElements = xmlDoc.getElementsByTagName("ogc:And"); + + // Iterate through the elements and check for "undefined" + for (let i = 0; i < andElements.length; i++) { + const andElement = andElements[i]; + + // If we find an element with text "undefined", return false + if (andElement.textContent === "undefined") { + return false; + } + } + return true; +} diff --git a/web/client/utils/__tests__/XMLUtils-test.js b/web/client/utils/__tests__/XMLUtils-test.js index f867057cdd..4eb12095ca 100644 --- a/web/client/utils/__tests__/XMLUtils-test.js +++ b/web/client/utils/__tests__/XMLUtils-test.js @@ -14,7 +14,8 @@ import { escapeText, escapeAttributeValue, removeEmptyNodes, - writeXML + writeXML, + validXMLFilter } from '../XMLUtils'; const namespaces = { @@ -155,4 +156,11 @@ describe('XMLUtils tests', () => { `; expect(writeXML(removeEmptyNodes(tree), values(namespaces))).toBe(xml); }); + + it('Check valid XML filter', () => { + const xmlFilter = 'filters>'; + expect(validXMLFilter(xmlFilter)).toBe(true); + const invalidXMLFilter = 'undefined'; + expect(validXMLFilter(invalidXMLFilter)).toBe(false); + }); }); From e3877bf12bab3462da8818813051769dc7c84d89 Mon Sep 17 00:00:00 2001 From: Rohit Gautam Date: Thu, 21 Nov 2024 12:52:47 +0545 Subject: [PATCH 3/9] fix: filter undefined on viewpoint undefined --- .../widgets/enhancers/dependenciesToFilter.js | 7 ++--- .../widgets/enhancers/wpsCounter.js | 2 +- web/client/utils/XMLUtils.js | 28 ------------------- web/client/utils/__tests__/XMLUtils-test.js | 6 ---- 4 files changed, 4 insertions(+), 39 deletions(-) diff --git a/web/client/components/widgets/enhancers/dependenciesToFilter.js b/web/client/components/widgets/enhancers/dependenciesToFilter.js index f3b72528c2..33549676ff 100644 --- a/web/client/components/widgets/enhancers/dependenciesToFilter.js +++ b/web/client/components/widgets/enhancers/dependenciesToFilter.js @@ -83,11 +83,10 @@ const createFilterProps = ({ mapSync, geomProp = "the_geom", dependencies = {}, property(geomProp).intersects(geom))) }; } - // this will contain only an ogc filter based on current and other filters (cql excluded) + + // this is the point viewport undefined, so to avoid api call, filter is undefined return { - filter: filter(and( - ...(layerFilter ? toOGCFilterParts(layerFilter, "1.1.0", "ogc") : []), - ...(newFilterObj ? toOGCFilterParts(newFilterObj, "1.1.0", "ogc") : []))) + filter: undefined }; }; diff --git a/web/client/components/widgets/enhancers/wpsCounter.js b/web/client/components/widgets/enhancers/wpsCounter.js index cde2a6f371..26e49b5fdc 100644 --- a/web/client/components/widgets/enhancers/wpsCounter.js +++ b/web/client/components/widgets/enhancers/wpsCounter.js @@ -31,7 +31,7 @@ import { validXMLFilter } from '../../../utils/XMLUtils'; */ const dataStreamFactory = ($props) => $props - .filter(({layer = {}, options, filter}) => layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute && validXMLFilter(filter)) + .filter(({layer = {}, options, filter}) => layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute && filter) .distinctUntilChanged( ({layer = {}, options = {}, filter}, newProps) => (newProps.layer && layer.name === newProps.layer.name && layer.loadingError === newProps.layer.loadingError) diff --git a/web/client/utils/XMLUtils.js b/web/client/utils/XMLUtils.js index 3bf29ab19a..2b15c377c6 100644 --- a/web/client/utils/XMLUtils.js +++ b/web/client/utils/XMLUtils.js @@ -168,31 +168,3 @@ export const objectToAttributes = (obj = {}, xmlns) => keys(obj).filter(key => o export const assignNamespace = (nodes, xmlns) => nodes.filter(node => !!node).map(node => ({...node, xmlns})); -/** - * Checks if any element in the XML string contains the text "undefined". - * - * @param {string} xmlString - The XML string to check. - * @returns {boolean} - Returns `false` if any contains "undefined", otherwise `true`. - * - * @example - * validFilter('undefined'); // false - * validFilter('valid'); // true - */ -export function validXMLFilter(xmlString) { - const parser = new DOMParser(); - const xmlDoc = parser.parseFromString(xmlString, "application/xml"); - - // Find all elements (you can have multiple elements) - const andElements = xmlDoc.getElementsByTagName("ogc:And"); - - // Iterate through the elements and check for "undefined" - for (let i = 0; i < andElements.length; i++) { - const andElement = andElements[i]; - - // If we find an element with text "undefined", return false - if (andElement.textContent === "undefined") { - return false; - } - } - return true; -} diff --git a/web/client/utils/__tests__/XMLUtils-test.js b/web/client/utils/__tests__/XMLUtils-test.js index ac6fdc8d4b..2fefc092d1 100644 --- a/web/client/utils/__tests__/XMLUtils-test.js +++ b/web/client/utils/__tests__/XMLUtils-test.js @@ -157,10 +157,4 @@ describe('XMLUtils tests', () => { expect(writeXML(removeEmptyNodes(tree), values(namespaces))).toBe(xml); }); - it('Check valid XML filter', () => { - const xmlFilter = 'filters'; - expect(validXMLFilter(xmlFilter)).toBe(true); - const invalidXMLFilter = 'undefined'; - expect(validXMLFilter(invalidXMLFilter)).toBe(false); - }); }); From 061daaa0d7190d5335e9ce6b2c14f5a79e37988d Mon Sep 17 00:00:00 2001 From: Rohit Gautam Date: Thu, 21 Nov 2024 13:00:52 +0545 Subject: [PATCH 4/9] fix: lint fix --- web/client/components/widgets/enhancers/wpsCounter.js | 1 - web/client/utils/__tests__/XMLUtils-test.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/web/client/components/widgets/enhancers/wpsCounter.js b/web/client/components/widgets/enhancers/wpsCounter.js index 26e49b5fdc..6aa278a6cf 100644 --- a/web/client/components/widgets/enhancers/wpsCounter.js +++ b/web/client/components/widgets/enhancers/wpsCounter.js @@ -21,7 +21,6 @@ const sameOptions = (o1 = {}, o2 = {}) => && o1.aggregationAttribute === o2.aggregationAttribute && o1.viewParams === o2.viewParams; import { getWpsUrl } from '../../../utils/LayersUtils'; -import { validXMLFilter } from '../../../utils/XMLUtils'; /** * Stream of props -> props to retrieve data from WPS aggregate process on params changes. diff --git a/web/client/utils/__tests__/XMLUtils-test.js b/web/client/utils/__tests__/XMLUtils-test.js index 2fefc092d1..1d1bff85a5 100644 --- a/web/client/utils/__tests__/XMLUtils-test.js +++ b/web/client/utils/__tests__/XMLUtils-test.js @@ -14,8 +14,7 @@ import { escapeText, escapeAttributeValue, removeEmptyNodes, - writeXML, - validXMLFilter + writeXML } from '../XMLUtils'; const namespaces = { From 7581bec1c9485aaa1fd90756fe1430fd8514a644 Mon Sep 17 00:00:00 2001 From: Rohit Gautam Date: Thu, 21 Nov 2024 13:36:49 +0545 Subject: [PATCH 5/9] fix: check viewport instead of filter --- .../components/widgets/enhancers/dependenciesToFilter.js | 7 ++++--- web/client/components/widgets/enhancers/wpsCounter.js | 4 +++- web/client/utils/XMLUtils.js | 2 -- web/client/utils/__tests__/XMLUtils-test.js | 1 - 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/web/client/components/widgets/enhancers/dependenciesToFilter.js b/web/client/components/widgets/enhancers/dependenciesToFilter.js index 33549676ff..f3b72528c2 100644 --- a/web/client/components/widgets/enhancers/dependenciesToFilter.js +++ b/web/client/components/widgets/enhancers/dependenciesToFilter.js @@ -83,10 +83,11 @@ const createFilterProps = ({ mapSync, geomProp = "the_geom", dependencies = {}, property(geomProp).intersects(geom))) }; } - - // this is the point viewport undefined, so to avoid api call, filter is undefined + // this will contain only an ogc filter based on current and other filters (cql excluded) return { - filter: undefined + filter: filter(and( + ...(layerFilter ? toOGCFilterParts(layerFilter, "1.1.0", "ogc") : []), + ...(newFilterObj ? toOGCFilterParts(newFilterObj, "1.1.0", "ogc") : []))) }; }; diff --git a/web/client/components/widgets/enhancers/wpsCounter.js b/web/client/components/widgets/enhancers/wpsCounter.js index 6aa278a6cf..d8c68d9ddd 100644 --- a/web/client/components/widgets/enhancers/wpsCounter.js +++ b/web/client/components/widgets/enhancers/wpsCounter.js @@ -30,7 +30,9 @@ import { getWpsUrl } from '../../../utils/LayersUtils'; */ const dataStreamFactory = ($props) => $props - .filter(({layer = {}, options, filter}) => layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute && filter) + .filter(({layer = {}, options, dependencies}) => { + return layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute && dependencies.viewport; + }) .distinctUntilChanged( ({layer = {}, options = {}, filter}, newProps) => (newProps.layer && layer.name === newProps.layer.name && layer.loadingError === newProps.layer.loadingError) diff --git a/web/client/utils/XMLUtils.js b/web/client/utils/XMLUtils.js index 2b15c377c6..564b43d18c 100644 --- a/web/client/utils/XMLUtils.js +++ b/web/client/utils/XMLUtils.js @@ -166,5 +166,3 @@ export const objectToAttributes = (obj = {}, xmlns) => keys(obj).filter(key => o })); export const assignNamespace = (nodes, xmlns) => nodes.filter(node => !!node).map(node => ({...node, xmlns})); - - diff --git a/web/client/utils/__tests__/XMLUtils-test.js b/web/client/utils/__tests__/XMLUtils-test.js index 1d1bff85a5..f867057cdd 100644 --- a/web/client/utils/__tests__/XMLUtils-test.js +++ b/web/client/utils/__tests__/XMLUtils-test.js @@ -155,5 +155,4 @@ describe('XMLUtils tests', () => { `; expect(writeXML(removeEmptyNodes(tree), values(namespaces))).toBe(xml); }); - }); From 9856394e3fb834b06da1f299ffca42b58134ee76 Mon Sep 17 00:00:00 2001 From: Rohit Gautam Date: Thu, 21 Nov 2024 13:39:46 +0545 Subject: [PATCH 6/9] fix: syntax fix --- web/client/components/widgets/enhancers/wpsCounter.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web/client/components/widgets/enhancers/wpsCounter.js b/web/client/components/widgets/enhancers/wpsCounter.js index d8c68d9ddd..5b3727b85b 100644 --- a/web/client/components/widgets/enhancers/wpsCounter.js +++ b/web/client/components/widgets/enhancers/wpsCounter.js @@ -30,9 +30,7 @@ import { getWpsUrl } from '../../../utils/LayersUtils'; */ const dataStreamFactory = ($props) => $props - .filter(({layer = {}, options, dependencies}) => { - return layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute && dependencies.viewport; - }) + .filter(({layer = {}, options, dependencies}) => layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute && dependencies.viewport) .distinctUntilChanged( ({layer = {}, options = {}, filter}, newProps) => (newProps.layer && layer.name === newProps.layer.name && layer.loadingError === newProps.layer.loadingError) From e5ea162bf735a94657f4c921d90b17099f43be33 Mon Sep 17 00:00:00 2001 From: Rohit Gautam Date: Thu, 21 Nov 2024 14:00:26 +0545 Subject: [PATCH 7/9] fix: old tests --- .../widgets/enhancers/__tests__/wpsCounter-test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js b/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js index bea5aa0103..b0ae0e70d7 100644 --- a/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js +++ b/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js @@ -40,7 +40,8 @@ describe('wpsChart enhancer', () => { options: { aggregateFunction: "Count", aggregationAttribute: "test" - } + }, + dependencies: { viewport: true} }; ReactDOM.render(, document.getElementById("container")); }); @@ -60,7 +61,8 @@ describe('wpsChart enhancer', () => { options: { aggregateFunction: "Count", aggregationAttribute: "test" - } + }, + dependencies: { viewport: true} }; ReactDOM.render(, document.getElementById("container")); }); From 1b980052819a86d7b5c6998efc6e939f19d15572 Mon Sep 17 00:00:00 2001 From: Rohit Gautam Date: Tue, 26 Nov 2024 18:54:49 +0545 Subject: [PATCH 8/9] fix: filter event to call api if mapSync is on and viewport is null --- .../widgets/enhancers/__tests__/wpsCounter-test.js | 6 ++---- .../widgets/enhancers/wfsTable/triggerFetch.js | 10 +++++++++- web/client/components/widgets/enhancers/wpsCounter.js | 10 +++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js b/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js index b0ae0e70d7..bea5aa0103 100644 --- a/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js +++ b/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js @@ -40,8 +40,7 @@ describe('wpsChart enhancer', () => { options: { aggregateFunction: "Count", aggregationAttribute: "test" - }, - dependencies: { viewport: true} + } }; ReactDOM.render(, document.getElementById("container")); }); @@ -61,8 +60,7 @@ describe('wpsChart enhancer', () => { options: { aggregateFunction: "Count", aggregationAttribute: "test" - }, - dependencies: { viewport: true} + } }; ReactDOM.render(, document.getElementById("container")); }); diff --git a/web/client/components/widgets/enhancers/wfsTable/triggerFetch.js b/web/client/components/widgets/enhancers/wfsTable/triggerFetch.js index 8ef8aa1c96..50f73c232d 100644 --- a/web/client/components/widgets/enhancers/wfsTable/triggerFetch.js +++ b/web/client/components/widgets/enhancers/wfsTable/triggerFetch.js @@ -22,7 +22,15 @@ const sameSortOptions = (o1 = {}, o2 = {}) => * @return {Observable} Stream of props to trigger the data fetch */ export default ($props) => - $props.filter(({ layer = {} }) => layer.name ) + $props.filter(({ layer = {}, mapSync, dependencies }) => { + // Check if mapSync is enabled (true) and dependencies.viewport is null or falsy + // If this condition is true, return false to filter out the event. + // This prevents an extra API call from being triggered when the viewport is not available. + if (mapSync && !dependencies.viewport) { + return false; + } + return layer.name; + } ) .distinctUntilChanged( ({ layer = {}, options = {}, filter, sortOptions }, newProps) => /* getSearchUrl(layer) === getSearchUrl(layer) && */ diff --git a/web/client/components/widgets/enhancers/wpsCounter.js b/web/client/components/widgets/enhancers/wpsCounter.js index 5b3727b85b..e122d49d3b 100644 --- a/web/client/components/widgets/enhancers/wpsCounter.js +++ b/web/client/components/widgets/enhancers/wpsCounter.js @@ -30,7 +30,15 @@ import { getWpsUrl } from '../../../utils/LayersUtils'; */ const dataStreamFactory = ($props) => $props - .filter(({layer = {}, options, dependencies}) => layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute && dependencies.viewport) + .filter(({layer = {}, options, dependencies, mapSync}) => { + // Check if mapSync is enabled (true) and dependencies.viewport is null or falsy + // If this condition is true, return false to filter out the event. + // This prevents an extra API call from being triggered when the viewport is not available. + if (mapSync && !dependencies.viewport) { + return false; + } + return layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute; + }) .distinctUntilChanged( ({layer = {}, options = {}, filter}, newProps) => (newProps.layer && layer.name === newProps.layer.name && layer.loadingError === newProps.layer.loadingError) From 6fe416f3c115abb06a967f879ee87ea22c9d3dce Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Wed, 27 Nov 2024 10:26:02 +0100 Subject: [PATCH 9/9] Add unit tests and reduced error cases --- .../enhancers/__tests__/wpsCounter-test.js | 28 +++++++++++++++++-- .../wfsTable/__tests__/triggerFetch-test.js | 23 +++++++++++++++ .../enhancers/wfsTable/triggerFetch.js | 2 +- .../widgets/enhancers/wpsCounter.js | 2 +- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js b/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js index bea5aa0103..bfee98fe2d 100644 --- a/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js +++ b/web/client/components/widgets/enhancers/__tests__/wpsCounter-test.js @@ -23,7 +23,7 @@ describe('wpsChart enhancer', () => { document.body.innerHTML = ''; setTimeout(done); }); - it('wpsChart data retrival', (done) => { + it('wpsCounter data retrieval', (done) => { const Sink = wpsCounter(createSink( ({data, loading} = {}) => { if (!loading) { expect(data).toExist(); @@ -44,7 +44,7 @@ describe('wpsChart enhancer', () => { }; ReactDOM.render(, document.getElementById("container")); }); - it('wpsChart error management', (done) => { + it('wpsCounter error management', (done) => { const Sink = wpsCounter(createSink( ({error, loading} = {}) => { if (!loading && error) { expect(error).toExist(); @@ -64,4 +64,28 @@ describe('wpsChart enhancer', () => { }; ReactDOM.render(, document.getElementById("container")); }); + it('wpsCounter with mapSync and dependencies', (done) => { + const Sink = wpsCounter(createSink( ({data, loading} = {}) => { + if (!loading) { + expect(data).toExist(); + done(); + } + })); + const props = { + mapSync: true, + dependencies: { + viewport: "..." + }, + layer: { + name: "test", + url: 'base/web/client/test-resources/widgetbuilder/aggregate', + wpsUrl: 'base/web/client/test-resources/widgetbuilder/aggregate', + search: {url: 'base/web/client/test-resources/widgetbuilder/aggregate'}}, + options: { + aggregateFunction: "Count", + aggregationAttribute: "test" + } + }; + ReactDOM.render(, document.getElementById("container")); + }); }); diff --git a/web/client/components/widgets/enhancers/wfsTable/__tests__/triggerFetch-test.js b/web/client/components/widgets/enhancers/wfsTable/__tests__/triggerFetch-test.js index e695294210..44a125b3c7 100644 --- a/web/client/components/widgets/enhancers/wfsTable/__tests__/triggerFetch-test.js +++ b/web/client/components/widgets/enhancers/wfsTable/__tests__/triggerFetch-test.js @@ -55,5 +55,28 @@ describe('triggerFetch stream', () => { } ); }); + it('triggerFetch with mapSync and dependencies.viewport', (done) => { + const base = { + layer: { name: "TEST" }, + mapSync: true + }; + const propsChanges = [ + base, // does not trigger fetch + {...base, dependencies: { viewport: true }}, // triggers fetch (p1) + {...base, dependencies: { viewport: false }}, // does not trigger fetch + {...base, mapSync: false, filter: "changed"} // triggers fetch (p2) (the filter changes due to the viewport) + ]; + triggerFetch(Rx.Observable.from(propsChanges)) + .bufferCount(4) + .subscribe( + ([p1, p2, p3, p4]) => { + expect(p1?.dependencies?.viewport).toBe(true); + expect(p2).toExist(); + expect(p3).toNotExist(); + expect(p4).toNotExist(); + done(); + } + ); + }); }); diff --git a/web/client/components/widgets/enhancers/wfsTable/triggerFetch.js b/web/client/components/widgets/enhancers/wfsTable/triggerFetch.js index 50f73c232d..9eb7660a25 100644 --- a/web/client/components/widgets/enhancers/wfsTable/triggerFetch.js +++ b/web/client/components/widgets/enhancers/wfsTable/triggerFetch.js @@ -26,7 +26,7 @@ export default ($props) => // Check if mapSync is enabled (true) and dependencies.viewport is null or falsy // If this condition is true, return false to filter out the event. // This prevents an extra API call from being triggered when the viewport is not available. - if (mapSync && !dependencies.viewport) { + if (mapSync && !dependencies?.viewport) { return false; } return layer.name; diff --git a/web/client/components/widgets/enhancers/wpsCounter.js b/web/client/components/widgets/enhancers/wpsCounter.js index e122d49d3b..91ac32c6ee 100644 --- a/web/client/components/widgets/enhancers/wpsCounter.js +++ b/web/client/components/widgets/enhancers/wpsCounter.js @@ -34,7 +34,7 @@ const dataStreamFactory = ($props) => // Check if mapSync is enabled (true) and dependencies.viewport is null or falsy // If this condition is true, return false to filter out the event. // This prevents an extra API call from being triggered when the viewport is not available. - if (mapSync && !dependencies.viewport) { + if (mapSync && !dependencies?.viewport) { return false; } return layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute;