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