From 9456a165e6ebdbf1ead5847a619a8f9acdf1932f Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Wed, 3 Apr 2019 11:00:35 +0200 Subject: [PATCH] context-menus-in-public-favorite-panel Feature #14941 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- .../public-favorites/public-favorites-actions.ts | 14 ++++++++++++++ .../public-favorites-panel.tsx | 14 ++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/store/public-favorites/public-favorites-actions.ts b/src/store/public-favorites/public-favorites-actions.ts index ae6815b61e..b5aa9fcef7 100644 --- a/src/store/public-favorites/public-favorites-actions.ts +++ b/src/store/public-favorites/public-favorites-actions.ts @@ -9,6 +9,8 @@ import { checkPublicFavorite } from "./public-favorites-reducer"; import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions"; import { ServiceRepository } from "~/services/services"; import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions"; +import { getResource } from '~/store/resources/resources'; +import { LinkResource } from "~/models/link"; export const publicFavoritesActions = unionize({ TOGGLE_PUBLIC_FAVORITE: ofType<{ resourceUuid: string }>(), @@ -66,3 +68,15 @@ export const updatePublicFavorites = (resourceUuids: string[]) => dispatch(publicFavoritesActions.UPDATE_PUBLIC_FAVORITES(results)); }); }; + +export const getHeadUuid = (uuid: string) => + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const resource = getResource(uuid)(getState().resources); + return resource!.headUuid; + }; + +export const getIsAdmin = () => + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const resource = getState().auth.user!.isAdmin; + return resource; + }; diff --git a/src/views/public-favorites-panel/public-favorites-panel.tsx b/src/views/public-favorites-panel/public-favorites-panel.tsx index 3970418f48..7af4edc773 100644 --- a/src/views/public-favorites-panel/public-favorites-panel.tsx +++ b/src/views/public-favorites-panel/public-favorites-panel.tsx @@ -31,6 +31,7 @@ import { createTree } from '~/models/tree'; import { getSimpleObjectTypeFilters } from '~/store/resource-type-filters/resource-type-filters'; import { PUBLIC_FAVORITE_PANEL_ID } from '~/store/public-favorites-panel/public-favorites-action'; import { PublicFavoritesState } from '~/store/public-favorites/public-favorites-reducer'; +import { getHeadUuid, getIsAdmin } from '~/store/public-favorites/public-favorites-actions'; type CssRules = "toolbar" | "button"; @@ -113,24 +114,25 @@ const mapStateToProps = ({ publicFavorites }: RootState): PublicFavoritePanelDat const mapDispatchToProps = (dispatch: Dispatch): PublicFavoritePanelActionProps => ({ onContextMenu: (event, resourceUuid) => { - const kind = resourceKindToContextMenuKind(resourceUuid); + const isAdmin = dispatch(getIsAdmin()); + const kind = resourceKindToContextMenuKind(dispatch(getHeadUuid(resourceUuid)), isAdmin); if (kind) { dispatch(openContextMenu(event, { name: '', - uuid: resourceUuid, + uuid: dispatch(getHeadUuid(resourceUuid)), ownerUuid: '', kind: ResourceKind.NONE, menuKind: kind })); } - dispatch(loadDetailsPanel(resourceUuid)); + dispatch(loadDetailsPanel(dispatch(getHeadUuid(resourceUuid)))); }, onDialogOpen: (ownerUuid: string) => { return; }, - onItemClick: (resourceUuid: string) => { - dispatch(loadDetailsPanel(resourceUuid)); + onItemClick: (uuid: string) => { + dispatch(loadDetailsPanel(dispatch(getHeadUuid(uuid)))); }, onItemDoubleClick: uuid => { - dispatch(navigateTo(uuid)); + dispatch(navigateTo(dispatch(getHeadUuid(uuid)))); } }); -- 2.30.2