Skip to content

Commit

Permalink
Merge pull request #882 from opossum-tool/allow_only_one_open_popup_o…
Browse files Browse the repository at this point in the history
…f_a_kind

Allow only one popup of a kind
  • Loading branch information
leslielazzarino authored Aug 29, 2022
2 parents 4bc931f + ca09295 commit 6453bc4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,17 @@ describe('popup actions', () => {
expect(getPopupAttributionId(testStore.getState())).toBeNull();
expect(getOpenPopup(testStore.getState())).toBeNull();
});

it('opens each popup only once', () => {
const testStore = createTestAppStore();
expect(getOpenPopup(testStore.getState())).toBeNull();
// open file search popup twice
testStore.dispatch(openPopup(PopupType.FileSearchPopup));
testStore.dispatch(openPopup(PopupType.FileSearchPopup));
expect(getOpenPopup(testStore.getState())).toBe(PopupType.FileSearchPopup);

// there should be only one search popup open
testStore.dispatch(closePopup());
expect(getOpenPopup(testStore.getState())).toBeNull();
});
});
6 changes: 5 additions & 1 deletion src/Frontend/state/reducers/view-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ export function viewState(
popupInfo: state.popupInfo.slice(0, -1),
};
case ACTION_OPEN_POPUP:
const openPopups = state.popupInfo.map((popupInfo) => popupInfo.popup);
const newPopupInfo = openPopups.includes(action.payload.popup)
? state.popupInfo
: state.popupInfo.concat(action.payload);
return {
...state,
popupInfo: state.popupInfo.concat(action.payload),
popupInfo: newPopupInfo,
};
case ACTION_UPDATE_ACTIVE_FILTERS:
return {
Expand Down

0 comments on commit 6453bc4

Please sign in to comment.