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