[ARVADOS-WORKBENCH2] updated: 1.1.4-640-gf70757a

Git user git at public.curoverse.com
Sat Aug 18 04:09:54 EDT 2018


Summary of changes:
 src/common/api/common-resource-service.ts          | 20 +++++++++++++
 .../collection-panel-files-actions.ts              | 35 +++++++++++++---------
 2 files changed, 41 insertions(+), 14 deletions(-)

       via  f70757a56d4d119c0da5d675242268be786f0cbc (commit)
      from  8fb7517405c53a71782863fcb5863f9b5a948964 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit f70757a56d4d119c0da5d675242268be786f0cbc
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Sat Aug 18 10:09:38 2018 +0200

    Add partial copy form async name validation
    
    Feature #14014
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/common/api/common-resource-service.ts b/src/common/api/common-resource-service.ts
index caa4d76..da5bc33 100644
--- a/src/common/api/common-resource-service.ts
+++ b/src/common/api/common-resource-service.ts
@@ -29,6 +29,12 @@ export interface Errors {
     errorToken: string;
 }
 
+export enum CommonResourceServiceError {
+    UNIQUE_VIOLATION = 'UniqueViolation',
+    UNKNOWN = 'Unknown',
+    NONE = 'None'
+}
+
 export class CommonResourceService<T extends Resource> {
 
     static mapResponseKeys = (response: any): Promise<any> =>
@@ -106,3 +112,17 @@ export class CommonResourceService<T extends Resource> {
     }
 }
 
+export const getCommonResourceServiceError = (errorResponse: any) => {
+    if ('errors' in errorResponse && 'errorToken' in errorResponse) {
+        const error = errorResponse.errors.join('');
+        switch (true) {
+            case /UniqueViolation/.test(error):
+                return CommonResourceServiceError.UNIQUE_VIOLATION;
+            default:
+                return CommonResourceServiceError.UNKNOWN;
+        }
+    }
+    return CommonResourceServiceError.NONE;
+};
+
+
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 114446a..f2dc551 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
@@ -11,8 +11,9 @@ import { snackbarActions } from "../../snackbar/snackbar-actions";
 import { dialogActions } from '../../dialog/dialog-actions';
 import { getNodeValue } from "~/models/tree";
 import { filterCollectionFilesBySelection } from './collection-panel-files-state';
-import { startSubmit, initialize } from 'redux-form';
+import { startSubmit, initialize, SubmissionError, stopSubmit } from 'redux-form';
 import { loadProjectTreePickerProjects } from '../../../views-components/project-tree-picker/project-tree-picker';
+import { getCommonResourceServiceError, CommonResourceServiceError } from "~/common/api/common-resource-service";
 
 export const collectionPanelFilesAction = unionize({
     SET_COLLECTION_FILES: ofType<CollectionFilesTree>(),
@@ -113,19 +114,25 @@ export const doCollectionPartialCopy = ({ name, description, projectUuid }: Coll
         const state = getState();
         const currentCollection = state.collectionPanel.item;
         if (currentCollection) {
-            const collection = await services.collectionService.get(currentCollection.uuid);
-            const collectionCopy = {
-                ...collection,
-                name,
-                description,
-                ownerUuid: projectUuid,
-                uuid: undefined
-            };
-            const newCollection = await services.collectionService.create(collectionCopy);
-            const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, false).map(file => file.id);
-            await services.collectionService.deleteFiles(newCollection.uuid, paths);
-            dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY }));
-            dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'New collection created.', hideDuration: 2000 }));
+            try {
+                const collection = await services.collectionService.get(currentCollection.uuid);
+                const collectionCopy = {
+                    ...collection,
+                    name,
+                    description,
+                    ownerUuid: projectUuid,
+                    uuid: undefined
+                };
+                const newCollection = await services.collectionService.create(collectionCopy);
+                const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, false).map(file => file.id);
+                await services.collectionService.deleteFiles(newCollection.uuid, paths);
+                dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY }));
+                dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'New collection created.', hideDuration: 2000 }));
+            } catch (e) {
+                if (getCommonResourceServiceError(e) === CommonResourceServiceError.UNIQUE_VIOLATION) {
+                    dispatch(stopSubmit(COLLECTION_PARTIAL_COPY, { name: 'Collection with this name already exists.' }));
+                }
+            }
         }
     };
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list