X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/9f472b932176e09be950115feab148da3be5c321..4f26fc6e11a411c11fc481b937c2e073f4858081:/src/store/dialog/dialog-reducer.ts diff --git a/src/store/dialog/dialog-reducer.ts b/src/store/dialog/dialog-reducer.ts index 48f8ee8a..30368685 100644 --- a/src/store/dialog/dialog-reducer.ts +++ b/src/store/dialog/dialog-reducer.ts @@ -6,19 +6,22 @@ import { DialogAction, dialogActions } from "./dialog-actions"; export type DialogState = Record>; -export interface Dialog { +export interface Dialog { open: boolean; 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, data: {} } }), + CLOSE_DIALOG: ({ id }) => ({ + ...state, + [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} } + }), + CLOSE_ALL_DIALOGS: () => ({ }), default: () => state, }); -export const getDialog = (state: DialogState, id: string) => +export const getDialog = (state: DialogState, id: string) => state[id] ? state[id] as Dialog : undefined;