Merge branch 'master' into 14313-basic-view-recent-queries
[arvados-workbench2.git] / src / store / dialog / dialog-reducer.ts
index e49f65debc70c37dbfaeaa3f960cbf60442a96fe..48f8ee8a1e6caac149fb07b8c94a10a46a3f2377 100644 (file)
@@ -4,11 +4,11 @@
 
 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) =>
@@ -16,7 +16,9 @@ export const dialogReducer = (state: DialogState = {}, action: DialogAction) =>
         OPEN_DIALOG: ({ id, data }) => ({ ...state, [id]: { open: true, data } }),
         CLOSE_DIALOG: ({ id }) => ({ 
             ...state, 
-            [id]: state[id] ? { ...state[id], open: false } : { open: false } }),
+            [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} } }),
         default: () => state,
     });
 
+export const getDialog = <T>(state: DialogState, id: string) => 
+    state[id] ? state[id] as Dialog<T> : undefined;