Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / dialog / dialog-reducer.ts
index 48f8ee8a1e6caac149fb07b8c94a10a46a3f2377..548d0a7897f99ba48a27c9826bf02bc18ad8d9ca 100644 (file)
@@ -2,11 +2,11 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { DialogAction, dialogActions } from "./dialog-actions";
+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;
 }
@@ -14,11 +14,12 @@ export interface Dialog <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, data: {} } }),
+        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;
+export const getDialog = <T>(state: DialogState, id: string) => (state[id] ? (state[id] as Dialog<T>) : undefined);