Skip to content

Commit

Permalink
Allow only one popup of a kind
Browse files Browse the repository at this point in the history
Fix bug of allowing for several instances of a single popup kind to be open.

Fix: #759

Signed-off-by: Benedikt Richter <[email protected]>
  • Loading branch information
benedikt-richter committed Aug 19, 2022
1 parent 8d56f52 commit ca09295
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 ca09295

Please sign in to comment.