Merge branch '21705-go-deps-update-all'
[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 } from "components/icon/icon";
18 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
19 import { openProcessUpdateDialog } from "store/processes/process-update-actions";
20 import { openCopyProcessDialog } from "store/processes/process-copy-actions";
21 import { openRemoveProcessDialog } from "store/processes/processes-actions";
22 import { toggleDetailsPanel } from "store/details-panel/details-panel-action";
23 import { navigateToOutput } from "store/process-panel/process-panel-actions";
24 import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
25 import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
26 import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
27 import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
28 import { openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
29 import { cancelRunningWorkflow } from "store/processes/processes-actions";
30
31 export const readOnlyProcessResourceActionSet: ContextMenuActionSet = [
32     [
33         {
34             component: ToggleFavoriteAction,
35             name: ContextMenuActionNames.ADD_TO_FAVORITES,
36             execute: (dispatch, resources) => {
37                 dispatch<any>(toggleFavorite(resources[0])).then(() => {
38                     dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
39                 });
40             },
41         },
42         {
43             icon: OpenIcon,
44             name: ContextMenuActionNames.OPEN_IN_NEW_TAB,
45             execute: (dispatch, resources) => {
46                 dispatch<any>(openInNewTabAction(resources[0]));
47             },
48         },
49         {
50             icon: ReRunProcessIcon,
51             name: ContextMenuActionNames.COPY_AND_RERUN_PROCESS,
52             execute: (dispatch, resources) => {
53                 dispatch<any>(openCopyProcessDialog(resources[0]));
54             },
55         },
56         {
57             icon: OutputIcon,
58             name: ContextMenuActionNames.OUTPUTS,
59             execute: (dispatch, resources) => {
60                 if (resources[0]) {
61                     dispatch<any>(navigateToOutput(resources[0]));
62                 }
63             },
64         },
65         {
66             icon: DetailsIcon,
67             name: ContextMenuActionNames.VIEW_DETAILS,
68             execute: dispatch => {
69                 dispatch<any>(toggleDetailsPanel());
70             },
71         },
72         {
73             icon: AdvancedIcon,
74             name: ContextMenuActionNames.API_DETAILS,
75             execute: (dispatch, resources) => {
76                 dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
77             },
78         },
79     ],
80 ];
81
82 export const processResourceActionSet: ContextMenuActionSet = [
83     [
84         ...readOnlyProcessResourceActionSet.reduce((prev, next) => prev.concat(next), []),
85         {
86             icon: RenameIcon,
87             name: ContextMenuActionNames.EDIT_PROCESS,
88             execute: (dispatch, resources) => {
89                 dispatch<any>(openProcessUpdateDialog(resources[0]));
90             },
91         },
92         // removed until auto-move children is implemented
93         // {
94         //     icon: MoveToIcon,
95         //     name: ContextMenuActionNames.MOVE_TO,
96         //     execute: (dispatch, resources) => {
97         //         dispatch<any>(openMoveProcessDialog(resources[0]));
98         //     },
99         // },
100         {
101             name: ContextMenuActionNames.REMOVE,
102             icon: RemoveIcon,
103             execute: (dispatch, resources) => {
104                 dispatch<any>(openRemoveProcessDialog(resources[0], resources.length));
105             },
106         },
107     ],
108 ];
109
110 const runningProcessOnlyActionSet: ContextMenuActionSet = [
111     [
112         {
113             name: ContextMenuActionNames.CANCEL,
114             icon: StopIcon,
115             execute: (dispatch, resources) => {
116                 dispatch<any>(cancelRunningWorkflow(resources[0].uuid));
117             },
118         },
119     ]
120 ];
121
122 export const processResourceAdminActionSet: ContextMenuActionSet = [
123     [
124         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
125         {
126             component: TogglePublicFavoriteAction,
127             name: ContextMenuActionNames.ADD_TO_PUBLIC_FAVORITES,
128             execute: (dispatch, resources) => {
129                 dispatch<any>(togglePublicFavorite(resources[0])).then(() => {
130                     dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
131                 });
132             },
133         },
134     ],
135 ];
136
137 export const runningProcessResourceActionSet = [
138     [
139         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
140         ...runningProcessOnlyActionSet.reduce((prev, next) => prev.concat(next), []),
141     ],
142 ];
143
144 export const runningProcessResourceAdminActionSet: ContextMenuActionSet = [
145     [
146         ...processResourceAdminActionSet.reduce((prev, next) => prev.concat(next), []),
147         ...runningProcessOnlyActionSet.reduce((prev, next) => prev.concat(next), []),
148     ],
149 ];