Skip to content

Commit cfb4fea

Browse files
Merge branch 'handle-non-existing-menu-section-removal-error_contribute-9.0'
2 parents 45b7427 + 2f05127 commit cfb4fea

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/app/shared/menu/menu.reducer.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,13 @@ describe('menusReducer', () => {
388388
expect(newState[menuID].sectionToSubsectionIndex[parentID]).not.toContain(childID);
389389
});
390390

391+
it('should not throw an error when trying to remove an already removed section using the REMOVE_SECTION action', () => {
392+
const state = dummyState;
393+
const action = new RemoveMenuSectionAction(menuID, 'non-existing-id');
394+
const newState = menusReducer(state, action);
395+
expect(newState).toEqual(dummyState);
396+
});
397+
391398
it('should set active to true for the correct menu section in response to the ACTIVATE_SECTION action', () => {
392399
dummyState[menuID].sections[topSectionID].active = false;
393400
const state = dummyState;

src/app/shared/menu/menu.reducer.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { hasValue } from '@dspace/shared/utils/empty.util';
1+
import {
2+
hasNoValue,
3+
hasValue,
4+
} from '@dspace/shared/utils/empty.util';
25

36
import { initialMenusState } from './initial-menus-state';
47
import {
@@ -149,11 +152,14 @@ function removeSection(state: MenusState, action: RemoveMenuSectionAction) {
149152
/**
150153
* Remove a section from the index of a certain menu
151154
* @param {MenusState} state The initial state
152-
* @param {MenuSection} action The MenuSection of which the ID should be removed from the index
153-
* @param {MenuID} action The Menu ID to which the section belonged
155+
* @param {MenuSection} section The MenuSection of which the ID should be removed from the index
156+
* @param {MenuID} menuID The Menu ID to which the section belonged
154157
* @returns {MenusState} The new reduced state
155158
*/
156159
function removeFromIndex(state: MenusState, section: MenuSection, menuID: MenuID) {
160+
if (hasNoValue(section)) {
161+
return state;
162+
}
157163
const sectionID = section.id;
158164
const parentID = section.parentID;
159165
if (hasValue(parentID)) {

0 commit comments

Comments
 (0)