Merge branch '22207-icon-resort'
[arvados.git] / services / workbench2 / src / views-components / multiselect-toolbar / ms-project-action-set.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { MultiSelectMenuAction, MultiSelectMenuActionSet, msCommonActionSet } from 'views-components/multiselect-toolbar/ms-menu-actions';
6 import { ContextMenuActionNames } from "views-components/context-menu/context-menu-action-set";
7 import { openMoveProjectDialog } from 'store/projects/project-move-actions';
8 import { toggleProjectTrashed } from 'store/trash/trash-actions';
9 import {
10     FreezeIcon,
11     MoveToIcon,
12     NewProjectIcon,
13     RenameIcon,
14     UnfreezeIcon,
15     ShareIcon,
16     CopyIcon,
17 } from 'components/icon/icon';
18 import { RestoreFromTrashIcon, TrashIcon, FolderSharedIcon, Link } from 'components/icon/icon';
19 import { getResource } from 'store/resources/resources';
20 import { openProjectCreateDialog } from 'store/projects/project-create-actions';
21 import { openProjectUpdateDialog } from 'store/projects/project-update-actions';
22 import { freezeProject, unfreezeProject } from 'store/projects/project-lock-actions';
23 import { openWebDavS3InfoDialog } from 'store/collections/collection-info-actions';
24 import { copyToClipboardAction, copyStringToClipboardAction } from 'store/open-in-new-tab/open-in-new-tab.actions';
25 import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
26
27 const {
28     ADD_TO_FAVORITES,
29     ADD_TO_PUBLIC_FAVORITES,
30     OPEN_IN_NEW_TAB,
31     COPY_LINK_TO_CLIPBOARD,
32     COPY_UUID,
33     VIEW_DETAILS,
34     API_DETAILS,
35     OPEN_WITH_3RD_PARTY_CLIENT,
36     EDIT_PROJECT,
37     SHARE,
38     MOVE_TO,
39     MOVE_TO_TRASH,
40     FREEZE_PROJECT,
41     NEW_PROJECT,
42 } = ContextMenuActionNames;
43
44 const msCopyToClipboardMenuAction: MultiSelectMenuAction  = {
45     name: COPY_LINK_TO_CLIPBOARD,
46     icon: Link,
47     hasAlts: false,
48     isForMulti: false,
49     execute: (dispatch, resources) => {
50         dispatch<any>(copyToClipboardAction(resources));
51     },
52 };
53
54 const msCopyUuid: MultiSelectMenuAction  = {
55     name: COPY_UUID,
56     icon: CopyIcon,
57     hasAlts: false,
58     isForMulti: false,
59     execute: (dispatch, resources) => {
60         dispatch<any>(copyStringToClipboardAction(resources[0].uuid));
61     },
62 };
63
64 const msEditProjectAction: MultiSelectMenuAction = {
65     name: EDIT_PROJECT,
66     icon: RenameIcon,
67     hasAlts: false,
68     isForMulti: false,
69     execute: (dispatch, resources) => {
70         dispatch<any>(openProjectUpdateDialog(resources[0]));
71     },
72 };
73
74 const msMoveToAction: MultiSelectMenuAction = {
75     name: MOVE_TO,
76     icon: MoveToIcon,
77     hasAlts: false,
78     isForMulti: true,
79     execute: (dispatch, resource) => {
80         dispatch<any>(openMoveProjectDialog(resource[0]));
81     },
82 };
83
84 const msOpenWith3rdPartyClientAction: MultiSelectMenuAction  = {
85     name: OPEN_WITH_3RD_PARTY_CLIENT,
86     icon: FolderSharedIcon,
87     hasAlts: false,
88     isForMulti: false,
89     execute: (dispatch, resources) => {
90         dispatch<any>(openWebDavS3InfoDialog(resources[0].uuid));
91     },
92 };
93
94 export const msToggleTrashAction: MultiSelectMenuAction = {
95     name: MOVE_TO_TRASH,
96     icon: TrashIcon,
97     hasAlts: true,
98     altName: 'Restore from Trash',
99     altIcon: RestoreFromTrashIcon,
100     isForMulti: true,
101     useAlts: (uuid, iconProps) => {
102         return uuid ? (getResource(uuid)(iconProps.resources) as any)?.isTrashed : false;
103     },
104     execute: (dispatch, resources) => {
105         for (const resource of [...resources]) {
106             dispatch<any>(toggleProjectTrashed(resource.uuid, resource.ownerUuid, resource.isTrashed!!, resources.length > 1));
107         }
108     },
109 };
110
111 const msFreezeProjectAction: MultiSelectMenuAction = {
112     name: FREEZE_PROJECT,
113     icon: FreezeIcon,
114     hasAlts: true,
115     altName: 'Unfreeze Project',
116     altIcon: UnfreezeIcon,
117     isForMulti: false,
118     useAlts: (uuid, iconProps) => {
119         return uuid ? !!(getResource(uuid)(iconProps.resources) as any).frozenByUuid : false;
120     },
121     execute: (dispatch, resources) => {
122         if ((resources[0] as any).frozenByUuid) {
123             dispatch<any>(unfreezeProject(resources[0].uuid));
124         } else {
125             dispatch<any>(freezeProject(resources[0].uuid));
126         }
127     },
128 };
129
130 const msNewProjectAction: MultiSelectMenuAction = {
131     name: NEW_PROJECT,
132     icon: NewProjectIcon,
133     hasAlts: false,
134     isForMulti: false,
135     execute: (dispatch, resources): void => {
136         dispatch<any>(openProjectCreateDialog(resources[0].uuid));
137     },
138 };
139
140 const msShareAction: MultiSelectMenuAction  = {
141     name: SHARE,
142     icon: ShareIcon,
143     hasAlts: false,
144     isForMulti: false,
145     execute: (dispatch, resources) => {
146         dispatch<any>(openSharingDialog(resources[0].uuid));
147     },
148 };
149
150 export const msProjectActionSet: MultiSelectMenuActionSet = [
151     [
152         ...msCommonActionSet,
153         msEditProjectAction,
154         msMoveToAction,
155         msToggleTrashAction,
156         msNewProjectAction,
157         msFreezeProjectAction,
158         msOpenWith3rdPartyClientAction,
159         msCopyToClipboardMenuAction,
160         msShareAction,
161         msCopyUuid,
162     ],
163 ];
164
165 export const msCommonProjectActionFilter = new Set<string>([
166     ADD_TO_FAVORITES,
167     MOVE_TO_TRASH,
168     API_DETAILS,
169     COPY_LINK_TO_CLIPBOARD,
170     EDIT_PROJECT,
171     FREEZE_PROJECT,
172     MOVE_TO,
173     NEW_PROJECT,
174     OPEN_IN_NEW_TAB,
175     OPEN_WITH_3RD_PARTY_CLIENT,
176     SHARE,
177     VIEW_DETAILS,
178     COPY_UUID,
179 ]);
180 export const msReadOnlyProjectActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, COPY_UUID, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS,]);
181 export const msFrozenProjectActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, COPY_UUID, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, FREEZE_PROJECT])
182 export const msAdminFrozenProjectActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, COPY_UUID, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, FREEZE_PROJECT, ADD_TO_PUBLIC_FAVORITES])
183
184 export const msFilterGroupActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, COPY_UUID, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, MOVE_TO_TRASH, EDIT_PROJECT, MOVE_TO])
185 export const msAdminFilterGroupActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, COPY_UUID, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, MOVE_TO_TRASH, EDIT_PROJECT, MOVE_TO, ADD_TO_PUBLIC_FAVORITES])