X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/fb1ecf2421f8aac07d733d3bb56bb39312274f8c..8ae34cc6c505d6359bf300d111d0c7b4e4e68a15:/src/store/collections/collection-upload-actions.ts diff --git a/src/store/collections/collection-upload-actions.ts b/src/store/collections/collection-upload-actions.ts index c04ef1a2..ef241a7c 100644 --- a/src/store/collections/collection-upload-actions.ts +++ b/src/store/collections/collection-upload-actions.ts @@ -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 } from 'redux-form'; +import { reset, startSubmit } from 'redux-form'; +import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions"; export const uploadCollectionFiles = (collectionUuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { @@ -19,27 +20,38 @@ export const uploadCollectionFiles = (collectionUuid: string) => dispatch(fileUploaderActions.CLEAR_UPLOAD()); }; -export const UPLOAD_COLLECTION_FILES_DIALOG = 'uploadCollectionFilesDialog'; +export const COLLECTION_UPLOAD_FILES_DIALOG = 'uploadCollectionFilesDialog'; export const openUploadCollectionFilesDialog = () => (dispatch: Dispatch) => { - dispatch(reset(UPLOAD_COLLECTION_FILES_DIALOG)); + dispatch(reset(COLLECTION_UPLOAD_FILES_DIALOG)); dispatch(fileUploaderActions.CLEAR_UPLOAD()); - dispatch(dialogActions.OPEN_DIALOG({ id: UPLOAD_COLLECTION_FILES_DIALOG, data: {} })); + dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_UPLOAD_FILES_DIALOG, data: {} })); }; -export const uploadCurrentCollectionFiles = () => +export const submitCollectionFiles = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const currentCollection = getState().collectionPanel.item; if (currentCollection) { - await dispatch(uploadCollectionFiles(currentCollection.uuid)); - dispatch(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(uploadCollectionFiles(currentCollection.uuid)); + dispatch(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(progressIndicatorActions.STOP_WORKING(COLLECTION_UPLOAD_FILES_DIALOG)); + } } }; -export const closeUploadCollectionFilesDialog = () => dialogActions.CLOSE_DIALOG({ id: UPLOAD_COLLECTION_FILES_DIALOG }); +export const closeUploadCollectionFilesDialog = () => dialogActions.CLOSE_DIALOG({ id: COLLECTION_UPLOAD_FILES_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 +};