Use webdav to retrieve list of files
[arvados-workbench2.git] / src / store / dialog / with-dialog.ts
index 60cb5d1024f8eb7f994ce852c59641545ec99d05..d53a79d6efe19f5ccde771f05d1590bd77199f0e 100644 (file)
@@ -5,17 +5,31 @@
 import * as React from 'react';
 import { connect } from 'react-redux';
 import { DialogState } from './dialog-reducer';
+import { Dispatch } from 'redux';
+import { dialogActions } from './dialog-actions';
 
-export type WithDialog<T> = {
+export type WithDialogStateProps<T> = {
     open: boolean;
-    data?: T;
+    data: T;
 };
 
+export type WithDialogDispatchProps = {
+    closeDialog: () => void;
+};
+
+export type WithDialogProps<T> = WithDialogStateProps<T> & WithDialogDispatchProps;
+
 export const withDialog = (id: string) =>
-    <T>(component: React.ComponentType<WithDialog<T>>) =>
-        connect(mapStateToProps(id))(component);
+    <T, P>(component: React.ComponentType<WithDialogProps<T> & P>) =>
+        connect(mapStateToProps(id), mapDispatchToProps(id))(component);
 
-export const mapStateToProps = (id: string) => <T>(state: { dialog: DialogState }): WithDialog<T> => {
+export const mapStateToProps = (id: string) => <T>(state: { dialog: DialogState }): WithDialogStateProps<T> => {
     const dialog = state.dialog[id];
-    return dialog ? dialog : { open: false };
+    return dialog ? dialog : { open: false, data: {} };
 };
+
+export const mapDispatchToProps = (id: string) => (dispatch: Dispatch): WithDialogDispatchProps => ({
+    closeDialog: () => {
+        dispatch(dialogActions.CLOSE_DIALOG({ id }));
+    }
+});
\ No newline at end of file