1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from 'redux';
6 import { IconType } from 'components/icon/icon';
7 import { ResourcesState } from 'store/resources/resources';
8 import { FavoritesState } from 'store/favorites/favorites-reducer';
9 import { ContextMenuResource } from 'store/context-menu/context-menu-actions';
10 import { AddFavoriteIcon, AdvancedIcon, DetailsIcon, OpenIcon, PublicFavoriteIcon, RemoveFavoriteIcon, ShareIcon } from 'components/icon/icon';
11 import { checkFavorite } from 'store/favorites/favorites-reducer';
12 import { toggleFavorite } from 'store/favorites/favorites-actions';
13 import { favoritePanelActions } from 'store/favorite-panel/favorite-panel-action';
14 import { openInNewTabAction } from 'store/open-in-new-tab/open-in-new-tab.actions';
15 import { toggleDetailsPanel } from 'store/details-panel/details-panel-action';
16 import { openAdvancedTabDialog } from 'store/advanced-tab/advanced-tab';
17 import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
18 import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
19 import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
20 import { PublicFavoritesState } from 'store/public-favorites/public-favorites-reducer';
21 import { ContextMenuActionNames } from 'views-components/context-menu/context-menu-action-set';
23 export type MultiSelectMenuAction = {
30 useAlts?: (uuid: string | null, iconProps: {resources: ResourcesState, favorites: FavoritesState, publicFavorites: PublicFavoritesState}) => boolean;
31 execute(dispatch: Dispatch, resources: ContextMenuResource[], state?: any): void;
35 export type MultiSelectMenuActionSet = MultiSelectMenuAction[][];
37 const { ADD_TO_FAVORITES, ADD_TO_PUBLIC_FAVORITES, OPEN_IN_NEW_TAB, VIEW_DETAILS, API_DETAILS, SHARE } = ContextMenuActionNames;
39 const msToggleFavoriteAction: MultiSelectMenuAction = {
40 name: ADD_TO_FAVORITES,
41 icon: AddFavoriteIcon,
43 altName: 'Remove from Favorites',
44 altIcon: RemoveFavoriteIcon,
46 useAlts: (uuid: string, iconProps) => {
47 return checkFavorite(uuid, iconProps.favorites);
49 execute: (dispatch, resources) => {
50 dispatch<any>(toggleFavorite(resources[0])).then(() => {
51 dispatch(favoritePanelActions.REQUEST_ITEMS());
56 const msOpenInNewTabMenuAction: MultiSelectMenuAction = {
57 name: OPEN_IN_NEW_TAB,
61 execute: (dispatch, resources) => {
62 dispatch<any>(openInNewTabAction(resources[0]));
66 const msViewDetailsAction: MultiSelectMenuAction = {
71 execute: (dispatch) => {
72 dispatch<any>(toggleDetailsPanel());
76 const msAdvancedAction: MultiSelectMenuAction = {
81 execute: (dispatch, resources) => {
82 dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
86 const msShareAction: MultiSelectMenuAction = {
91 execute: (dispatch, resources) => {
92 dispatch<any>(openSharingDialog(resources[0].uuid));
96 const msTogglePublicFavoriteAction: MultiSelectMenuAction = {
97 name: ADD_TO_PUBLIC_FAVORITES,
98 icon: PublicFavoriteIcon,
100 altName: 'Remove from public favorites',
101 altIcon: PublicFavoriteIcon,
103 useAlts: (uuid: string, iconProps) => {
104 return iconProps.publicFavorites[uuid] === true
106 execute: (dispatch, resources) => {
107 dispatch<any>(togglePublicFavorite(resources[0])).then(() => {
108 dispatch(publicFavoritePanelActions.REQUEST_ITEMS());
113 export const msCommonActionSet = [
114 msToggleFavoriteAction,
115 msOpenInNewTabMenuAction,
119 msTogglePublicFavoriteAction