Merge branch 'master' into 13540-add-possibility-to-open-files-in-third-party-apps
[arvados-workbench2.git] / src / store / dialog / dialog-reducer.ts
index e49f65debc70c37dbfaeaa3f960cbf60442a96fe..30368685064dfe6f9837d7c20d0cc4808b0cbf01 100644 (file)
@@ -4,19 +4,24 @@
 
 import { DialogAction, dialogActions } from "./dialog-actions";
 
-export type DialogState = Record<string, Dialog>;
+export type DialogState = Record<string, Dialog<any>>;
 
-export interface Dialog {
+export interface Dialog<T> {
     open: boolean;
-    data?: any;
+    data: T;
 }
 
 export const dialogReducer = (state: DialogState = {}, 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 } }),
+        CLOSE_DIALOG: ({ id }) => ({
+            ...state,
+            [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} }
+        }),
+        CLOSE_ALL_DIALOGS: () => ({ }),
         default: () => state,
     });
 
+export const getDialog = <T>(state: DialogState, id: string) =>
+    state[id] ? state[id] as Dialog<T> : undefined;