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, FolderSharedIcon, Link, OpenIcon, 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 { copyToClipboardAction, 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 { openWebDavS3InfoDialog } from 'store/collections/collection-info-actions';
18 import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
20 export const MultiSelectMenuActionNames: Record<string, string> = {
21 ADD_TO_FAVORITES: 'Add to Favorites',
22 ADD_TO_TRASH: 'Add to Trash',
23 API_DETAILS: 'API Details',
24 COPY_AND_RERUN_PROCESS: 'Copy and re-run process',
25 COPY_TO_CLIPBOARD: 'Copy to clipboard',
26 DELETE_WORKFLOW: 'Delete Worflow',
27 EDIT_PPROJECT: 'Edit project',
28 FREEZE_PROJECT: 'Freeze Project',
29 MAKE_A_COPY: 'Make a copy',
31 NEW_PROJECT: 'New project',
32 OPEN_IN_NEW_TAB: 'Open in new tab',
33 OPEN_W_3RD_PARTY_CLIENT: 'Open with 3rd party client',
35 RUN_WORKFLOW: 'Run Workflow',
37 VIEW_DETAILS: 'View details',
40 export type MultiSelectMenuAction = {
47 useAlts?: (uuid: string, iconProps: {resources: ResourcesState, favorites: FavoritesState}) => boolean;
48 execute(dispatch: Dispatch, resources: ContextMenuResource[], state?: any): void;
52 export type MultiSelectMenuActionSet = MultiSelectMenuAction[][];
54 const { ADD_TO_FAVORITES, OPEN_IN_NEW_TAB, COPY_TO_CLIPBOARD, VIEW_DETAILS, API_DETAILS, OPEN_W_3RD_PARTY_CLIENT, SHARE } = MultiSelectMenuActionNames;
56 const msToggleFavoriteAction: MultiSelectMenuAction = {
57 name: ADD_TO_FAVORITES,
58 icon: AddFavoriteIcon,
60 altName: 'Remove from Favorites',
61 altIcon: RemoveFavoriteIcon,
63 useAlts: (uuid, iconProps) => {
64 return checkFavorite(uuid, iconProps.favorites);
66 execute: (dispatch, resources) => {
67 dispatch<any>(toggleFavorite(resources[0])).then(() => {
68 dispatch(favoritePanelActions.REQUEST_ITEMS());
73 const msOpenInNewTabMenuAction: MultiSelectMenuAction = {
74 name: OPEN_IN_NEW_TAB,
78 execute: (dispatch, resources) => {
79 dispatch<any>(openInNewTabAction(resources[0]));
83 const msCopyToClipboardMenuAction: MultiSelectMenuAction = {
84 name: COPY_TO_CLIPBOARD,
88 execute: (dispatch, resources) => {
89 dispatch<any>(copyToClipboardAction(resources));
93 const msViewDetailsAction: MultiSelectMenuAction = {
98 execute: (dispatch) => {
99 dispatch<any>(toggleDetailsPanel());
103 const msAdvancedAction: MultiSelectMenuAction = {
108 execute: (dispatch, resources) => {
109 dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
113 const msOpenWith3rdPartyClientAction: MultiSelectMenuAction = {
114 name: OPEN_W_3RD_PARTY_CLIENT,
115 icon: FolderSharedIcon,
118 execute: (dispatch, resources) => {
119 dispatch<any>(openWebDavS3InfoDialog(resources[0].uuid));
123 const msShareAction: MultiSelectMenuAction = {
128 execute: (dispatch, resources) => {
129 dispatch<any>(openSharingDialog(resources[0].uuid));
133 export const msCommonActionSet = [
134 msToggleFavoriteAction,
135 msOpenInNewTabMenuAction,
136 msCopyToClipboardMenuAction,
139 msOpenWith3rdPartyClientAction,