Create actions for resolving resource favorite status
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 23 Jul 2018 20:16:20 +0000 (22:16 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 23 Jul 2018 20:16:20 +0000 (22:16 +0200)
Feature #13784

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/store/favorites/favorites-actions.ts
src/store/project/project-action.ts
src/views/project-panel/project-panel.tsx

index 63ea2067f8a113c5a710855adcd05a9566195646..d7e14a2bfbc2f7898f8f7438122ca92dbcd480de 100644 (file)
@@ -3,9 +3,23 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { unionize, ofType, UnionOf } from "unionize";
+import { Dispatch } from "../../../node_modules/redux";
+import { favoriteService } from "../../services/services";
 
 export const favoritesActions = unionize({
+    CHECK_PRESENCE_IN_FAVORITES: ofType<string[]>(),
     UPDATE_FAVORITES: ofType<Record<string, boolean>>()
 }, { tag: 'type', value: 'payload' });
 
-export type FavoritesAction = UnionOf<typeof favoritesActions>;
\ No newline at end of file
+export type FavoritesAction = UnionOf<typeof favoritesActions>;
+
+export const checkPresenceInFavorites = (userUuid: string, resourceUuids: string[]) =>
+    (dispatch: Dispatch) => {
+        dispatch(favoritesActions.CHECK_PRESENCE_IN_FAVORITES(resourceUuids));
+        favoriteService
+            .checkPresenceInFavorites(userUuid, resourceUuids)
+            .then(results => {
+                dispatch(favoritesActions.UPDATE_FAVORITES(results));
+            });
+    };
+
index 2a7a5c126860253af5929695d05ef9020978e53a..dae245cf97c9fcf70e615b71c69afa24435dd538 100644 (file)
@@ -8,6 +8,7 @@ import { projectService } from "../../services/services";
 import { Dispatch } from "redux";
 import { FilterBuilder } from "../../common/api/filter-builder";
 import { RootState } from "../store";
+import { checkPresenceInFavorites } from "../favorites/favorites-actions";
 
 export const projectActions = unionize({
     OPEN_PROJECT_CREATOR: ofType<{ ownerUuid: string }>(),
@@ -26,7 +27,7 @@ export const projectActions = unionize({
         value: 'payload'
     });
 
-export const getProjectList = (parentUuid: string = '') => (dispatch: Dispatch) => {
+export const getProjectList = (parentUuid: string = '') => (dispatch: Dispatch, getState: () => RootState) => {
     dispatch(projectActions.PROJECTS_REQUEST(parentUuid));
     return projectService.list({
         filters: FilterBuilder
@@ -34,6 +35,8 @@ 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)));
         return projects;
     });
 };
index daf22b11faca3b02e87441a625cf50f513f84191..316a9ff674a7e6503931708e5b7b3062760ac315 100644 (file)
@@ -16,8 +16,9 @@ import { ContainerRequestState } from '../../models/container-request';
 import { SortDirection } from '../../components/data-table/data-column';
 import { ResourceKind } from '../../models/resource';
 import { resourceLabel } from '../../common/labels';
-import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon } from '../../components/icon/icon';
+import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon, FavoriteIcon } from '../../components/icon/icon';
 import { ArvadosTheme } from '../../common/custom-theme';
+import { FavoriteStar } from '../../views-components/favorite-star/favorite-star';
 
 type CssRules = "toolbar" | "button";
 
@@ -41,6 +42,11 @@ const renderName = (item: ProjectPanelItem) =>
                 {item.name}
             </Typography>
         </Grid>
+        <Grid item>
+            <Typography variant="caption" style={{fontSize: '8px'}}>
+                <FavoriteStar resourceUuid={item.uuid} />
+            </Typography>
+        </Grid>
     </Grid>;
 
 
@@ -184,7 +190,7 @@ interface ProjectPanelActionProps {
 }
 
 type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp
-                        & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
+    & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
 
 export const ProjectPanel = withStyles(styles)(
     connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(