Merge branch '18559-user-profile' into main. Closes #18559
[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     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 { 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
29 export const readOnlyProcessResourceActionSet: ContextMenuActionSet = [[
30     {
31         component: ToggleFavoriteAction,
32         execute: (dispatch, resource) => {
33             dispatch<any>(toggleFavorite(resource)).then(() => {
34                 dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
35             });
36         }
37     },
38     {
39         icon: CopyIcon,
40         name: "Copy to project",
41         execute: (dispatch, resource) => {
42             dispatch<any>(openCopyProcessDialog(resource));
43         }
44     },
45     {
46         icon: ReRunProcessIcon,
47         name: "Re-run process",
48         execute: (dispatch, resource) => {
49             if(resource.workflowUuid) {
50                 dispatch<any>(reRunProcess(resource.uuid, resource.workflowUuid));
51             } else {
52                 dispatch(snackbarActions.OPEN_SNACKBAR({ message: `You can't re-run this process`, hideDuration: 2000, kind: SnackbarKind.ERROR }));
53             }
54         }
55     },
56     {
57         icon: InputIcon,
58         name: "Inputs",
59         execute: (dispatch, resource) => {
60             dispatch<any>(openProcessInputDialog(resource.uuid));
61         }
62     },
63     {
64         icon: OutputIcon,
65         name: "Outputs",
66         execute: (dispatch, resource) => {
67             if(resource.outputUuid){
68                 dispatch<any>(navigateToOutput(resource.outputUuid));
69             }
70         }
71     },
72     {
73         icon: CommandIcon,
74         name: "Command",
75         execute: (dispatch, resource) => {
76             dispatch<any>(openProcessCommandDialog(resource.uuid));
77         }
78     },
79     {
80         icon: DetailsIcon,
81         name: "View details",
82         execute: dispatch => {
83             dispatch<any>(toggleDetailsPanel());
84         }
85     },
86     {
87         icon: AdvancedIcon,
88         name: "Advanced",
89         execute: (dispatch, resource) => {
90             dispatch<any>(openAdvancedTabDialog(resource.uuid));
91         }
92     },
93 ]];
94
95 export const processResourceActionSet: ContextMenuActionSet = [[
96     ...readOnlyProcessResourceActionSet.reduce((prev, next) => prev.concat(next), []),
97     {
98         icon: RenameIcon,
99         name: "Edit process",
100         execute: (dispatch, resource) => {
101             dispatch<any>(openProcessUpdateDialog(resource));
102         }
103     },
104     {
105         icon: ShareIcon,
106         name: "Share",
107         execute: (dispatch, { uuid }) => {
108             dispatch<any>(openSharingDialog(uuid));
109         }
110     },
111     {
112         icon: MoveToIcon,
113         name: "Move to",
114         execute: (dispatch, resource) => {
115             dispatch<any>(openMoveProcessDialog(resource));
116         }
117     },
118     {
119         name: "Remove",
120         icon: RemoveIcon,
121         execute: (dispatch, resource) => {
122             dispatch<any>(openRemoveProcessDialog(resource.uuid));
123         }
124     }
125 ]];
126
127 export const processResourceAdminActionSet: ContextMenuActionSet = [[
128     ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
129     {
130         component: TogglePublicFavoriteAction,
131         name: "Add to public favorites",
132         execute: (dispatch, resource) => {
133             dispatch<any>(togglePublicFavorite(resource)).then(() => {
134                 dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
135             });
136         }
137     },
138 ]];