[ARVADOS-WORKBENCH2] created: 1.3.1-461-gc35f7839

Git user git at public.curoverse.com
Wed May 22 10:02:39 UTC 2019


        at  c35f7839e29088c6f5711d9fddfa69e4c8440fb2 (commit)


commit c35f7839e29088c6f5711d9fddfa69e4c8440fb2
Author: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
Date:   Wed May 22 12:02:23 2019 +0200

    adding-posibility-to-choose-files-many-times-and-dont-replace-other-files
    
    Feature #15160
    
    Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>

diff --git a/src/store/file-uploader/file-uploader-actions.ts b/src/store/file-uploader/file-uploader-actions.ts
index 906263fe..f4a30a23 100644
--- a/src/store/file-uploader/file-uploader-actions.ts
+++ b/src/store/file-uploader/file-uploader-actions.ts
@@ -3,6 +3,8 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { unionize, ofType, UnionOf } from "~/common/unionize";
+import { Dispatch } from "redux";
+import { RootState } from '~/store/store';
 
 export interface UploadFile {
     id: number;
@@ -18,8 +20,13 @@ export interface UploadFile {
 export const fileUploaderActions = unionize({
     CLEAR_UPLOAD: ofType(),
     SET_UPLOAD_FILES: ofType<File[]>(),
+    UPDATE_UPLOAD_FILES: ofType<File[]>(),
     SET_UPLOAD_PROGRESS: ofType<{ fileId: number, loaded: number, total: number, currentTime: number }>(),
     START_UPLOAD: ofType(),
 });
 
 export type FileUploaderAction = UnionOf<typeof fileUploaderActions>;
+
+export const getFileUploaderState = () => (dispatch: Dispatch, getState: () => RootState) => {
+    return getState().fileUploader;
+};
\ No newline at end of file
diff --git a/src/store/file-uploader/file-uploader-reducer.ts b/src/store/file-uploader/file-uploader-reducer.ts
index 625306f0..9ea63131 100644
--- a/src/store/file-uploader/file-uploader-reducer.ts
+++ b/src/store/file-uploader/file-uploader-reducer.ts
@@ -3,6 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { UploadFile, fileUploaderActions, FileUploaderAction } from "./file-uploader-actions";
+import * as _ from 'lodash';
 
 export type UploaderState = UploadFile[];
 
@@ -20,9 +21,25 @@ export const fileUploaderReducer = (state: UploaderState = initialState, action:
             prevTime: 0,
             currentTime: 0
         })),
+        UPDATE_UPLOAD_FILES: files => {
+            const updateFiles = files.map((f, idx) => ({
+                id: state.length + idx,
+                file: f,
+                prevLoaded: 0,
+                loaded: 0,
+                total: 0,
+                startTime: 0,
+                prevTime: 0,
+                currentTime: 0
+            }));
+            const updatedState = state.concat(updateFiles);
+            const uniqUpdatedState = _.uniqBy(updatedState, 'file.name');
+
+            return uniqUpdatedState;
+        },
         START_UPLOAD: () => {
             const startTime = Date.now();
-            return state.map(f => ({...f, startTime, prevTime: startTime}));
+            return state.map(f => ({ ...f, startTime, prevTime: startTime }));
         },
         SET_UPLOAD_PROGRESS: ({ fileId, loaded, total, currentTime }) =>
             state.map(f => f.id === fileId ? {
diff --git a/src/views-components/file-uploader/file-uploader.tsx b/src/views-components/file-uploader/file-uploader.tsx
index e71a14c5..83808016 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 } from '~/store/file-uploader/file-uploader-actions';
 import { WrappedFieldProps } from 'redux-form';
 import { Typography } from '@material-ui/core';
 
@@ -21,9 +21,13 @@ const mapStateToProps = (state: RootState, { disabled }: FileUploaderProps): Pic
 
 const mapDispatchToProps = (dispatch: Dispatch, { onDrop }: FileUploaderProps): Pick<FileUploadProps, 'onDrop'> => ({
     onDrop: files => {
-        if (files.length > 0) {
+        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);
         }
     },
 });

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list