20382: cancel in context menu works for non-admins Arvados-DCO-1.1-Signed-off-by...
[arvados-workbench2.git] / 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 } 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     ShareIcon,
11     MoveToIcon,
12     DetailsIcon,
13     RemoveIcon,
14     ReRunProcessIcon,
15     OutputIcon,
16     AdvancedIcon,
17     OpenIcon,
18     StopIcon,
19 } from "components/icon/icon";
20 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
21 import { openMoveProcessDialog } from "store/processes/process-move-actions";
22 import { openProcessUpdateDialog } from "store/processes/process-update-actions";
23 import { openCopyProcessDialog } from "store/processes/process-copy-actions";
24 import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
25 import { openRemoveProcessDialog } from "store/processes/processes-actions";
26 import { toggleDetailsPanel } from "store/details-panel/details-panel-action";
27 import { navigateToOutput } from "store/process-panel/process-panel-actions";
28 import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
29 import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
30 import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
31 import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
32 import { openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
33 import { cancelRunningWorkflow } from "store/processes/processes-actions";
34
35 export const readOnlyProcessResourceActionSet: ContextMenuActionSet = [
36     [
37         {
38             component: ToggleFavoriteAction,
39             execute: (dispatch, resource) => {
40                 dispatch<any>(toggleFavorite(resource)).then(() => {
41                     dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
42                 });
43             },
44         },
45         {
46             icon: OpenIcon,
47             name: "Open in new tab",
48             execute: (dispatch, resource) => {
49                 dispatch<any>(openInNewTabAction(resource));
50             },
51         },
52         {
53             icon: ReRunProcessIcon,
54             name: "Copy and re-run process",
55             execute: (dispatch, resource) => {
56                 dispatch<any>(openCopyProcessDialog(resource));
57             },
58         },
59         {
60             icon: OutputIcon,
61             name: "Outputs",
62             execute: (dispatch, resource) => {
63                 if (resource.outputUuid) {
64                     dispatch<any>(navigateToOutput(resource.outputUuid));
65                 }
66             },
67         },
68         {
69             icon: DetailsIcon,
70             name: "View details",
71             execute: dispatch => {
72                 dispatch<any>(toggleDetailsPanel());
73             },
74         },
75         {
76             icon: AdvancedIcon,
77             name: "API Details",
78             execute: (dispatch, resource) => {
79                 dispatch<any>(openAdvancedTabDialog(resource.uuid));
80             },
81         },
82     ],
83 ];
84
85 export const processResourceActionSet: ContextMenuActionSet = [
86     [
87         ...readOnlyProcessResourceActionSet.reduce((prev, next) => prev.concat(next), []),
88         {
89             icon: RenameIcon,
90             name: "Edit process",
91             execute: (dispatch, resource) => {
92                 dispatch<any>(openProcessUpdateDialog(resource));
93             },
94         },
95         {
96             icon: ShareIcon,
97             name: "Share",
98             execute: (dispatch, { uuid }) => {
99                 dispatch<any>(openSharingDialog(uuid));
100             },
101         },
102         {
103             icon: MoveToIcon,
104             name: "Move to",
105             execute: (dispatch, resource) => {
106                 dispatch<any>(openMoveProcessDialog(resource));
107             },
108         },
109         {
110             name: "Remove",
111             icon: RemoveIcon,
112             execute: (dispatch, resource) => {
113                 dispatch<any>(openRemoveProcessDialog(resource.uuid));
114             },
115         },
116         // {
117         //     name: "Cancel",
118         //     icon: StopIcon,
119         //     execute: (dispatch, resource) => {
120         //         dispatch<any>(cancelRunningWorkflow(resource.uuid));
121         //     },
122         // },
123     ],
124 ];
125
126 export const runningProcessResourceActionSet = [
127     [
128         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
129         {
130             name: "Cancel",
131             icon: StopIcon,
132             execute: (dispatch, resource) => {
133                 dispatch(cancelRunningWorkflow(resource.uuid));
134             },
135         },
136     ],
137 ];
138
139 export const processResourceAdminActionSet: ContextMenuActionSet = [
140     [
141         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
142         {
143             component: TogglePublicFavoriteAction,
144             name: "Add to public favorites",
145             execute: (dispatch, resource) => {
146                 dispatch<any>(togglePublicFavorite(resource)).then(() => {
147                     dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
148                 });
149             },
150         },
151     ],
152 ];