X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9fbb245286171bc55fed5b5104361a1869a1d76b..e586962e68a264bc6a8cf2830475e4fb2c910046:/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 d9111f47d9..f14c54feae 100644
--- a/src/views-components/file-uploader/file-uploader.tsx
+++ b/src/views-components/file-uploader/file-uploader.tsx
@@ -8,7 +8,7 @@ import { connect } from 'react-redux';
 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, FileWithId } from '~/store/file-uploader/file-uploader-actions';
 import { WrappedFieldProps } from 'redux-form';
 import { Typography } from '@material-ui/core';
 
@@ -19,11 +19,18 @@ 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: files => dispatch(fileUploaderActions.DELETE_UPLOAD_FILE(files as FileWithId[])),
 });
 
 export const FileUploader = connect(mapStateToProps, mapDispatchToProps)(FileUpload);
