init and save form, modify store
authorJanicki Artur <artur.janicki@contractors.roche.com>
Thu, 2 Aug 2018 11:03:34 +0000 (13:03 +0200)
committerJanicki Artur <artur.janicki@contractors.roche.com>
Thu, 2 Aug 2018 11:03:34 +0000 (13:03 +0200)
Feature #13903

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

src/common/api/common-resource-service.ts
src/store/collection-panel/collection-panel-action.ts
src/store/collections/updator/collection-updator-action.ts
src/store/collections/updator/collection-updator-reducer.ts
src/views-components/context-menu/action-sets/collection-action-set.ts
src/views-components/dialog-update/dialog-collection-update.tsx
src/views/collection-panel/collection-panel.tsx

index 3956fb7390983824a402456abc2144850b85cda2..8ad8fe916ee48e7ef7cf373c105530a224b1c1a2 100644 (file)
@@ -100,8 +100,11 @@ export class CommonResourceService<T extends Resource> {
                 }));
     }
 
-    update(uuid: string) {
-        throw new Error("Not implemented");
+    update(uuid: string, data: any) {
+        return CommonResourceService.defaultResponse(
+            this.serverApi
+                .put<T>(this.resourceType + uuid, data));
+        
     }
 }
 
index 946836a5a756adbf53ab754671893aa4ffed3e9c..c0d3366eaee8fb65d49c73ffcb46510a94c9ee8f 100644 (file)
@@ -21,7 +21,7 @@ export const loadCollection = (uuid: string, kind: ResourceKind) =>
         return collectionService
             .get(uuid)
             .then(item => {
-                dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: item as CollectionResource }));
+                dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item }));
             });
     };
 
index 5272baa8df612f364f63948406a55ce0fec56d86..ac422f07927c00f31f31b20dfc19304b13bef589 100644 (file)
@@ -8,26 +8,40 @@ import { Dispatch } from "redux";
 import { RootState } from "../../store";
 import { collectionService } from '../../../services/services';
 import { CollectionResource } from '../../../models/collection';
+import { initialize } from 'redux-form';
+import { collectionPanelActions } from "../../collection-panel/collection-panel-action";
 
 export const collectionUpdatorActions = unionize({
-    OPEN_COLLECTION_UPDATOR: ofType<{ ownerUuid: string }>(),
+    OPEN_COLLECTION_UPDATOR: ofType<{ uuid: string }>(),
     CLOSE_COLLECTION_UPDATOR: ofType<{}>(),
-    UPDATE_COLLECTION: ofType<{}>(),
     UPDATE_COLLECTION_SUCCESS: ofType<{}>(),
 }, {
         tag: 'type',
         value: 'payload'
     });
 
+
+export const COLLECTION_FORM_NAME = 'collectionEditDialog';
+    
+export const openUpdator = (uuid: string) =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        dispatch(collectionUpdatorActions.OPEN_COLLECTION_UPDATOR({ uuid }));
+        const item = getState().collectionPanel.item;
+        if(item) {
+            dispatch(initialize(COLLECTION_FORM_NAME, { name: item.name, description: item.description }));
+        }
+    };
+
 export const updateCollection = (collection: Partial<CollectionResource>) =>
     (dispatch: Dispatch, getState: () => RootState) => {
-        const { ownerUuid } = getState().collections.creator;
-        const collectiontData = { ownerUuid, ...collection };
-        dispatch(collectionUpdatorActions.UPDATE_COLLECTION(collectiontData));
+        const { uuid } = getState().collections.updator;
         return collectionService
-            // change for update
-            .create(collectiontData)
-            .then(collection => dispatch(collectionUpdatorActions.UPDATE_COLLECTION_SUCCESS(collection)));
+            .update(uuid, collection)
+            .then(collection => {
+                    dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection }));
+                    dispatch(collectionUpdatorActions.UPDATE_COLLECTION_SUCCESS());
+                }
+            );
     };
 
 export type CollectionUpdatorAction = UnionOf<typeof collectionUpdatorActions>;
\ No newline at end of file
index f47f19601ff8d853014b169893684ef6418facd3..b9d0250c490e86aa3f9b3ba730b02cd34f44fb48 100644 (file)
@@ -8,7 +8,7 @@ export type CollectionUpdatorState = CollectionUpdator;
 
 interface CollectionUpdator {
     opened: boolean;
-    ownerUuid: string;
+    uuid: string;
 }
 
 const updateCollection = (state: CollectionUpdatorState, updator?: Partial<CollectionUpdator>) => ({
@@ -18,15 +18,14 @@ const updateCollection = (state: CollectionUpdatorState, updator?: Partial<Colle
 
 const initialState: CollectionUpdatorState = {
     opened: false,
-    ownerUuid: ''
+    uuid: ''
 };
 
 export const collectionCreationReducer = (state: CollectionUpdatorState = initialState, action: CollectionUpdatorAction) => {
     return collectionUpdatorActions.match(action, {
-        OPEN_COLLECTION_UPDATOR: ({ ownerUuid }) => updateCollection(state, { ownerUuid, opened: true }),
+        OPEN_COLLECTION_UPDATOR: ({ uuid }) => updateCollection(state, { uuid, opened: true }),
         CLOSE_COLLECTION_UPDATOR: () => updateCollection(state, { opened: false }),
-        UPDATE_COLLECTION: () => updateCollection(state),
-        UPDATE_COLLECTION_SUCCESS: () => updateCollection(state, { opened: false, ownerUuid: "" }),
+        UPDATE_COLLECTION_SUCCESS: () => updateCollection(state, { opened: false, uuid: "" }),
         default: () => state
     });
 };
index 7f9cbc1378768e3d098f4280303fa951a53978ef..9e3ff348245d2704bc4502cbee5425cc3069ab0d 100644 (file)
@@ -8,14 +8,14 @@ import { toggleFavorite } from "../../../store/favorites/favorites-actions";
 import { dataExplorerActions } from "../../../store/data-explorer/data-explorer-action";
 import { FAVORITE_PANEL_ID } from "../../../views/favorite-panel/favorite-panel";
 import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, ProvenanceGraphIcon, AdvancedIcon, RemoveIcon } from "../../../components/icon/icon";
-import { collectionUpdatorActions } from "../../../store/collections/updator/collection-updator-action";
+import { openUpdator } from "../../../store/collections/updator/collection-updator-action";
 
 export const collectionActionSet: ContextMenuActionSet = [[
     {
         icon: RenameIcon,
         name: "Edit collection",
         execute: (dispatch, resource) => {
-            dispatch(collectionUpdatorActions.OPEN_COLLECTION_UPDATOR({ ownerUuid: resource.uuid }));
+            dispatch<any>(openUpdator(resource.uuid));
         }
     },
     {
index 30a3256d7e5343f992d3fe5d1872f84dca85858a..80a82b27fd97bb27a65dd954603e1cb7c2a965d8 100644 (file)
@@ -8,6 +8,7 @@ import { compose } from 'redux';
 import { ArvadosTheme } from '../../common/custom-theme';
 import { Dialog, DialogActions, DialogContent, DialogTitle, TextField, StyleRulesCallback, withStyles, WithStyles, Button, CircularProgress } from '../../../node_modules/@material-ui/core';
 import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION } from '../../validators/create-project/create-project-validator';
+import { COLLECTION_FORM_NAME } from '../../store/collections/updator/collection-updator-action';
 
 type CssRules = 'content' | 'actions' | 'textField' | 'buttonWrapper' | 'saveButton' | 'circularProgress';
 
@@ -64,7 +65,7 @@ interface TextFieldProps {
 }
 
 export const DialogCollectionUpdate = compose(
-    reduxForm({ form: 'collectionEditDialog' }),
+    reduxForm({ form: COLLECTION_FORM_NAME }),
     withStyles(styles))(
 
         class DialogCollectionUpdate extends React.Component<DialogCollectionProps> {
index 71ec309f7b0b3f8fa2e134b79c8910fd60883dbf..340d7c9cf5bad431023b63fe20fcc92683ec9d1d 100644 (file)
@@ -59,13 +59,12 @@ export const CollectionPanel = withStyles(styles)(
                                         <MoreOptionsIcon />
                                     </IconButton> 
                                 }
-                                title={item && item.name } />
+                                title={item && item.name } 
+                                subheader={item && item.description} />
                             <CardContent>
                                 <Grid container direction="column">
                                     <Grid item xs={6}>
-                                    <DetailsAttribute label='Collection UUID' value={item && item.uuid}>
-                                        Here I will add copy
-                                    </DetailsAttribute>
+                                    <DetailsAttribute label='Collection UUID' value={item && item.uuid} />
                                     <DetailsAttribute label='Content size' value='54 MB' />
                                     <DetailsAttribute label='Owner' value={item && item.ownerUuid} />
                                     </Grid>