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 } 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 { openDetailsPanel } from 'store/details-panel/details-panel-action';
16 import { openAdvancedTabDialog } from 'store/advanced-tab/advanced-tab';
17 import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
18 import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
19 import { PublicFavoritesState } from 'store/public-favorites/public-favorites-reducer';
20 import { ContextMenuActionNames } from 'views-components/context-menu/context-menu-action-set';
22 export type MultiSelectMenuAction = {
29 useAlts?: (uuid: string | null, iconProps: {resources: ResourcesState, favorites: FavoritesState, publicFavorites: PublicFavoritesState}) => boolean;
30 execute(dispatch: Dispatch, resources: ContextMenuResource[], state?: any): void;
34 export type MultiSelectMenuActionSet = MultiSelectMenuAction[][];
36 const { ADD_TO_FAVORITES, ADD_TO_PUBLIC_FAVORITES, OPEN_IN_NEW_TAB, VIEW_DETAILS, API_DETAILS } = ContextMenuActionNames;
38 const msToggleFavoriteAction: MultiSelectMenuAction = {
39 name: ADD_TO_FAVORITES,
40 icon: AddFavoriteIcon,
42 altName: 'Remove from Favorites',
43 altIcon: RemoveFavoriteIcon,
45 useAlts: (uuid: string, iconProps) => {
46 return checkFavorite(uuid, iconProps.favorites);
48 execute: (dispatch, resources) => {
49 dispatch<any>(toggleFavorite(resources[0])).then(() => {
50 dispatch(favoritePanelActions.REQUEST_ITEMS());
55 const msOpenInNewTabMenuAction: MultiSelectMenuAction = {
56 name: OPEN_IN_NEW_TAB,
60 execute: (dispatch, resources) => {
61 dispatch<any>(openInNewTabAction(resources[0]));
65 const msViewDetailsAction: MultiSelectMenuAction = {
70 execute: (dispatch, resources) => {
71 dispatch<any>(openDetailsPanel(resources[0].uuid));
75 const msAdvancedAction: MultiSelectMenuAction = {
80 execute: (dispatch, resources) => {
81 dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
85 const msTogglePublicFavoriteAction: MultiSelectMenuAction = {
86 name: ADD_TO_PUBLIC_FAVORITES,
87 icon: PublicFavoriteIcon,
89 altName: 'Remove from public favorites',
90 altIcon: PublicFavoriteIcon,
92 useAlts: (uuid: string, iconProps) => {
93 return iconProps.publicFavorites[uuid] === true
95 execute: (dispatch, resources) => {
96 dispatch<any>(togglePublicFavorite(resources[0])).then(() => {
97 dispatch(publicFavoritePanelActions.REQUEST_ITEMS());
102 export const msCommonActionSet = [
103 msToggleFavoriteAction,
104 msOpenInNewTabMenuAction,
107 msTogglePublicFavoriteAction