1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { DialogAction, dialogActions } from "./dialog-actions";
7 export type DialogState = Record<string, Dialog<any>>;
9 export interface Dialog<T> {
14 export const dialogReducer = (state: DialogState = {}, action: DialogAction) =>
16 dialogActions.match(action, {
17 OPEN_DIALOG: ({ id, data }) => ({ ...state, [id]: { open: true, data } }),
18 CLOSE_DIALOG: ({ id }) => ({
20 [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} }
22 CLOSE_ALL_DIALOGS: () => ({ }),
26 export const getDialog = <T>(state: DialogState, id: string) =>
27 state[id] ? state[id] as Dialog<T> : undefined;