From: Lucas Di Pentima Date: Wed, 18 Nov 2020 21:46:21 +0000 (-0300) Subject: 13494: Makes several operations asynchronous. X-Git-Tag: 2.1.2~26^2~7 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/7b8e48c2f9130d799a42c81440bc8b4e04224d4e 13494: Makes several operations asynchronous. Details panel's collection version browser refresh, property addition and removal, file renaming and removal are now asynchronous. Also, the details panel gets reloaded when this collection operations take place. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/store/collection-panel/collection-panel-action.ts b/src/store/collection-panel/collection-panel-action.ts index 851ba84d..58407b90 100644 --- a/src/store/collection-panel/collection-panel-action.ts +++ b/src/store/collection-panel/collection-panel-action.ts @@ -44,27 +44,32 @@ export const loadCollectionPanel = (uuid: string) => }; export const createCollectionTag = (data: TagProperty) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const item = getState().collectionPanel.item; if (!item) { return; } const properties = Object.assign({}, item.properties); - try { - const key = data.keyID || data.key; - const value = data.valueID || data.value; - const updatedCollection = await services.collectionService.update( - item.uuid, { - properties: addProperty(properties, key, value) - } - ); + const key = data.keyID || data.key; + const value = data.valueID || data.value; + services.collectionService.update( + item.uuid, { + properties: addProperty(properties, key, value) + } + ).then(updatedCollection => { dispatch(collectionPanelActions.SET_COLLECTION(updatedCollection)); dispatch(resourcesActions.SET_RESOURCES([updatedCollection])); - dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Tag has been successfully added.", hideDuration: 2000, kind: SnackbarKind.SUCCESS })); + dispatch(snackbarActions.OPEN_SNACKBAR({ + message: "Tag has been successfully added.", + hideDuration: 2000, + kind: SnackbarKind.SUCCESS })); + dispatch(loadDetailsPanel(updatedCollection.uuid)); return updatedCollection; - } catch (e) { - dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors[0], hideDuration: 2000, kind: SnackbarKind.ERROR })); - return; - } + }).catch (e => + dispatch(snackbarActions.OPEN_SNACKBAR({ + message: e.errors[0], + hideDuration: 2000, + kind: SnackbarKind.ERROR })) + ); }; export const navigateToProcess = (uuid: string) => @@ -78,23 +83,25 @@ export const navigateToProcess = (uuid: string) => }; export const deleteCollectionTag = (key: string, value: string) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const item = getState().collectionPanel.item; if (!item) { return; } const properties = Object.assign({}, item.properties); - try { - const updatedCollection = await services.collectionService.update( - item.uuid, { - properties: deleteProperty(properties, key, value) - } - ); + services.collectionService.update( + item.uuid, { + properties: deleteProperty(properties, key, value) + } + ).then(updatedCollection => { dispatch(collectionPanelActions.SET_COLLECTION(updatedCollection)); dispatch(resourcesActions.SET_RESOURCES([updatedCollection])); dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Tag has been successfully deleted.", hideDuration: 2000, kind: SnackbarKind.SUCCESS })); + dispatch(loadDetailsPanel(updatedCollection.uuid)); return updatedCollection; - } catch (e) { - dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors[0], hideDuration: 2000, kind: SnackbarKind.ERROR })); - return; - } + }).catch (e => { + dispatch(snackbarActions.OPEN_SNACKBAR({ + message: e.errors[0], + hideDuration: 2000, + kind: SnackbarKind.ERROR })); + }); }; diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts index 7b2b2557..1d2a40b2 100644 --- a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts +++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts @@ -15,6 +15,7 @@ import { startSubmit, stopSubmit, initialize, FormErrors } from 'redux-form'; import { getDialog } from "~/store/dialog/dialog-reducer"; import { getFileFullPath, sortFilesTree } from "~/services/collection-service/collection-service-files-response"; import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions"; +import { loadDetailsPanel } from "~/store/details-panel/details-panel-action"; export const collectionPanelFilesAction = unionize({ SET_COLLECTION_FILES: ofType(), @@ -31,39 +32,44 @@ export const COLLECTION_PANEL_LOAD_FILES = 'collectionPanelLoadFiles'; export const COLLECTION_PANEL_LOAD_FILES_THRESHOLD = 40000; export const loadCollectionFiles = (uuid: string) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { dispatch(progressIndicatorActions.START_WORKING(COLLECTION_PANEL_LOAD_FILES)); - const files = await services.collectionService.files(uuid); - - // Given the array of directories and files, create the appropriate tree nodes, - // sort them, and add the complete url to each. - const tree = createCollectionFilesTree(files); - const sorted = sortFilesTree(tree); - const mapped = mapTreeValues(services.collectionService.extendFileURL)(sorted); - dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES(mapped)); - dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_PANEL_LOAD_FILES)); + services.collectionService.files(uuid).then(files => { + // Given the array of directories and files, create the appropriate tree nodes, + // sort them, and add the complete url to each. + const tree = createCollectionFilesTree(files); + const sorted = sortFilesTree(tree); + const mapped = mapTreeValues(services.collectionService.extendFileURL)(sorted); + dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES(mapped)); + dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_PANEL_LOAD_FILES)); + }).catch(e => { + dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_PANEL_LOAD_FILES)); + dispatch(snackbarActions.OPEN_SNACKBAR({ + message: `Error getting file list: ${e.errors[0]}`, + hideDuration: 2000, + kind: SnackbarKind.ERROR })); + }); }; export const removeCollectionFiles = (filePaths: string[]) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const currentCollection = getState().collectionPanel.item; if (currentCollection) { - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing...' })); - try { - await services.collectionService.deleteFiles(currentCollection.uuid, filePaths); + services.collectionService.deleteFiles(currentCollection.uuid, filePaths).then(() => { dispatch(loadCollectionFiles(currentCollection.uuid)); dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS })); - } catch (e) { + dispatch(loadDetailsPanel(currentCollection.uuid)); + }).catch(e => dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Could not remove file.', hideDuration: 2000, kind: SnackbarKind.ERROR - })); - } + })) + ); } }; @@ -131,7 +137,7 @@ export const openRenameFileDialog = (data: RenameFileDialogData) => }; export const renameFile = (newFullPath: string) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const dialog = getDialog(getState().dialog, RENAME_FILE_DIALOG); const currentCollection = getState().collectionPanel.item; if (dialog && currentCollection) { @@ -140,17 +146,17 @@ export const renameFile = (newFullPath: string) => dispatch(startSubmit(RENAME_FILE_DIALOG)); const oldPath = getFileFullPath(file); const newPath = newFullPath; - try { - await services.collectionService.moveFile(currentCollection.uuid, oldPath, newPath); + services.collectionService.moveFile(currentCollection.uuid, oldPath, newPath).then(() => { dispatch(loadCollectionFiles(currentCollection.uuid)); dispatch(dialogActions.CLOSE_DIALOG({ id: RENAME_FILE_DIALOG })); dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'File name changed.', hideDuration: 2000 })); - } catch (e) { + dispatch(loadDetailsPanel(currentCollection.uuid)); + }).catch (e => { const errors: FormErrors = { path: `Could not rename the file: ${e.responseText}` }; dispatch(stopSubmit(RENAME_FILE_DIALOG, errors)); - } + }); } } }; diff --git a/src/store/details-panel/details-panel-action.ts b/src/store/details-panel/details-panel-action.ts index 69b69d3b..91ca9cba 100644 --- a/src/store/details-panel/details-panel-action.ts +++ b/src/store/details-panel/details-panel-action.ts @@ -61,15 +61,19 @@ export const openProjectPropertiesDialog = () => }; export const refreshCollectionVersionsList = (uuid: string) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const versions = await services.collectionService.list({ + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + services.collectionService.list({ filters: new FilterBuilder() .addEqual('current_version_uuid', uuid) .getFilters(), includeOldVersions: true, order: new OrderBuilder().addDesc("version").getOrder() - }); - dispatch(resourcesActions.SET_RESOURCES(versions.items)); + }).then(versions => dispatch(resourcesActions.SET_RESOURCES(versions.items)) + ).catch(e => snackbarActions.OPEN_SNACKBAR({ + message: `Couldn't retrieve versions: ${e.errors[0]}`, + hideDuration: 2000, + kind: SnackbarKind.ERROR }) + ); }; export const deleteProjectProperty = (key: string, value: string) =>