21448: running process also sorted Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa...
[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     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             name: ContextMenuActionNames.ADD_TO_FAVORITES,
40             execute: (dispatch, resources) => {
41                 dispatch<any>(toggleFavorite(resources[0])).then(() => {
42                     dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
43                 });
44             },
45         },
46         {
47             icon: OpenIcon,
48             name: ContextMenuActionNames.OPEN_IN_NEW_TAB,
49             execute: (dispatch, resources) => {
50                 dispatch<any>(openInNewTabAction(resources[0]));
51             },
52         },
53         {
54             icon: ReRunProcessIcon,
55             name: ContextMenuActionNames.COPY_AND_RERUN_PROCESS,
56             execute: (dispatch, resources) => {
57                 dispatch<any>(openCopyProcessDialog(resources[0]));
58             },
59         },
60         {
61             icon: OutputIcon,
62             name: ContextMenuActionNames.OUTPUTS,
63             execute: (dispatch, resources) => {
64                 if (resources[0]) {
65                     dispatch<any>(navigateToOutput(resources[0]));
66                 }
67             },
68         },
69         {
70             icon: DetailsIcon,
71             name: ContextMenuActionNames.VIEW_DETAILS,
72             execute: dispatch => {
73                 dispatch<any>(toggleDetailsPanel());
74             },
75         },
76         {
77             icon: AdvancedIcon,
78             name: ContextMenuActionNames.API_DETAILS,
79             execute: (dispatch, resources) => {
80                 dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
81             },
82         },
83     ],
84 ];
85
86 export const processResourceActionSet: ContextMenuActionSet = [
87     [
88         ...readOnlyProcessResourceActionSet.reduce((prev, next) => prev.concat(next), []),
89         {
90             icon: RenameIcon,
91             name: ContextMenuActionNames.EDIT_PROCESS,
92             execute: (dispatch, resources) => {
93                 dispatch<any>(openProcessUpdateDialog(resources[0]));
94             },
95         },
96         {
97             icon: ShareIcon,
98             name: ContextMenuActionNames.SHARE,
99             execute: (dispatch, resources) => {
100                 dispatch<any>(openSharingDialog(resources[0].uuid));
101             },
102         },
103         {
104             icon: MoveToIcon,
105             name: ContextMenuActionNames.MOVE_TO,
106             execute: (dispatch, resources) => {
107                 dispatch<any>(openMoveProcessDialog(resources[0]));
108             },
109         },
110         {
111             name: ContextMenuActionNames.REMOVE,
112             icon: RemoveIcon,
113             execute: (dispatch, resources) => {
114                 dispatch<any>(openRemoveProcessDialog(resources[0], resources.length));
115             },
116         },
117     ],
118 ];
119
120 const runningProcessOnlyActionSet: ContextMenuActionSet = [
121     [
122         {
123             name: ContextMenuActionNames.CANCEL,
124             icon: StopIcon,
125             execute: (dispatch, resources) => {
126                 dispatch<any>(cancelRunningWorkflow(resources[0].uuid));
127             },
128         },
129     ]
130 ];
131
132 export const processResourceAdminActionSet: ContextMenuActionSet = [
133     [
134         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
135         {
136             component: TogglePublicFavoriteAction,
137             name: ContextMenuActionNames.ADD_TO_PUBLIC_FAVORITES,
138             execute: (dispatch, resources) => {
139                 dispatch<any>(togglePublicFavorite(resources[0])).then(() => {
140                     dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
141                 });
142             },
143         },
144     ],
145 ];
146
147 export const runningProcessResourceActionSet = [
148     [
149         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
150         ...runningProcessOnlyActionSet.reduce((prev, next) => prev.concat(next), []),
151     ],
152 ];
153
154 export const runningProcessResourceAdminActionSet: ContextMenuActionSet = [
155     [
156         ...processResourceAdminActionSet.reduce((prev, next) => prev.concat(next), []),
157         ...runningProcessOnlyActionSet.reduce((prev, next) => prev.concat(next), []),
158     ],
159 ];