Merge branch '21278-search-redirect' refs #21278
[arvados.git] / services / workbench2 / src / views-components / multiselect-toolbar / ms-collection-action-set.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { MoveToIcon, CopyIcon, RenameIcon } from "components/icon/icon";
6 import { openMoveCollectionDialog } from "store/collections/collection-move-actions";
7 import { openCollectionCopyDialog, openMultiCollectionCopyDialog } from "store/collections/collection-copy-actions";
8 import { toggleCollectionTrashed } from "store/trash/trash-actions";
9 import { ContextMenuResource } from "store/context-menu/context-menu-actions";
10 import { msCommonActionSet, MultiSelectMenuActionSet, MultiSelectMenuAction } from "./ms-menu-actions";
11 import { MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions";
12 import { TrashIcon, Link, FolderSharedIcon } from "components/icon/icon";
13 import { openCollectionUpdateDialog } from "store/collections/collection-update-actions";
14 import { copyToClipboardAction } from "store/open-in-new-tab/open-in-new-tab.actions";
15 import { openWebDavS3InfoDialog } from "store/collections/collection-info-actions";
16
17 const { MAKE_A_COPY, MOVE_TO, MOVE_TO_TRASH, EDIT_COLLECTION, OPEN_IN_NEW_TAB, OPEN_W_3RD_PARTY_CLIENT, COPY_TO_CLIPBOARD, VIEW_DETAILS, API_DETAILS, ADD_TO_FAVORITES, SHARE} = MultiSelectMenuActionNames;
18
19 const msCopyCollection: MultiSelectMenuAction = {
20     name: MAKE_A_COPY,
21     icon: CopyIcon,
22     hasAlts: false,
23     isForMulti: true,
24     execute: (dispatch, [...resources]) => {
25         if (resources[0].fromContextMenu || resources.length === 1) dispatch<any>(openCollectionCopyDialog(resources[0]));
26         else dispatch<any>(openMultiCollectionCopyDialog(resources[0]));
27     },
28 }
29
30 const msMoveCollection: MultiSelectMenuAction = {
31     name: MOVE_TO,
32     icon: MoveToIcon,
33     hasAlts: false,
34     isForMulti: true,
35     execute: (dispatch, resources) => dispatch<any>(openMoveCollectionDialog(resources[0])),
36 }
37
38 const msToggleTrashAction: MultiSelectMenuAction = {
39     name: MOVE_TO_TRASH,
40     icon: TrashIcon,
41     isForMulti: true,
42     hasAlts: false,
43     execute: (dispatch, resources: ContextMenuResource[]) => {
44         for (const resource of [...resources]) {
45             dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
46         }
47     },
48 }
49
50 const msEditCollection: MultiSelectMenuAction = {
51     name: MultiSelectMenuActionNames.EDIT_COLLECTION,
52     icon: RenameIcon,
53     hasAlts: false,
54     isForMulti: false,
55     execute: (dispatch, resources) => {
56         dispatch<any>(openCollectionUpdateDialog(resources[0]));
57     },
58 }
59
60 const msCopyToClipboardMenuAction: MultiSelectMenuAction  = {
61     name: COPY_TO_CLIPBOARD,
62     icon: Link,
63     hasAlts: false,
64     isForMulti: false,
65     execute: (dispatch, resources) => {
66         dispatch<any>(copyToClipboardAction(resources));
67     },
68 };
69
70 const msOpenWith3rdPartyClientAction: MultiSelectMenuAction  = {
71     name: OPEN_W_3RD_PARTY_CLIENT,
72     icon: FolderSharedIcon,
73     hasAlts: false,
74     isForMulti: false,
75     execute: (dispatch, resources) => {
76         dispatch<any>(openWebDavS3InfoDialog(resources[0].uuid));
77     },
78 };
79
80 export const msCollectionActionSet: MultiSelectMenuActionSet = [
81     [
82         ...msCommonActionSet,
83         msCopyCollection,
84         msMoveCollection,
85         msToggleTrashAction,
86         msEditCollection,
87         msCopyToClipboardMenuAction,
88         msOpenWith3rdPartyClientAction
89     ],
90 ];
91
92 export const msReadOnlyCollectionActionFilter = new Set([OPEN_IN_NEW_TAB, COPY_TO_CLIPBOARD, MAKE_A_COPY, VIEW_DETAILS, API_DETAILS, ADD_TO_FAVORITES, OPEN_W_3RD_PARTY_CLIENT]);
93 export const msCommonCollectionActionFilter = new Set([OPEN_IN_NEW_TAB, COPY_TO_CLIPBOARD, MAKE_A_COPY, VIEW_DETAILS, API_DETAILS, OPEN_W_3RD_PARTY_CLIENT, EDIT_COLLECTION, SHARE, MOVE_TO, ADD_TO_FAVORITES, MOVE_TO_TRASH])
94 export const msOldCollectionActionFilter = new Set([OPEN_IN_NEW_TAB, COPY_TO_CLIPBOARD, MAKE_A_COPY, VIEW_DETAILS, API_DETAILS, OPEN_W_3RD_PARTY_CLIENT, EDIT_COLLECTION, SHARE, MOVE_TO, ADD_TO_FAVORITES, MOVE_TO_TRASH])