Skip to content

Commit 2f05127

Browse files
132007: Prevent error from being thrown when you try to remove an already removed filter
1 parent bcc437d commit 2f05127

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 '../empty.util';
1+
import {
2+
hasNoValue,
3+
hasValue,
4+
} from '../empty.util';
25
import { initialMenusState } from './initial-menus-state';
36
import {
47
ActivateMenuSectionAction,
@@ -148,11 +151,14 @@ function removeSection(state: MenusState, action: RemoveMenuSectionAction) {
148151
/**
149152
* Remove a section from the index of a certain menu
150153
* @param {MenusState} state The initial state
151-
* @param {MenuSection} action The MenuSection of which the ID should be removed from the index
152-
* @param {MenuID} action The Menu ID to which the section belonged
154+
* @param {MenuSection} section The MenuSection of which the ID should be removed from the index
155+
* @param {MenuID} menuID The Menu ID to which the section belonged
153156
* @returns {MenusState} The new reduced state
154157
*/
155158
function removeFromIndex(state: MenusState, section: MenuSection, menuID: MenuID) {
159+
if (hasNoValue(section)) {
160+
return state;
161+
}
156162
const sectionID = section.id;
157163
const parentID = section.parentID;
158164
if (hasValue(parentID)) {

0 commit comments

Comments
 (0)