13494: Makes several operations asynchronous.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 18 Nov 2020 21:46:21 +0000 (18:46 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 18 Nov 2020 21:46:21 +0000 (18:46 -0300)
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 <lucas@di-pentima.com.ar>

src/store/collection-panel/collection-panel-action.ts
src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts
src/store/details-panel/details-panel-action.ts

index 851ba84d73e8d095b7be3a563149ee05e936c0cb..58407b903e9696af73e7a0dc20c345b188cd58e2 100644 (file)
@@ -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<any>(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<any>(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 }));
+        });
     };
index 7b2b2557aaf26eb2c39a729c05048dc6d7ccabbc..1d2a40b22ddfa10c3d68bf13d7ab423dc7f42683 100644 (file)
@@ -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<CollectionFilesTree>(),
@@ -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<any>(loadCollectionFiles(currentCollection.uuid));
                 dispatch(snackbarActions.OPEN_SNACKBAR({
                     message: 'Removed.',
                     hideDuration: 2000,
                     kind: SnackbarKind.SUCCESS
                 }));
-            } catch (e) {
+                dispatch<any>(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<RenameFileDialogData>(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<any>(loadCollectionFiles(currentCollection.uuid));
                     dispatch(dialogActions.CLOSE_DIALOG({ id: RENAME_FILE_DIALOG }));
                     dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'File name changed.', hideDuration: 2000 }));
-                } catch (e) {
+                    dispatch<any>(loadDetailsPanel(currentCollection.uuid));
+                }).catch (e => {
                     const errors: FormErrors<RenameFileDialogData, string> = {
                         path: `Could not rename the file: ${e.responseText}`
                     };
                     dispatch(stopSubmit(RENAME_FILE_DIALOG, errors));
-                }
+                });
             }
         }
     };
index 69b69d3b490277ae2be794d9dbaa7af83cc2c107..91ca9cbad460e5d54095cbfe988dafbb76d52b24 100644 (file)
@@ -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<CollectionResource>().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) =>