X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c0afd448c39a41d229612afe47643aed7a2cf5dd..e5682f2f1490de87f7727a364c717c06d5f58eee:/src/store/dialog/dialog-reducer.ts diff --git a/src/store/dialog/dialog-reducer.ts b/src/store/dialog/dialog-reducer.ts index e49f65de..548d0a78 100644 --- a/src/store/dialog/dialog-reducer.ts +++ b/src/store/dialog/dialog-reducer.ts @@ -2,21 +2,24 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { DialogAction, dialogActions } from "./dialog-actions"; +import { DialogAction, dialogActions } from './dialog-actions'; -export type DialogState = Record; +export type DialogState = Record>; -export interface Dialog { +export interface Dialog { 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 = (state: DialogState, id: string) => (state[id] ? (state[id] as Dialog) : undefined);