13494: Simplifies collection update action calling.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 18 Nov 2020 21:43:45 +0000 (18:43 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 18 Nov 2020 21:43:45 +0000 (18:43 -0300)
Also makes action asynchronous, and refresh details panel after the update
operation is done.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

src/store/collections/collection-update-actions.ts
src/store/workbench/workbench-actions.ts
src/views-components/dialog-forms/update-collection-dialog.ts

index f8fac398b7ad3458241213e4f4772be401f43074..2faaa215b4ab6e1c694697bef7b5b02e9c6bf845 100644 (file)
@@ -11,6 +11,10 @@ import { getCommonResourceServiceError, CommonResourceServiceError } from "~/ser
 import { ServiceRepository } from "~/services/services";
 import { CollectionResource } from '~/models/collection';
 import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
+import { snackbarActions, SnackbarKind } from "../snackbar/snackbar-actions";
+import { updateResources } from "../resources/resources-actions";
+import { reloadProjectMatchingUuid } from "../workbench/workbench-actions";
+import { loadDetailsPanel } from "../details-panel/details-panel-action";
 
 export interface CollectionUpdateFormDialogData {
     uuid: string;
@@ -27,26 +31,38 @@ export const openCollectionUpdateDialog = (resource: CollectionUpdateFormDialogD
     };
 
 export const updateCollection = (collection: CollectionUpdateFormDialogData) =>
-    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const uuid = collection.uuid || '';
         dispatch(startSubmit(COLLECTION_UPDATE_FORM_NAME));
         dispatch(progressIndicatorActions.START_WORKING(COLLECTION_UPDATE_FORM_NAME));
-        try {
-            const updatedCollection = await services.collectionService.update(uuid, { name: collection.name, description: collection.description });
+
+        services.collectionService.update(uuid, {
+            name: collection.name,
+            description: collection.description }
+        ).then(updatedCollection => {
             dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: updatedCollection as CollectionResource }));
             dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_UPDATE_FORM_NAME }));
             dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPDATE_FORM_NAME));
-            return updatedCollection;
-        } catch (e) {
+            dispatch(snackbarActions.OPEN_SNACKBAR({
+                message: "Collection has been successfully updated.",
+                hideDuration: 2000,
+                kind: SnackbarKind.SUCCESS
+            }));
+            dispatch<any>(updateResources([updatedCollection]));
+            dispatch<any>(reloadProjectMatchingUuid([updatedCollection.ownerUuid]));
+            dispatch<any>(loadDetailsPanel(updatedCollection.uuid));
+        }).catch (e => {
             dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPDATE_FORM_NAME));
             const error = getCommonResourceServiceError(e);
             if (error === CommonResourceServiceError.UNIQUE_NAME_VIOLATION) {
                 dispatch(stopSubmit(COLLECTION_UPDATE_FORM_NAME, { name: 'Collection with the same name already exists.' } as FormErrors));
             } else {
-                // Unknown error, handling left to caller.
                 dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_UPDATE_FORM_NAME }));
-                throw(e);
+                dispatch(snackbarActions.OPEN_SNACKBAR({
+                    message: e.errors.join(''),
+                    hideDuration: 2000,
+                    kind: SnackbarKind.ERROR }));
+                }
             }
-        }
-        return;
+        );
     };
index 0416d815805640bbe7bc69fb046cec7abc169a1d..09aad2bd581b2e62d8cc23fc8be674e4f1f1d7b2 100644 (file)
@@ -42,7 +42,6 @@ import * as projectMoveActions from '~/store/projects/project-move-actions';
 import * as projectUpdateActions from '~/store/projects/project-update-actions';
 import * as collectionCreateActions from '~/store/collections/collection-create-actions';
 import * as collectionCopyActions from '~/store/collections/collection-copy-actions';
-import * as collectionUpdateActions from '~/store/collections/collection-update-actions';
 import * as collectionMoveActions from '~/store/collections/collection-move-actions';
 import * as processesActions from '~/store/processes/processes-actions';
 import * as processMoveActions from '~/store/processes/process-move-actions';
@@ -323,24 +322,6 @@ export const createCollection = (data: collectionCreateActions.CollectionCreateF
         }
     };
 
-export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
-    async (dispatch: Dispatch) => {
-        try {
-            const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
-            if (collection) {
-                dispatch(snackbarActions.OPEN_SNACKBAR({
-                    message: "Collection has been successfully updated.",
-                    hideDuration: 2000,
-                    kind: SnackbarKind.SUCCESS
-                }));
-                dispatch<any>(updateResources([collection]));
-                dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
-            }
-        } catch (e) {
-            dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors.join(''), hideDuration: 2000, kind: SnackbarKind.ERROR }));
-        }
-    };
-
 export const copyCollection = (data: CopyFormDialogData) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         try {
index 021a335b63dd6c0ffd9c0da80a5850bde49d26ed..b2fe96b816f5dd3f7ebd26fd34a8826e0273e052 100644 (file)
@@ -6,8 +6,7 @@ import { compose } from "redux";
 import { reduxForm } from 'redux-form';
 import { withDialog } from "~/store/dialog/with-dialog";
 import { DialogCollectionUpdate } from '~/views-components/dialog-update/dialog-collection-update';
-import { COLLECTION_UPDATE_FORM_NAME, CollectionUpdateFormDialogData } from '~/store/collections/collection-update-actions';
-import { updateCollection } from "~/store/workbench/workbench-actions";
+import { COLLECTION_UPDATE_FORM_NAME, CollectionUpdateFormDialogData, updateCollection } from '~/store/collections/collection-update-actions';
 
 export const UpdateCollectionDialog = compose(
     withDialog(COLLECTION_UPDATE_FORM_NAME),