X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/e3b0f767bb84fa82188879e391b5feff15a3db0f..ef8180fa2f0b90b1656b1d8c7ef12bc6ea028a0a:/src/views-components/file-uploader/file-uploader.tsx?ds=sidebyside

diff --git a/src/views-components/file-uploader/file-uploader.tsx b/src/views-components/file-uploader/file-uploader.tsx
index d9111f47..be592617 100644
--- a/src/views-components/file-uploader/file-uploader.tsx
+++ b/src/views-components/file-uploader/file-uploader.tsx
@@ -2,13 +2,13 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { FileUpload } from '~/components/file-upload/file-upload';
+import React from 'react';
+import { FileUpload } from 'components/file-upload/file-upload';
 import { connect } from 'react-redux';
-import { RootState } from '~/store/store';
+import { RootState } from 'store/store';
 import { FileUploadProps } from '../../components/file-upload/file-upload';
 import { Dispatch } from 'redux';
-import { fileUploaderActions } from '~/store/file-uploader/file-uploader-actions';
+import { fileUploaderActions, getFileUploaderState } from 'store/file-uploader/file-uploader-actions';
 import { WrappedFieldProps } from 'redux-form';
 import { Typography } from '@material-ui/core';
 
@@ -19,17 +19,24 @@ const mapStateToProps = (state: RootState, { disabled }: FileUploaderProps): Pic
     files: state.fileUploader,
 });
 
-const mapDispatchToProps = (dispatch: Dispatch, { onDrop }: FileUploaderProps): Pick<FileUploadProps, 'onDrop'> => ({
+const mapDispatchToProps = (dispatch: Dispatch, { onDrop }: FileUploaderProps): Pick<FileUploadProps, 'onDrop' | 'onDelete'> => ({
     onDrop: files => {
-        dispatch(fileUploaderActions.SET_UPLOAD_FILES(files));
-        onDrop(files);
+        const state = dispatch<any>(getFileUploaderState());
+        if (files.length > 0 && state.length === 0) {
+            dispatch(fileUploaderActions.SET_UPLOAD_FILES(files));
+            onDrop(files);
+        } else if (files.length > 0 && state.length > 0) {
+            dispatch(fileUploaderActions.UPDATE_UPLOAD_FILES(files));
+            onDrop(files);
+        }
     },
+    onDelete: file => dispatch(fileUploaderActions.DELETE_UPLOAD_FILE(file))
 });
 
 export const FileUploader = connect(mapStateToProps, mapDispatchToProps)(FileUpload);
 
 export const FileUploaderField = (props: WrappedFieldProps & { label?: string }) =>
-    <div>
+    <>
         <Typography variant='caption'>{props.label}</Typography>
-        <FileUploader disabled={props.meta.submitting} onDrop={props.input.onChange} />
-    </div>;
+        <FileUploader disabled={false} onDrop={props.input.onChange} />
+    </>;
