22207: added copy uuid to context menus
[arvados.git] / services / workbench2 / src / views-components / context-menu / action-sets / process-resource-action-set.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ContextMenuActionSet, ContextMenuActionNames } from "../context-menu-action-set";
6 import { ToggleFavoriteAction } from "../actions/favorite-action";
7 import { toggleFavorite } from "store/favorites/favorites-actions";
8 import {
9     RenameIcon,
10     DetailsIcon,
11     RemoveIcon,
12     ReRunProcessIcon,
13     OutputIcon,
14     AdvancedIcon,
15     OpenIcon,
16     StopIcon,
17     Link,
18 } from "components/icon/icon";
19 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
20 import { openProcessUpdateDialog } from "store/processes/process-update-actions";
21 import { openCopyProcessDialog } from "store/processes/process-copy-actions";
22 import { openRemoveProcessDialog } from "store/processes/processes-actions";
23 import { openDetailsPanel } from "store/details-panel/details-panel-action";
24 import { navigateToOutput } from "store/process-panel/process-panel-actions";
25 import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
26 import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
27 import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
28 import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
29 import { openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
30 import { cancelRunningWorkflow } from "store/processes/processes-actions";
31 import { copyStringToClipboardAction } from "store/open-in-new-tab/open-in-new-tab.actions";
32
33 export const readOnlyProcessResourceActionSet: ContextMenuActionSet = [
34     [
35         {
36             component: ToggleFavoriteAction,
37             name: ContextMenuActionNames.ADD_TO_FAVORITES,
38             execute: (dispatch, resources) => {
39                 dispatch<any>(toggleFavorite(resources[0])).then(() => {
40                     dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
41                 });
42             },
43         },
44         {
45             icon: OpenIcon,
46             name: ContextMenuActionNames.OPEN_IN_NEW_TAB,
47             execute: (dispatch, resources) => {
48                 dispatch<any>(openInNewTabAction(resources[0]));
49             },
50         },
51         {
52             icon: ReRunProcessIcon,
53             name: ContextMenuActionNames.COPY_AND_RERUN_PROCESS,
54             execute: (dispatch, resources) => {
55                 dispatch<any>(openCopyProcessDialog(resources[0]));
56             },
57         },
58         {
59             icon: OutputIcon,
60             name: ContextMenuActionNames.OUTPUTS,
61             execute: (dispatch, resources) => {
62                 if (resources[0]) {
63                     dispatch<any>(navigateToOutput(resources[0]));
64                 }
65             },
66         },
67         {
68             icon: DetailsIcon,
69             name: ContextMenuActionNames.VIEW_DETAILS,
70             execute: (dispatch, resources) => {
71                 dispatch<any>(openDetailsPanel(resources[0].uuid));
72             },
73         },
74         {
75             icon: AdvancedIcon,
76             name: ContextMenuActionNames.API_DETAILS,
77             execute: (dispatch, resources) => {
78                 dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
79             },
80         },
81         {
82             icon: Link,
83             name: ContextMenuActionNames.COPY_UUID,
84             execute: (dispatch, resources) => {
85                 dispatch<any>(copyStringToClipboardAction(resources[0].uuid));
86             },
87         },
88     ],
89 ];
90
91 export const processResourceActionSet: ContextMenuActionSet = [
92     [
93         ...readOnlyProcessResourceActionSet.reduce((prev, next) => prev.concat(next), []),
94         {
95             icon: RenameIcon,
96             name: ContextMenuActionNames.EDIT_PROCESS,
97             execute: (dispatch, resources) => {
98                 dispatch<any>(openProcessUpdateDialog(resources[0]));
99             },
100         },
101         // removed until auto-move children is implemented
102         // {
103         //     icon: MoveToIcon,
104         //     name: ContextMenuActionNames.MOVE_TO,
105         //     execute: (dispatch, resources) => {
106         //         dispatch<any>(openMoveProcessDialog(resources[0]));
107         //     },
108         // },
109         {
110             name: ContextMenuActionNames.REMOVE,
111             icon: RemoveIcon,
112             execute: (dispatch, resources) => {
113                 dispatch<any>(openRemoveProcessDialog(resources[0], resources.length));
114             },
115         },
116     ],
117 ];
118
119 const runningProcessOnlyActionSet: ContextMenuActionSet = [
120     [
121         {
122             name: ContextMenuActionNames.CANCEL,
123             icon: StopIcon,
124             execute: (dispatch, resources) => {
125                 dispatch<any>(cancelRunningWorkflow(resources[0].uuid));
126             },
127         },
128     ]
129 ];
130
131 export const processResourceAdminActionSet: ContextMenuActionSet = [
132     [
133         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
134         {
135             component: TogglePublicFavoriteAction,
136             name: ContextMenuActionNames.ADD_TO_PUBLIC_FAVORITES,
137             execute: (dispatch, resources) => {
138                 dispatch<any>(togglePublicFavorite(resources[0])).then(() => {
139                     dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
140                 });
141             },
142         },
143     ],
144 ];
145
146 export const runningProcessResourceActionSet = [
147     [
148         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
149         ...runningProcessOnlyActionSet.reduce((prev, next) => prev.concat(next), []),
150     ],
151 ];
152
153 export const runningProcessResourceAdminActionSet: ContextMenuActionSet = [
154     [
155         ...processResourceAdminActionSet.reduce((prev, next) => prev.concat(next), []),
156         ...runningProcessOnlyActionSet.reduce((prev, next) => prev.concat(next), []),
157     ],
158 ];