fix services after merge and improve onSubmit method for save collection
authorJanicki Artur <artur.janicki@contractors.roche.com>
Fri, 3 Aug 2018 06:27:23 +0000 (08:27 +0200)
committerJanicki Artur <artur.janicki@contractors.roche.com>
Fri, 3 Aug 2018 06:27:23 +0000 (08:27 +0200)
Feature #13903

Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki@contractors.roche.com>

src/store/collections/updator/collection-updator-action.ts
src/views-components/update-collection-dialog/update-collection-dialog..tsx

index ac422f07927c00f31f31b20dfc19304b13bef589..e12bfe548c01e69c874dc001c5533d398013a1b0 100644 (file)
@@ -6,7 +6,7 @@ import { default as unionize, ofType, UnionOf } from "unionize";
 import { Dispatch } from "redux";
 
 import { RootState } from "../../store";
-import { collectionService } from '../../../services/services';
+import { ServiceRepository } from "../../../services/services";
 import { CollectionResource } from '../../../models/collection';
 import { initialize } from 'redux-form';
 import { collectionPanelActions } from "../../collection-panel/collection-panel-action";
@@ -33,12 +33,12 @@ export const openUpdator = (uuid: string) =>
     };
 
 export const updateCollection = (collection: Partial<CollectionResource>) =>
-    (dispatch: Dispatch, getState: () => RootState) => {
+    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const { uuid } = getState().collections.updator;
-        return collectionService
+        return services.collectionService
             .update(uuid, collection)
             .then(collection => {
-                    dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection }));
+                    dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection as CollectionResource }));
                     dispatch(collectionUpdatorActions.UPDATE_COLLECTION_SUCCESS());
                 }
             );
index 8daff014a44fbfcbf5cdd3d14b73e43c2f75ec04..a91277e996d6fbdecac7617597f6f5c80df48dcc 100644 (file)
@@ -23,7 +23,9 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
     onSubmit: (data: { name: string, description: string }) => {
         return dispatch<any>(editCollection(data))
             .catch((e: any) => {
-                throw new SubmissionError({ name: e.errors.join("").includes("UniqueViolation") ? "Collection with this name already exists." : "" });
+                if(e.errors) {
+                    throw new SubmissionError({ name: e.errors.join("").includes("UniqueViolation") ? "Collection with this name already exists." : "" });
+                }
             });
     }
 });