refs #master Merge branch 'origin/master' into 14044-filter-order-simplification
[arvados-workbench2.git] / src / store / dialog / dialog-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { DialogAction, dialogActions } from "./dialog-actions";
6
7 export type DialogState = Record<string, Dialog>;
8
9 export interface Dialog {
10     open: boolean;
11     data: any;
12 }
13
14 export const dialogReducer = (state: DialogState = {}, action: DialogAction) =>
15     dialogActions.match(action, {
16         OPEN_DIALOG: ({ id, data }) => ({ ...state, [id]: { open: true, data } }),
17         CLOSE_DIALOG: ({ id }) => ({ 
18             ...state, 
19             [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} } }),
20         default: () => state,
21     });
22