modals-are-closed-after-using-browsers-back-or-forward-option
authorPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Thu, 13 Dec 2018 14:54:25 +0000 (15:54 +0100)
committerPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Thu, 13 Dec 2018 14:54:25 +0000 (15:54 +0100)
Feature #14489

Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>

src/routes/route-change-handlers.ts
src/store/dialog/dialog-actions.ts
src/store/dialog/dialog-reducer.ts

index c4b0fc7d5d5486f8be4fc30896a5296407c90ed2..655c806f3a3b0337cc1a89eccae6b7a29ddaa832 100644 (file)
@@ -7,6 +7,7 @@ import { RootStore } from '~/store/store';
 import * as Routes from '~/routes/routes';
 import * as WorkbenchActions from '~/store/workbench/workbench-actions';
 import { navigateToRootProject } from '~/store/navigation/navigation-action';
+import { dialogActions } from '~/store/dialog/dialog-actions';
 
 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
     const handler = handleLocationChange(store);
@@ -38,6 +39,8 @@ const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
     const userMatch = Routes.matchUsersRoute(pathname);
     const linksMatch = Routes.matchLinksRoute(pathname);
 
+    store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
+
     if (projectMatch) {
         store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
     } else if (collectionMatch) {
index 22629b692f2bff6dea8c7f78ee97ea18fe0308ca..ce01a50d6919285190974570e254e14841989061 100644 (file)
@@ -6,7 +6,8 @@ import { unionize, ofType, UnionOf } from "~/common/unionize";
 
 export const dialogActions = unionize({
     OPEN_DIALOG: ofType<{ id: string, data: any }>(),
-    CLOSE_DIALOG: ofType<{ id: string }>()
+    CLOSE_DIALOG: ofType<{ id: string }>(),
+    CLOSE_ALL_DIALOGS: ofType<{}>()
 });
 
 export type DialogAction = UnionOf<typeof dialogActions>;
index 48f8ee8a1e6caac149fb07b8c94a10a46a3f2377..775a4d5fce87eed6f93f30650bd3ad5148567ce2 100644 (file)
@@ -6,19 +6,24 @@ import { DialogAction, dialogActions } from "./dialog-actions";
 
 export type DialogState = Record<string, Dialog<any>>;
 
-export interface Dialog <T> {
+export interface Dialog<T> {
     open: boolean;
     data: T;
 }
 
-export const dialogReducer = (state: DialogState = {}, action: DialogAction) =>
+const initialState: DialogState = {};
+
+export const dialogReducer = (state: DialogState = initialState, action: DialogAction) =>
+
     dialogActions.match(action, {
         OPEN_DIALOG: ({ id, data }) => ({ ...state, [id]: { open: true, data } }),
-        CLOSE_DIALOG: ({ id }) => ({ 
-            ...state, 
-            [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} } }),
+        CLOSE_DIALOG: ({ id }) => ({
+            ...state,
+            [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} }
+        }),
+        CLOSE_ALL_DIALOGS: () => ({ ...initialState }),
         default: () => state,
     });
 
-export const getDialog = <T>(state: DialogState, id: string) => 
+export const getDialog = <T>(state: DialogState, id: string) =>
     state[id] ? state[id] as Dialog<T> : undefined;