refs #14310 Merge branch 'origin/14310-upload-crash-on-chrome'
[arvados-workbench2.git] / src / store / collections / collection-upload-actions.ts
index 4a5aff35009becbbdb6e018b4735fce4618fb842..cf8c37c890f6d24c79de79c37ab776f690ca6f61 100644 (file)
@@ -7,9 +7,10 @@ import { RootState } from '~/store/store';
 import { ServiceRepository } from '~/services/services';
 import { dialogActions } from '~/store/dialog/dialog-actions';
 import { loadCollectionFiles } from '../collection-panel/collection-panel-files/collection-panel-files-actions';
-import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
 import { fileUploaderActions } from '~/store/file-uploader/file-uploader-actions';
-import { reset, startSubmit } from 'redux-form';
+import { reset, startSubmit, stopSubmit } from 'redux-form';
+import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
 
 export const uploadCollectionFiles = (collectionUuid: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
@@ -31,11 +32,28 @@ export const submitCollectionFiles = () =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const currentCollection = getState().collectionPanel.item;
         if (currentCollection) {
-            dispatch(startSubmit(COLLECTION_UPLOAD_FILES_DIALOG));
-            await dispatch<any>(uploadCollectionFiles(currentCollection.uuid));
-            dispatch<any>(loadCollectionFiles(currentCollection.uuid));
-            dispatch(closeUploadCollectionFilesDialog());
-            dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Data has been uploaded.', hideDuration: 2000 }));
+            try {
+                dispatch(progressIndicatorActions.START_WORKING(COLLECTION_UPLOAD_FILES_DIALOG));
+                dispatch(startSubmit(COLLECTION_UPLOAD_FILES_DIALOG));
+                await dispatch<any>(uploadCollectionFiles(currentCollection.uuid));
+                dispatch<any>(loadCollectionFiles(currentCollection.uuid));
+                dispatch(closeUploadCollectionFilesDialog());
+                dispatch(snackbarActions.OPEN_SNACKBAR({
+                    message: 'Data has been uploaded.',
+                    hideDuration: 2000,
+                    kind: SnackbarKind.SUCCESS
+                }));
+                dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPLOAD_FILES_DIALOG));
+            } catch (e) {
+                dispatch(stopSubmit(COLLECTION_UPLOAD_FILES_DIALOG));
+                dispatch(closeUploadCollectionFilesDialog());
+                dispatch(snackbarActions.OPEN_SNACKBAR({
+                    message: 'Data has not been uploaded. Too large file',
+                    hideDuration: 2000,
+                    kind: SnackbarKind.ERROR
+                }));
+                dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPLOAD_FILES_DIALOG));
+            }
         }
     };
 
@@ -43,4 +61,4 @@ export const closeUploadCollectionFilesDialog = () => dialogActions.CLOSE_DIALOG
 
 const handleUploadProgress = (dispatch: Dispatch) => (fileId: number, loaded: number, total: number, currentTime: number) => {
     dispatch(fileUploaderActions.SET_UPLOAD_PROGRESS({ fileId, loaded, total, currentTime }));
-};
\ No newline at end of file
+};