[ARVADOS-WORKBENCH2] created: 1.1.4-360-g28ded6a

Git user git at public.curoverse.com
Mon Jul 23 15:20:17 EDT 2018


        at  28ded6ac60c1317b5872a22ce827b073f26fa030 (commit)


commit 28ded6ac60c1317b5872a22ce827b073f26fa030
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Mon Jul 23 21:20:09 2018 +0200

    Add method for checking if resource is present in favorites
    
    Feature #13784
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/services/favorite-service/favorite-service.test.ts b/src/services/favorite-service/favorite-service.test.ts
index 7e74b52..58c3bf4 100644
--- a/src/services/favorite-service/favorite-service.test.ts
+++ b/src/services/favorite-service/favorite-service.test.ts
@@ -74,4 +74,20 @@ describe("FavoriteService", () => {
         expect(favorites).toEqual({ items: [{ uuid: "resourceUuid" }] });
     });
 
+    it("checks if resources are present in favorites", async () => {
+        const list = jest.fn().mockReturnValue(Promise.resolve({ items: [{ headUuid: "foo" }] }));
+        const listFilters = FilterBuilder
+            .create<LinkResource>()
+            .addIn("headUuid", ["foo", "oof"])
+            .addEqual("tailUuid", "userUuid")
+            .addEqual("linkClass", LinkClass.STAR);
+        linkService.list = list;
+        const favoriteService = new FavoriteService(linkService, groupService);
+
+        const favorites = await favoriteService.checkPresenceInFavorites("userUuid", ["foo", "oof"]);
+
+        expect(list.mock.calls[0][0].filters.getFilters()).toEqual(listFilters.getFilters());
+        expect(favorites).toEqual({ foo: true, oof: false });
+    });
+
 });
diff --git a/src/services/favorite-service/favorite-service.ts b/src/services/favorite-service/favorite-service.ts
index d075b79..f211a38 100644
--- a/src/services/favorite-service/favorite-service.ts
+++ b/src/services/favorite-service/favorite-service.ts
@@ -64,5 +64,20 @@ export class FavoriteService {
             });
     }
 
+    checkPresenceInFavorites(userUuid: string, resourceUuids: string[]): Promise<Record<string, boolean>> {
+        return this.linkService
+            .list({
+                filters: FilterBuilder
+                    .create<LinkResource>()
+                    .addIn("headUuid", resourceUuids)
+                    .addEqual("tailUuid", userUuid)
+                    .addEqual("linkClass", LinkClass.STAR)
+            })
+            .then(({items}) => resourceUuids.reduce((results, uuid) => {
+                const isFavorite = items.some(item => item.headUuid === uuid);
+                return {...results, [uuid]: isFavorite};
+            }, {}));
+    }
+
 
 }
\ No newline at end of file

commit 45169570ad44e6d2a2fa37be4d1796d66fd6697e
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Mon Jul 23 18:26:30 2018 +0200

    Create actions and reducer for favorites
    
    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
new file mode 100644
index 0000000..63ea206
--- /dev/null
+++ b/src/store/favorites/favorites-actions.ts
@@ -0,0 +1,11 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { unionize, ofType, UnionOf } from "unionize";
+
+export const favoritesActions = unionize({
+    UPDATE_FAVORITES: ofType<Record<string, boolean>>()
+}, { tag: 'type', value: 'payload' });
+
+export type FavoritesAction = UnionOf<typeof favoritesActions>;
\ No newline at end of file
diff --git a/src/store/favorites/favorites-reducer.ts b/src/store/favorites/favorites-reducer.ts
new file mode 100644
index 0000000..9599db0
--- /dev/null
+++ b/src/store/favorites/favorites-reducer.ts
@@ -0,0 +1,15 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { FavoritesAction, favoritesActions } from "./favorites-actions";
+
+export type FavoritesState = Record<string, boolean>;
+
+export const favoritesReducer = (state: FavoritesState = {}, action: FavoritesAction) => 
+    favoritesActions.match(action, {
+        UPDATE_FAVORITES: favorites => ({...state, ...favorites}),
+        default: () => state
+    });
+
+export const isFavorite = (uuid: string, state: FavoritesState) => state[uuid] === true;
\ No newline at end of file
diff --git a/src/store/store.ts b/src/store/store.ts
index adb7ddd..e7dbe16 100644
--- a/src/store/store.ts
+++ b/src/store/store.ts
@@ -14,6 +14,7 @@ import { dataExplorerReducer, DataExplorerState } from './data-explorer/data-exp
 import { projectPanelMiddleware } from './project-panel/project-panel-middleware';
 import { detailsPanelReducer, DetailsPanelState } from './details-panel/details-panel-reducer';
 import { contextMenuReducer, ContextMenuState } from './context-menu/context-menu-reducer';
+import { FavoritesState, favoritesReducer } from './favorites/favorites-reducer';
 
 const composeEnhancers =
     (process.env.NODE_ENV === 'development' &&
@@ -28,6 +29,7 @@ export interface RootState {
     sidePanel: SidePanelState;
     detailsPanel: DetailsPanelState;
     contextMenu: ContextMenuState;
+    favorites: FavoritesState;
 }
 
 const rootReducer = combineReducers({
@@ -37,7 +39,8 @@ const rootReducer = combineReducers({
     dataExplorer: dataExplorerReducer,
     sidePanel: sidePanelReducer,
     detailsPanel: detailsPanelReducer,
-    contextMenu: contextMenuReducer
+    contextMenu: contextMenuReducer,
+    favorites: favoritesReducer,
 });
 
 

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list