aceebe066b44badc8318cea8d71021b6c993f3de
[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,
10     ShareIcon,
11     MoveToIcon,
12     DetailsIcon,
13     RemoveIcon,
14     ReRunProcessIcon,
15     OutputIcon,
16     AdvancedIcon,
17     OpenIcon,
18 } from "components/icon/icon";
19 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
20 import { openMoveProcessDialog } from "store/processes/process-move-actions";
21 import { openProcessUpdateDialog } from "store/processes/process-update-actions";
22 import { openCopyProcessDialog } from "store/processes/process-copy-actions";
23 import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
24 import { openRemoveProcessDialog } from "store/processes/processes-actions";
25 import { toggleDetailsPanel } from "store/details-panel/details-panel-action";
26 import { navigateToOutput } from "store/process-panel/process-panel-actions";
27 import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
28 import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
29 import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
30 import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
31 import { openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
32
33 export const readOnlyProcessResourceActionSet: ContextMenuActionSet = [
34     [
35         {
36             component: ToggleFavoriteAction,
37             execute: (dispatch, resources) => {
38                 resources.forEach(resource =>
39                     dispatch<any>(toggleFavorite(resource)).then(() => {
40                         dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
41                     })
42                 );
43             },
44         },
45         {
46             icon: OpenIcon,
47             name: "Open in new tab",
48             execute: (dispatch, resources) => {
49                 resources.forEach(resource => dispatch<any>(openInNewTabAction(resource)));
50             },
51         },
52         {
53             icon: ReRunProcessIcon,
54             name: "Copy and re-run process",
55             execute: (dispatch, resources) => {
56                 resources.forEach(resource => dispatch<any>(openCopyProcessDialog(resource)));
57             },
58         },
59         {
60             icon: OutputIcon,
61             name: "Outputs",
62             execute: (dispatch, resources) => {
63                 resources.forEach(resource => {
64                     if (resource.outputUuid) {
65                         dispatch<any>(navigateToOutput(resource.outputUuid));
66                     }
67                 });
68             },
69         },
70         {
71             icon: DetailsIcon,
72             name: "View details",
73             execute: dispatch => {
74                 dispatch<any>(toggleDetailsPanel());
75             },
76         },
77         {
78             icon: AdvancedIcon,
79             name: "API Details",
80             execute: (dispatch, resources) => {
81                 resources.forEach(resource => dispatch<any>(openAdvancedTabDialog(resource.uuid)));
82             },
83         },
84     ],
85 ];
86
87 export const processResourceActionSet: ContextMenuActionSet = [
88     [
89         ...readOnlyProcessResourceActionSet.reduce((prev, next) => prev.concat(next), []),
90         {
91             icon: RenameIcon,
92             name: "Edit process",
93             execute: (dispatch, resources) => {
94                 resources.forEach(resource => dispatch<any>(openProcessUpdateDialog(resource)));
95             },
96         },
97         {
98             icon: ShareIcon,
99             name: "Share",
100             execute: (dispatch, resources) => {
101                 resources.forEach(({ uuid }) => dispatch<any>(openSharingDialog(uuid)));
102             },
103         },
104         {
105             icon: MoveToIcon,
106             name: "Move to",
107             execute: (dispatch, resources) => {
108                 dispatch<any>(openMoveProcessDialog(resources[0]));
109             },
110         },
111         {
112             name: "Remove",
113             icon: RemoveIcon,
114             execute: (dispatch, resources) => {
115                 dispatch<any>(openRemoveProcessDialog(resources[0], resources.length));
116             },
117         },
118     ],
119 ];
120
121 export const processResourceAdminActionSet: ContextMenuActionSet = [
122     [
123         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
124         {
125             component: TogglePublicFavoriteAction,
126             name: "Add to public favorites",
127             execute: (dispatch, resources) => {
128                 resources.forEach(resource =>
129                     dispatch<any>(togglePublicFavorite(resource)).then(() => {
130                         dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
131                     })
132                 );
133             },
134         },
135     ],
136 ];