Merge branch '18028-all-procs-context-menu'. Closes #18028
[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, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon,
10     RemoveIcon, ReRunProcessIcon, InputIcon, OutputIcon, CommandIcon,
11     LogIcon, AdvancedIcon
12 } from "components/icon/icon";
13 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
14 import { openMoveProcessDialog } from 'store/processes/process-move-actions';
15 import { openProcessUpdateDialog } from "store/processes/process-update-actions";
16 import { openCopyProcessDialog } from 'store/processes/process-copy-actions';
17 import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
18 import { openRemoveProcessDialog, reRunProcess } from "store/processes/processes-actions";
19 import { toggleDetailsPanel } from 'store/details-panel/details-panel-action';
20 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
21 import { openProcessInputDialog } from "store/processes/process-input-actions";
22 import { navigateToOutput } from "store/process-panel/process-panel-actions";
23 import { openProcessCommandDialog } from "store/processes/process-command-actions";
24 import { navigateToProcessLogs } from "store/navigation/navigation-action";
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
30 export const readOnlyProcessResourceActionSet: ContextMenuActionSet = [[
31     {
32         component: ToggleFavoriteAction,
33         execute: (dispatch, resource) => {
34             dispatch<any>(toggleFavorite(resource)).then(() => {
35                 dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
36             });
37         }
38     },
39     {
40         icon: CopyIcon,
41         name: "Copy to project",
42         execute: (dispatch, resource) => {
43             dispatch<any>(openCopyProcessDialog(resource));
44         }
45     },
46     {
47         icon: ReRunProcessIcon,
48         name: "Re-run process",
49         execute: (dispatch, resource) => {
50             if(resource.workflowUuid) {
51                 dispatch<any>(reRunProcess(resource.uuid, resource.workflowUuid));
52             } else {
53                 dispatch(snackbarActions.OPEN_SNACKBAR({ message: `You can't re-run this process`, hideDuration: 2000, kind: SnackbarKind.ERROR }));
54             }
55         }
56     },
57     {
58         icon: InputIcon,
59         name: "Inputs",
60         execute: (dispatch, resource) => {
61             dispatch<any>(openProcessInputDialog(resource.uuid));
62         }
63     },
64     {
65         icon: OutputIcon,
66         name: "Outputs",
67         execute: (dispatch, resource) => {
68             if(resource.outputUuid){
69                 dispatch<any>(navigateToOutput(resource.outputUuid));
70             }
71         }
72     },
73     {
74         icon: CommandIcon,
75         name: "Command",
76         execute: (dispatch, resource) => {
77             dispatch<any>(openProcessCommandDialog(resource.uuid));
78         }
79     },
80     {
81         icon: LogIcon,
82         name: "Log",
83         execute: (dispatch, resource) => {
84             dispatch<any>(navigateToProcessLogs(resource.uuid));
85         }
86     },
87     {
88         icon: DetailsIcon,
89         name: "View details",
90         execute: dispatch => {
91             dispatch<any>(toggleDetailsPanel());
92         }
93     },
94     {
95         icon: AdvancedIcon,
96         name: "Advanced",
97         execute: (dispatch, resource) => {
98             dispatch<any>(openAdvancedTabDialog(resource.uuid));
99         }
100     },
101 ]];
102
103 export const processResourceActionSet: ContextMenuActionSet = [[
104     ...readOnlyProcessResourceActionSet.reduce((prev, next) => prev.concat(next), []),
105     {
106         icon: RenameIcon,
107         name: "Edit process",
108         execute: (dispatch, resource) => {
109             dispatch<any>(openProcessUpdateDialog(resource));
110         }
111     },
112     {
113         icon: ShareIcon,
114         name: "Share",
115         execute: (dispatch, { uuid }) => {
116             dispatch<any>(openSharingDialog(uuid));
117         }
118     },
119     {
120         icon: MoveToIcon,
121         name: "Move to",
122         execute: (dispatch, resource) => {
123             dispatch<any>(openMoveProcessDialog(resource));
124         }
125     },
126     {
127         name: "Remove",
128         icon: RemoveIcon,
129         execute: (dispatch, resource) => {
130             dispatch<any>(openRemoveProcessDialog(resource.uuid));
131         }
132     }
133 ]];
134
135 export const processResourceAdminActionSet: ContextMenuActionSet = [[
136     ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
137     {
138         component: TogglePublicFavoriteAction,
139         name: "Add to public favorites",
140         execute: (dispatch, resource) => {
141             dispatch<any>(togglePublicFavorite(resource)).then(() => {
142                 dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
143             });
144         }
145     },
146 ]];