Skip to content

Commit

Permalink
geosolutions-it#10622: Not possible to remove widget from Map - JavaS…
Browse files Browse the repository at this point in the history
…cript error (geosolutions-it#10623)

Description:
- fix the issue of not remove widget from map in case of existing other widgets has dependenciesMap prop = empty object
- add unit test
  • Loading branch information
mahmoudadel54 authored Oct 24, 2024
1 parent 08772cd commit 3794608
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions web/client/reducers/__tests__/widgets-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,34 @@ describe('Test the widgets reducer', () => {
expect(uWidgets[0].dependenciesMap).toBeFalsy();
expect(uWidgets[0].id).toBe("2");
});
it('test deleteWidget if the some other widgets [not deleted] has dependenciesMap = {}', () => {
const state = {
containers: {
[DEFAULT_TARGET]: {
widgets: [{
id: "1",
maps: [{mapId: 1, layers: [1, 2]}]
}, {
id: "2",
mapSync: true,
dependenciesMap: {
layers: "widgets[1].maps[1].layers"
}
}, {
id: "3",
mapSync: true,
dependenciesMap: {}
}]
}
}
};
const newState = widgets(state, deleteWidget({id: "1"}));
const uWidgets = newState.containers[DEFAULT_TARGET].widgets;
expect(uWidgets.length).toBe(2);
expect(uWidgets[0].mapSync).toBeFalsy();
expect(uWidgets[0].dependenciesMap).toBeFalsy();
expect(uWidgets[0].id).toBe("2");
});
it('init', () => {
const defaults = {initialSize: {
w: 4,
Expand Down
2 changes: 1 addition & 1 deletion web/client/reducers/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function widgetsReducer(state = emptyState, action) {
const allWidgets = get(updatedState, path, []);
return set(path, allWidgets.map(m => {
if (m.dependenciesMap) {
const [, dependentWidgetId] = WIDGETS_REGEX.exec((Object.values(m.dependenciesMap) || [])[0]);
const [, dependentWidgetId] = WIDGETS_REGEX.exec((Object.values(m.dependenciesMap) || [])[0]) || [];
if (dependentWidgetId) {
if (action.widget.id === dependentWidgetId) {
return {...omit(m, "dependenciesMap"), mapSync: false};
Expand Down

0 comments on commit 3794608

Please sign in to comment.