[ARVADOS-WORKBENCH2] updated: 1.1.4-366-g1c6bd6a

Git user git at public.curoverse.com
Mon Jul 23 18:12:49 EDT 2018


Summary of changes:
 src/store/favorites/favorites-actions.ts           | 23 ++++++++++++++++++++--
 src/store/favorites/favorites-reducer.ts           |  2 +-
 src/store/project/project-action.ts                |  3 +--
 .../context-menu/action-sets/project-action-set.ts |  5 ++++-
 4 files changed, 27 insertions(+), 6 deletions(-)

       via  1c6bd6afe7d0faf19f24a37a283e1d0e39de6b79 (commit)
      from  37870430486b96966f874bb507c2511d679f7721 (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 1c6bd6afe7d0faf19f24a37a283e1d0e39de6b79
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Tue Jul 24 00:12:35 2018 +0200

    Implement action for toggling favorite status
    
    Feature #13784
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/store/favorites/favorites-actions.ts b/src/store/favorites/favorites-actions.ts
index d7e14a2..ddb1492 100644
--- a/src/store/favorites/favorites-actions.ts
+++ b/src/store/favorites/favorites-actions.ts
@@ -5,16 +5,35 @@
 import { unionize, ofType, UnionOf } from "unionize";
 import { Dispatch } from "../../../node_modules/redux";
 import { favoriteService } from "../../services/services";
+import { RootState } from "../store";
+import { checkFavorite } from "./favorites-reducer";
 
 export const favoritesActions = unionize({
+    TOGGLE_FAVORITE: ofType<{ resourceUuid: string }>(),
     CHECK_PRESENCE_IN_FAVORITES: ofType<string[]>(),
     UPDATE_FAVORITES: ofType<Record<string, boolean>>()
 }, { tag: 'type', value: 'payload' });
 
 export type FavoritesAction = UnionOf<typeof favoritesActions>;
 
-export const checkPresenceInFavorites = (userUuid: string, resourceUuids: string[]) =>
-    (dispatch: Dispatch) => {
+export const toggleFavorite = (resourceUuid: string) =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const userUuid = getState().auth.user!.uuid;
+        dispatch(favoritesActions.TOGGLE_FAVORITE({ resourceUuid }));
+        const isFavorite = checkFavorite(resourceUuid, getState().favorites);
+        const promise = isFavorite
+            ? favoriteService.delete({ userUuid, resourceUuid })
+            : favoriteService.create({ userUuid, resourceUuid });
+
+        promise
+            .then(fav => {
+                dispatch(favoritesActions.UPDATE_FAVORITES({ [resourceUuid]: !isFavorite }));
+            });
+    };
+
+export const checkPresenceInFavorites = (resourceUuids: string[]) =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const userUuid = getState().auth.user!.uuid;
         dispatch(favoritesActions.CHECK_PRESENCE_IN_FAVORITES(resourceUuids));
         favoriteService
             .checkPresenceInFavorites(userUuid, resourceUuids)
diff --git a/src/store/favorites/favorites-reducer.ts b/src/store/favorites/favorites-reducer.ts
index 9599db0..e38ea95 100644
--- a/src/store/favorites/favorites-reducer.ts
+++ b/src/store/favorites/favorites-reducer.ts
@@ -12,4 +12,4 @@ export const favoritesReducer = (state: FavoritesState = {}, action: FavoritesAc
         default: () => state
     });
 
-export const isFavorite = (uuid: string, state: FavoritesState) => state[uuid] === true;
\ No newline at end of file
+export const checkFavorite = (uuid: string, state: FavoritesState) => state[uuid] === true;
\ No newline at end of file
diff --git a/src/store/project/project-action.ts b/src/store/project/project-action.ts
index dae245c..77223e9 100644
--- a/src/store/project/project-action.ts
+++ b/src/store/project/project-action.ts
@@ -35,8 +35,7 @@ export const getProjectList = (parentUuid: string = '') => (dispatch: Dispatch,
             .addEqual("ownerUuid", parentUuid)
     }).then(({ items: projects }) => {
         dispatch(projectActions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
-        const { user } = getState().auth;
-        dispatch<any>(checkPresenceInFavorites(user ? user.uuid : "", projects.map(project => project.uuid)));
+        dispatch<any>(checkPresenceInFavorites(projects.map(project => project.uuid)));
         return projects;
     });
 };
diff --git a/src/views-components/context-menu/action-sets/project-action-set.ts b/src/views-components/context-menu/action-sets/project-action-set.ts
index 2b33649..e0284e8 100644
--- a/src/views-components/context-menu/action-sets/project-action-set.ts
+++ b/src/views-components/context-menu/action-sets/project-action-set.ts
@@ -6,6 +6,7 @@ import { ContextMenuActionSet } from "../context-menu-action-set";
 import { projectActions } from "../../../store/project/project-action";
 import { ShareIcon, NewProjectIcon } from "../../../components/icon/icon";
 import { FavoriteActionText, FavoriteActionIcon } from "./favorite-action";
+import { favoritesActions, toggleFavorite } from "../../../store/favorites/favorites-actions";
 
 export const projectActionSet: ContextMenuActionSet = [[{
     icon: NewProjectIcon,
@@ -16,5 +17,7 @@ export const projectActionSet: ContextMenuActionSet = [[{
 }, {
     name: FavoriteActionText,
     icon: FavoriteActionIcon,
-    execute: (dispatch, resource) => { alert(resource); }
+    execute: (dispatch, resource) => {
+        dispatch<any>(toggleFavorite(resource.uuid));
+    }
 }]];

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list