15768: collection copy dialog mostly works Arvados-DCO-1.1-Signed-off-by: Lisa Knox...
[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         resources.forEach(resource =>
42             dispatch<any>(toggleFavorite(resource)).then(() => {
43                 dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
44             })
45         );
46     },
47 };
48
49 const commonActionSet: ContextMenuActionSet = [
50     [
51         {
52             icon: OpenIcon,
53             name: "Open in new tab",
54             execute: (dispatch, resources) => {
55                 dispatch<any>(openInNewTabAction(resources[0]));
56             },
57         },
58         {
59             icon: Link,
60             name: "Copy to clipboard",
61             execute: (dispatch, resources) => {
62                 dispatch<any>(copyToClipboardAction(resources));
63             },
64         },
65         {
66             icon: CopyIcon,
67             name: "Make a copy",
68             execute: (dispatch, resources) => {
69                 console.log(resources[0]);
70                 //here fix single vs one
71                 if (resources[0].isSingle) dispatch<any>(openCollectionCopyDialog(resources[0]));
72                 else dispatch<any>(openMultiCollectionCopyDialog(resources[0]));
73             },
74         },
75         {
76             icon: DetailsIcon,
77             name: "View details",
78             execute: dispatch => {
79                 dispatch<any>(toggleDetailsPanel());
80             },
81         },
82         {
83             icon: AdvancedIcon,
84             name: "API Details",
85             execute: (dispatch, resources) => {
86                 resources.forEach(resource => dispatch<any>(openAdvancedTabDialog(resource.uuid)));
87             },
88         },
89     ],
90 ];
91
92 export const readOnlyCollectionActionSet: ContextMenuActionSet = [
93     [
94         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
95         toggleFavoriteAction,
96         {
97             icon: FolderSharedIcon,
98             name: "Open with 3rd party client",
99             execute: (dispatch, resources) => {
100                 resources.forEach(resource => dispatch<any>(openWebDavS3InfoDialog(resource.uuid)));
101             },
102         },
103     ],
104 ];
105
106 export const collectionActionSet: ContextMenuActionSet = [
107     [
108         ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []),
109         {
110             icon: RenameIcon,
111             name: "Edit collection",
112             execute: (dispatch, resources) => {
113                 resources.forEach(resource => dispatch<any>(openCollectionUpdateDialog(resource)));
114             },
115         },
116         {
117             icon: ShareIcon,
118             name: "Share",
119             execute: (dispatch, resources) => {
120                 resources.forEach(({ uuid }) => dispatch<any>(openSharingDialog(uuid)));
121             },
122         },
123         {
124             icon: MoveToIcon,
125             name: "Move to",
126             execute: (dispatch, resources) => dispatch<any>(openMoveCollectionDialog(resources[0])),
127         },
128         {
129             component: ToggleTrashAction,
130             name: "ToggleTrashAction",
131             execute: (dispatch, resources: ContextMenuResource[]) => {
132                 //here fix  multi?
133                 resources.forEach(resource => dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!)));
134             },
135         },
136     ],
137 ];
138
139 export const collectionAdminActionSet: ContextMenuActionSet = [
140     [
141         ...collectionActionSet.reduce((prev, next) => prev.concat(next), []),
142         {
143             component: TogglePublicFavoriteAction,
144             name: "TogglePublicFavoriteAction",
145             execute: (dispatch, resources) => {
146                 resources.forEach(resource =>
147                     dispatch<any>(togglePublicFavorite(resource)).then(() => {
148                         dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
149                     })
150                 );
151             },
152         },
153     ],
154 ];
155
156 export const oldCollectionVersionActionSet: ContextMenuActionSet = [
157     [
158         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
159         {
160             icon: RestoreVersionIcon,
161             name: "Restore version",
162             execute: (dispatch, resources) => {
163                 resources.forEach(({ uuid }) => dispatch<any>(openRestoreCollectionVersionDialog(uuid)));
164             },
165         },
166     ],
167 ];