Merge branch '17526-3rd-party-access-ui' into main. Closes #17526
[arvados-workbench2.git] / src / views-components / context-menu / action-sets / collection-action-set.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import {
6     ContextMenuAction,
7     ContextMenuActionSet
8 } from "../context-menu-action-set";
9 import { ToggleFavoriteAction } from "../actions/favorite-action";
10 import { toggleFavorite } from "store/favorites/favorites-actions";
11 import {
12     RenameIcon,
13     ShareIcon,
14     MoveToIcon,
15     CopyIcon,
16     DetailsIcon,
17     AdvancedIcon,
18     OpenIcon,
19     Link,
20     RestoreVersionIcon,
21     FolderSharedIcon
22 } from "components/icon/icon";
23 import { openCollectionUpdateDialog } from "store/collections/collection-update-actions";
24 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
25 import { openMoveCollectionDialog } from 'store/collections/collection-move-actions';
26 import { openCollectionCopyDialog } from "store/collections/collection-copy-actions";
27 import { openWebDavS3InfoDialog } from "store/collections/collection-info-actions";
28 import { ToggleTrashAction } from "views-components/context-menu/actions/trash-action";
29 import { toggleCollectionTrashed } from "store/trash/trash-actions";
30 import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
31 import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
32 import { toggleDetailsPanel } from 'store/details-panel/details-panel-action';
33 import { copyToClipboardAction, openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
34 import { openRestoreCollectionVersionDialog } from "store/collections/collection-version-actions";
35 import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
36 import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
37 import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
38
39 const toggleFavoriteAction: ContextMenuAction = {
40     component: ToggleFavoriteAction,
41     name: 'ToggleFavoriteAction',
42     execute: (dispatch, resource) => {
43         dispatch<any>(toggleFavorite(resource)).then(() => {
44             dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
45         });
46     }
47 };
48
49 const commonActionSet: ContextMenuActionSet = [[
50     {
51         icon: OpenIcon,
52         name: "Open in new tab",
53         execute: (dispatch, resource) => {
54             dispatch<any>(openInNewTabAction(resource));
55         }
56     },
57     {
58         icon: Link,
59         name: "Copy to clipboard",
60         execute: (dispatch, resource) => {
61             dispatch<any>(copyToClipboardAction(resource));
62         }
63     },
64     {
65         icon: CopyIcon,
66         name: "Make a copy",
67         execute: (dispatch, resource) => {
68             dispatch<any>(openCollectionCopyDialog(resource));
69         }
70
71     },
72     {
73         icon: DetailsIcon,
74         name: "View details",
75         execute: dispatch => {
76             dispatch<any>(toggleDetailsPanel());
77         }
78     },
79     {
80         icon: AdvancedIcon,
81         name: "Advanced",
82         execute: (dispatch, resource) => {
83             dispatch<any>(openAdvancedTabDialog(resource.uuid));
84         }
85     },
86 ]];
87
88 export const readOnlyCollectionActionSet: ContextMenuActionSet = [[
89     ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
90     toggleFavoriteAction,
91     {
92         icon: FolderSharedIcon,
93         name: "Open with 3rd party client",
94         execute: (dispatch, resource) => {
95             dispatch<any>(openWebDavS3InfoDialog(resource.uuid));
96         }
97     },
98 ]];
99
100 export const collectionActionSet: ContextMenuActionSet = [
101     [
102         ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []),
103         {
104             icon: RenameIcon,
105             name: "Edit collection",
106             execute: (dispatch, resource) => {
107                 dispatch<any>(openCollectionUpdateDialog(resource));
108             }
109         },
110         {
111             icon: ShareIcon,
112             name: "Share",
113             execute: (dispatch, { uuid }) => {
114                 dispatch<any>(openSharingDialog(uuid));
115             }
116         },
117         {
118             icon: MoveToIcon,
119             name: "Move to",
120             execute: (dispatch, resource) => dispatch<any>(openMoveCollectionDialog(resource))
121         },
122         {
123             component: ToggleTrashAction,
124             name: 'ToggleTrashAction',
125             execute: (dispatch, resource) => {
126                 dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
127             }
128         },
129     ]
130 ];
131
132 export const collectionAdminActionSet: ContextMenuActionSet = [
133     [
134         ...collectionActionSet.reduce((prev, next) => prev.concat(next), []),
135         {
136             component: TogglePublicFavoriteAction,
137             name: 'TogglePublicFavoriteAction',
138             execute: (dispatch, resource) => {
139                 dispatch<any>(togglePublicFavorite(resource)).then(() => {
140                     dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
141                 });
142             }
143         },
144     ]
145 ];
146
147 export const oldCollectionVersionActionSet: ContextMenuActionSet = [
148     [
149         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
150         {
151             icon: RestoreVersionIcon,
152             name: 'Restore version',
153             execute: (dispatch, { uuid }) => {
154                 dispatch<any>(openRestoreCollectionVersionDialog(uuid));
155             }
156         },
157     ]
158 ];