Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport c027-2024-10-24] - #10622: Not possible to remove widget from Map - JavaScript error (#10623) #10630

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading