18169: Removed cancel disable when uploading
[arvados-workbench2.git] / src / store / file-uploader / file-uploader-reducer.ts
index 9ea6313131b1d0e598ad5771cf75b5d370b5b86b..bade4c8f88082aa6057d6e8f7c1d07f2cc134979 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { UploadFile, fileUploaderActions, FileUploaderAction } from "./file-uploader-actions";
-import * as _ from 'lodash';
+import { uniqBy } from 'lodash';
 
 export type UploaderState = UploadFile[];
 
@@ -33,10 +33,33 @@ export const fileUploaderReducer = (state: UploaderState = initialState, action:
                 currentTime: 0
             }));
             const updatedState = state.concat(updateFiles);
-            const uniqUpdatedState = _.uniqBy(updatedState, 'file.name');
+            const uniqUpdatedState = uniqBy(updatedState, 'file.name');
 
             return uniqUpdatedState;
         },
+        DELETE_UPLOAD_FILE: file => {
+            const idToDelete: number = file.id;
+            const updatedState = state.filter(file => file.id !== idToDelete);
+
+            const key: string | undefined = Object.keys((window as any).cancelTokens)
+                .find(key => key.indexOf(file.file.name) > -1);
+
+            if (key) {
+                (window as any).cancelTokens[key]();
+                delete (window as any).cancelTokens[key];
+            }
+
+            return updatedState;
+        },
+        CANCEL_FILES_UPLOAD: () => {
+            Object.keys((window as any).cancelTokens)
+                .forEach((key) => {
+                    (window as any).cancelTokens[key]();
+                    delete (window as any).cancelTokens[key];
+                });
+
+            return state;
+        },
         START_UPLOAD: () => {
             const startTime = Date.now();
             return state.map(f => ({ ...f, startTime, prevTime: startTime }));