16622: Dialog with connection details for WebDAV and S3
[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 } from "~/components/icon/icon";
22 import { openCollectionUpdateDialog } from "~/store/collections/collection-update-actions";
23 import { favoritePanelActions } from "~/store/favorite-panel/favorite-panel-action";
24 import { openMoveCollectionDialog } from '~/store/collections/collection-move-actions';
25 import { openCollectionCopyDialog } from "~/store/collections/collection-copy-actions";
26 import { openWebDavS3InfoDialog } from "~/store/collections/collection-info-actions";
27 import { ToggleTrashAction } from "~/views-components/context-menu/actions/trash-action";
28 import { toggleCollectionTrashed } from "~/store/trash/trash-actions";
29 import { openSharingDialog } from '~/store/sharing-dialog/sharing-dialog-actions';
30 import { openAdvancedTabDialog } from "~/store/advanced-tab/advanced-tab";
31 import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
32 import { copyToClipboardAction, openInNewTabAction } from "~/store/open-in-new-tab/open-in-new-tab.actions";
33 import { openRestoreCollectionVersionDialog } from "~/store/collections/collection-version-actions";
34 import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
35 import { togglePublicFavorite } from "~/store/public-favorites/public-favorites-actions";
36 import { publicFavoritePanelActions } from "~/store/public-favorites-panel/public-favorites-action";
37
38 const toggleFavoriteAction: ContextMenuAction = {
39     component: ToggleFavoriteAction,
40     name: 'ToggleFavoriteAction',
41     execute: (dispatch, resource) => {
42         dispatch<any>(toggleFavorite(resource)).then(() => {
43             dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
44         });
45     }
46 };
47
48 const commonActionSet: ContextMenuActionSet = [[
49     {
50         icon: OpenIcon,
51         name: "Open in new tab",
52         execute: (dispatch, resource) => {
53             dispatch<any>(openInNewTabAction(resource));
54         }
55     },
56     {
57         icon: Link,
58         name: "Copy to clipboard",
59         execute: (dispatch, resource) => {
60             dispatch<any>(copyToClipboardAction(resource));
61         }
62     },
63     {
64         icon: CopyIcon,
65         name: "Make a copy",
66         execute: (dispatch, resource) => {
67             dispatch<any>(openCollectionCopyDialog(resource));
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 readOnlyCollectionActionSet: ContextMenuActionSet = [[
88     ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
89     toggleFavoriteAction,
90     {
91         icon: AdvancedIcon,
92         name: "Connecting with WebDav or S3",
93         execute: (dispatch, resource) => {
94             dispatch<any>(openWebDavS3InfoDialog(resource.uuid));
95         }
96     },
97 ]];
98
99 export const collectionActionSet: ContextMenuActionSet = [
100     [
101         ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []),
102         {
103             icon: RenameIcon,
104             name: "Edit collection",
105             execute: (dispatch, resource) => {
106                 dispatch<any>(openCollectionUpdateDialog(resource));
107             }
108         },
109         {
110             icon: ShareIcon,
111             name: "Share",
112             execute: (dispatch, { uuid }) => {
113                 dispatch<any>(openSharingDialog(uuid));
114             }
115         },
116         {
117             icon: MoveToIcon,
118             name: "Move to",
119             execute: (dispatch, resource) => dispatch<any>(openMoveCollectionDialog(resource))
120         },
121         {
122             component: ToggleTrashAction,
123             name: 'ToggleTrashAction',
124             execute: (dispatch, resource) => {
125                 dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
126             }
127         },
128     ]
129 ];
130
131 export const collectionAdminActionSet: ContextMenuActionSet = [
132     [
133         ...collectionActionSet.reduce((prev, next) => prev.concat(next), []),
134         {
135             component: TogglePublicFavoriteAction,
136             name: 'TogglePublicFavoriteAction',
137             execute: (dispatch, resource) => {
138                 dispatch<any>(togglePublicFavorite(resource)).then(() => {
139                     dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
140                 });
141             }
142         },
143     ]
144 ];
145
146 export const oldCollectionVersionActionSet: ContextMenuActionSet = [
147     [
148         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
149         {
150             icon: RestoreVersionIcon,
151             name: 'Restore version',
152             execute: (dispatch, { uuid }) => {
153                 dispatch<any>(openRestoreCollectionVersionDialog(uuid));
154             }
155         },
156     ]
157 ];