projects
/
arvados-workbench2.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
18594: Code and test cleanup
[arvados-workbench2.git]
/
src
/
store
/
dialog
/
dialog-reducer.ts
diff --git
a/src/store/dialog/dialog-reducer.ts
b/src/store/dialog/dialog-reducer.ts
index 6013ab64c1bc240404679963fd0d355a1e402c16..30368685064dfe6f9837d7c20d0cc4808b0cbf01 100644
(file)
--- a/
src/store/dialog/dialog-reducer.ts
+++ b/
src/store/dialog/dialog-reducer.ts
@@
-4,17
+4,24
@@
import { DialogAction, dialogActions } from "./dialog-actions";
import { DialogAction, dialogActions } from "./dialog-actions";
-export type DialogState = Record<string, Dialog>;
+export type DialogState = Record<string, Dialog
<any>
>;
-export interface Dialog {
+export interface Dialog
<T>
{
open: boolean;
open: boolean;
- data
?: any
;
+ data
: T
;
}
export const dialogReducer = (state: DialogState = {}, action: DialogAction) =>
}
export const dialogReducer = (state: DialogState = {}, action: DialogAction) =>
+
dialogActions.match(action, {
OPEN_DIALOG: ({ id, data }) => ({ ...state, [id]: { open: true, data } }),
dialogActions.match(action, {
OPEN_DIALOG: ({ id, data }) => ({ ...state, [id]: { open: true, data } }),
- CLOSE_DIALOG: ({ id }) => ({ ...state, [id]: { open: false } }),
+ CLOSE_DIALOG: ({ id }) => ({
+ ...state,
+ [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} }
+ }),
+ CLOSE_ALL_DIALOGS: () => ({ }),
default: () => state,
});
default: () => state,
});
+export const getDialog = <T>(state: DialogState, id: string) =>
+ state[id] ? state[id] as Dialog<T> : undefined;