Skip to content

Commit

Permalink
fix: filter event to call api if mapSync is on and viewport is null
Browse files Browse the repository at this point in the history
  • Loading branch information
rowheat02 committed Nov 26, 2024
1 parent e5ea162 commit 1b98005
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ describe('wpsChart enhancer', () => {
options: {
aggregateFunction: "Count",
aggregationAttribute: "test"
},
dependencies: { viewport: true}
}
};
ReactDOM.render(<Sink {...props} />, document.getElementById("container"));
});
Expand All @@ -61,8 +60,7 @@ describe('wpsChart enhancer', () => {
options: {
aggregateFunction: "Count",
aggregationAttribute: "test"
},
dependencies: { viewport: true}
}
};
ReactDOM.render(<Sink {...props} />, document.getElementById("container"));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) && */
Expand Down
10 changes: 9 additions & 1 deletion web/client/components/widgets/enhancers/wpsCounter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1b98005

Please sign in to comment.