Merge branch '21128-toolbar-context-menu'
[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 { ContextMenuAction, 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     CopyIcon,
13     DetailsIcon,
14     AdvancedIcon,
15     OpenIcon,
16     Link,
17     RestoreVersionIcon,
18     FolderSharedIcon,
19 } from "components/icon/icon";
20 import { openCollectionUpdateDialog } from "store/collections/collection-update-actions";
21 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
22 import { openMoveCollectionDialog } from "store/collections/collection-move-actions";
23 import { openCollectionCopyDialog, openMultiCollectionCopyDialog } from "store/collections/collection-copy-actions";
24 import { openWebDavS3InfoDialog } from "store/collections/collection-info-actions";
25 import { ToggleTrashAction } from "views-components/context-menu/actions/trash-action";
26 import { toggleCollectionTrashed } from "store/trash/trash-actions";
27 import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
28 import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
29 import { toggleDetailsPanel } from "store/details-panel/details-panel-action";
30 import { copyToClipboardAction, openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
31 import { openRestoreCollectionVersionDialog } from "store/collections/collection-version-actions";
32 import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
33 import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
34 import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
35 import { ContextMenuResource } from "store/context-menu/context-menu-actions";
36
37 const toggleFavoriteAction: ContextMenuAction = {
38     component: ToggleFavoriteAction,
39     name: "ToggleFavoriteAction",
40     execute: (dispatch, resources) => {
41         for (const resource of [...resources]) {
42             dispatch<any>(toggleFavorite(resource)).then(() => {
43                 dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
44             });
45         }
46     },
47 };
48 const commonActionSet: ContextMenuActionSet = [
49     [
50         {
51             icon: OpenIcon,
52             name: "Open in new tab",
53             execute: (dispatch, resources) => {
54                 dispatch<any>(openInNewTabAction(resources[0]));
55             },
56         },
57         {
58             icon: Link,
59             name: "Copy to clipboard",
60             execute: (dispatch, resources) => {
61                 dispatch<any>(copyToClipboardAction(resources));
62             },
63         },
64         {
65             icon: CopyIcon,
66             name: "Make a copy",
67             execute: (dispatch, resources) => {
68                 if (resources[0].fromContextMenu || resources.length === 1) dispatch<any>(openCollectionCopyDialog(resources[0]));
69                 else dispatch<any>(openMultiCollectionCopyDialog(resources[0]));
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: "API Details",
82             execute: (dispatch, resources) => {
83                 dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
84             },
85         },
86     ],
87 ];
88
89 export const readOnlyCollectionActionSet: ContextMenuActionSet = [
90     [
91         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
92         toggleFavoriteAction,
93         {
94             icon: FolderSharedIcon,
95             name: "Open with 3rd party client",
96             execute: (dispatch, resources) => {
97                 dispatch<any>(openWebDavS3InfoDialog(resources[0].uuid));
98             },
99         },
100     ],
101 ];
102
103 export const collectionActionSet: ContextMenuActionSet = [
104     [
105         ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []),
106         {
107             icon: RenameIcon,
108             name: "Edit collection",
109             execute: (dispatch, resources) => {
110                 dispatch<any>(openCollectionUpdateDialog(resources[0]));
111             },
112         },
113         {
114             icon: ShareIcon,
115             name: "Share",
116             execute: (dispatch, resources) => {
117                 dispatch<any>(openSharingDialog(resources[0].uuid));
118             },
119         },
120         {
121             icon: MoveToIcon,
122             name: "Move to",
123             execute: (dispatch, resources) => dispatch<any>(openMoveCollectionDialog(resources[0])),
124         },
125         {
126             component: ToggleTrashAction,
127             name: "ToggleTrashAction",
128             execute: (dispatch, resources: ContextMenuResource[]) => {
129                 for (const resource of [...resources]) {
130                     dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
131                 }
132             },
133         },
134     ],
135 ];
136
137 export const collectionAdminActionSet: ContextMenuActionSet = [
138     [
139         ...collectionActionSet.reduce((prev, next) => prev.concat(next), []),
140         {
141             component: TogglePublicFavoriteAction,
142             name: "TogglePublicFavoriteAction",
143             execute: (dispatch, resources) => {
144                 for (const resource of [...resources]) {
145                     dispatch<any>(togglePublicFavorite(resource)).then(() => {
146                         dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
147                     });
148                 }
149             },
150         },
151     ],
152 ];
153
154 export const oldCollectionVersionActionSet: ContextMenuActionSet = [
155     [
156         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
157         {
158             icon: RestoreVersionIcon,
159             name: "Restore version",
160             execute: (dispatch, resources) => {
161                 for (const resource of [...resources]) {
162                     dispatch<any>(openRestoreCollectionVersionDialog(resource.uuid));
163                 }
164             },
165         },
166     ],
167 ];