Skip to content

Commit

Permalink
fix: check mapSync dependencyMap for standard map also
Browse files Browse the repository at this point in the history
  • Loading branch information
rowheat02 committed Dec 4, 2024
1 parent f15603b commit 26525e1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,31 @@ describe('wpsChart enhancer', () => {
};
ReactDOM.render(<Sink {...props} />, document.getElementById("container"));
});
it('wpsCounter with mapSync standard Map', (done) => {
const Sink = wpsCounter(createSink( ({data, loading} = {}) => {
if (!loading) {
expect(data).toExist();
done();
}
}));
const props = {
mapSync: true,
dependencies: {
viewport: "..."
},
dependenciesMap: {
mapSync: 'map.mapSync'
},
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(<Sink {...props} />, document.getElementById("container"));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,33 @@ describe('triggerFetch stream', () => {
}
);
});
it('triggerFetch with mapSync with Standard Map and dependencies.viewport', (done) => {
const base = {
layer: { name: "TEST" },
mapSync: true,
widgets: [
],
dependenciesMap: {
mapSync: 'map.mapSync'
}
};
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();
}
);
});

});
5 changes: 4 additions & 1 deletion web/client/utils/WidgetsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ export const canTableWidgetBeDependency = (widget, dependencyTableWidget) => {
};

function findWidgetById(widgets, widgetId) {
return widgets.find(widget => widget.id === widgetId);
return widgets?.find(widget => widget.id === widgetId);
}

/**
Expand All @@ -1014,6 +1014,9 @@ export function checkMapSyncWithWidgetOfMapType(widgets, dependenciesMap) {
if (!mapSyncDependencies) {
return false;
}
if (mapSyncDependencies.includes("map.mapSync")) {
return true;
}
// Extract widget ID
const widgetId = mapSyncDependencies.match?.(/\[([^\]]+)\]/)?.[1];
if (!widgetId) {
Expand Down

0 comments on commit 26525e1

Please sign in to comment.