[ARVADOS-WORKBENCH2] created: 1.2.0-429-gb0aa1d7

Git user git at public.curoverse.com
Mon Sep 24 09:06:02 EDT 2018


        at  b0aa1d72fe826648a65a9f32bff67833ebaa4793 (commit)


commit b0aa1d72fe826648a65a9f32bff67833ebaa4793
Author: Janicki Artur <artur.janicki at contractors.roche.com>
Date:   Mon Sep 24 15:05:41 2018 +0200

    Switch the tagging adding properties) to use the collections API
    
    Feature #14043
    
    Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki at contractors.roche.com>

diff --git a/src/store/collection-panel/collection-panel-action.ts b/src/store/collection-panel/collection-panel-action.ts
index 97b6d49..5e99161 100644
--- a/src/store/collection-panel/collection-panel-action.ts
+++ b/src/store/collection-panel/collection-panel-action.ts
@@ -9,20 +9,14 @@ import { collectionPanelFilesAction } from "./collection-panel-files/collection-
 import { createTree } from "~/models/tree";
 import { RootState } from "../store";
 import { ServiceRepository } from "~/services/services";
-import { TagResource, TagProperty } from "~/models/tag";
+import { TagProperty } from "~/models/tag";
 import { snackbarActions } from "../snackbar/snackbar-actions";
 import { resourcesActions } from "~/store/resources/resources-actions";
 import { unionize, ofType, UnionOf } from '~/common/unionize';
 
 export const collectionPanelActions = unionize({
     LOAD_COLLECTION: ofType<{ uuid: string }>(),
-    LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>(),
-    LOAD_COLLECTION_TAGS: ofType<{ uuid: string }>(),
-    LOAD_COLLECTION_TAGS_SUCCESS: ofType<{ tags: TagResource[] }>(),
-    CREATE_COLLECTION_TAG: ofType<{ data: any }>(),
-    CREATE_COLLECTION_TAG_SUCCESS: ofType<{ tag: TagResource }>(),
-    DELETE_COLLECTION_TAG: ofType<{ uuid: string }>(),
-    DELETE_COLLECTION_TAG_SUCCESS: ofType<{ uuid: string }>()
+    LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>()
 });
 
 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
@@ -37,46 +31,41 @@ export const loadCollectionPanel = (uuid: string) =>
         dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection }));
         dispatch(resourcesActions.SET_RESOURCES([collection]));
         dispatch<any>(loadCollectionFiles(collection.uuid));
-        dispatch<any>(loadCollectionTags(collection.uuid));
         return collection;
     };
 
-export const loadCollectionTags = (uuid: string) =>
-    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        dispatch(collectionPanelActions.LOAD_COLLECTION_TAGS({ uuid }));
-        return services.tagService
-            .list(uuid)
-            .then(tags => {
-                dispatch(collectionPanelActions.LOAD_COLLECTION_TAGS_SUCCESS({ tags }));
-            });
-    };
-
-export const createCollectionTag = (data: TagProperty) =>
-    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        dispatch(collectionPanelActions.CREATE_COLLECTION_TAG({ data }));
+export const createCollectionTag = (data: TagProperty) => 
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const item = getState().collectionPanel.item;
         const uuid = item ? item.uuid : '';
-        return services.tagService
-            .create(uuid, data)
-            .then(tag => {
-                dispatch(collectionPanelActions.CREATE_COLLECTION_TAG_SUCCESS({ tag }));
-                dispatch(snackbarActions.OPEN_SNACKBAR({
-                    message: "Tag has been successfully added.",
-                    hideDuration: 2000
-                }));
-            });
+        try {
+            if (item) {
+                item.properties[data.key] = data.value;
+                const updatedCollection = await services.collectionService.update(uuid, item);
+                dispatch(resourcesActions.SET_RESOURCES([updatedCollection]));
+                dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Tag has been successfully added.", hideDuration: 2000 }));
+                return updatedCollection;
+            }
+            return;
+        } catch (e) {
+            return;
+        }
     };
 
-export const deleteCollectionTag = (uuid: string) =>
-    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        dispatch(collectionPanelActions.DELETE_COLLECTION_TAG({ uuid }));
-        return services.linkService
-            .delete(uuid)
-            .then(tag => {
-                dispatch(collectionPanelActions.DELETE_COLLECTION_TAG_SUCCESS({ uuid: tag.uuid }));
-                dispatch(snackbarActions.OPEN_SNACKBAR({
-                    message: "Tag has been successfully deleted.",
-                    hideDuration: 2000
-                }));
-            });
+export const deleteCollectionTag = (key: string) =>
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        const item = getState().collectionPanel.item;
+        const uuid = item ? item.uuid : '';
+        try {
+            if (item) {
+                delete item.properties[key];
+                const updatedCollection = await services.collectionService.update(uuid, item);
+                dispatch(resourcesActions.SET_RESOURCES([updatedCollection]));
+                dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Tag has been successfully deleted.", hideDuration: 2000 }));
+                return updatedCollection;
+            }
+            return;
+        } catch (e) {
+            return;
+        }
     };
diff --git a/src/store/collection-panel/collection-panel-reducer.ts b/src/store/collection-panel/collection-panel-reducer.ts
index 2c3edf1..b4951b8 100644
--- a/src/store/collection-panel/collection-panel-reducer.ts
+++ b/src/store/collection-panel/collection-panel-reducer.ts
@@ -4,23 +4,17 @@
 
 import { collectionPanelActions, CollectionPanelAction } from "./collection-panel-action";
 import { CollectionResource } from "~/models/collection";
-import { TagResource } from "~/models/tag";
 
 export interface CollectionPanelState {
     item: CollectionResource | null;
-    tags: TagResource[];
 }
 
 const initialState = {
-    item: null,
-    tags: []
+    item: null
 };
 
 export const collectionPanelReducer = (state: CollectionPanelState = initialState, action: CollectionPanelAction) =>
     collectionPanelActions.match(action, {
         default: () => state,
         LOAD_COLLECTION_SUCCESS: ({ item }) => ({ ...state, item }),
-        LOAD_COLLECTION_TAGS_SUCCESS: ({ tags }) => ({...state, tags }),
-        CREATE_COLLECTION_TAG_SUCCESS: ({ tag }) => ({...state, tags: [...state.tags, tag] }),
-        DELETE_COLLECTION_TAG_SUCCESS: ({ uuid }) => ({...state, tags: state.tags.filter(tag => tag.uuid !== uuid) })
     });
diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx
index 8e46385..b796abe 100644
--- a/src/views/collection-panel/collection-panel.tsx
+++ b/src/views/collection-panel/collection-panel.tsx
@@ -66,8 +66,7 @@ export const CollectionPanel = withStyles(styles)(
     connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
         const collection = getResource(props.match.params.id)(state.resources);
         return {
-            item: collection,
-            tags: state.collectionPanel.tags
+            item: collection
         };
     })(
         class extends React.Component<CollectionPanelProps> {
@@ -118,10 +117,10 @@ export const CollectionPanel = withStyles(styles)(
                                 <Grid item xs={12}><CollectionTagForm /></Grid>
                                 <Grid item xs={12}>
                                     {
-                                        tags.map(tag => {
-                                            return <Chip key={tag.etag} className={classes.tag}
-                                                onDelete={this.handleDelete(tag.uuid)}
-                                                label={renderTagLabel(tag)} />;
+                                        Object.keys(item.properties).map( key => {
+                                            return <Chip key={key} className={classes.tag}
+                                                onDelete={this.handleDelete(key)}
+                                                label={`${key}: ${item.properties[key]}`} />;
                                         })
                                     }
                                 </Grid>
@@ -147,8 +146,8 @@ export const CollectionPanel = withStyles(styles)(
                 this.props.dispatch<any>(openContextMenu(event, resource));
             }
 
-            handleDelete = (uuid: string) => () => {
-                this.props.dispatch<any>(deleteCollectionTag(uuid));
+            handleDelete = (key: string) => () => {
+                this.props.dispatch<any>(deleteCollectionTag(key));
             }
 
             onCopy = () => {
@@ -160,8 +159,3 @@ export const CollectionPanel = withStyles(styles)(
         }
     )
 );
-
-const renderTagLabel = (tag: TagResource) => {
-    const { properties } = tag;
-    return `${properties.key}: ${properties.value}`;
-};

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list