Merge branch '21901-file-log-throttling'
[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 } from 'components/icon/icon';
17 import { RestoreFromTrashIcon, TrashIcon, FolderSharedIcon, Link } from 'components/icon/icon';
18 import { getResource } from 'store/resources/resources';
19 import { openProjectCreateDialog } from 'store/projects/project-create-actions';
20 import { openProjectUpdateDialog } from 'store/projects/project-update-actions';
21 import { freezeProject, unfreezeProject } from 'store/projects/project-lock-actions';
22 import { openWebDavS3InfoDialog } from 'store/collections/collection-info-actions';
23 import { copyToClipboardAction } from 'store/open-in-new-tab/open-in-new-tab.actions';
24 import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
25
26 const {
27     ADD_TO_FAVORITES,
28     ADD_TO_PUBLIC_FAVORITES,
29     OPEN_IN_NEW_TAB,
30     COPY_LINK_TO_CLIPBOARD,
31     VIEW_DETAILS,
32     API_DETAILS,
33     OPEN_WITH_3RD_PARTY_CLIENT,
34     EDIT_PROJECT,
35     SHARE,
36     MOVE_TO,
37     MOVE_TO_TRASH,
38     FREEZE_PROJECT,
39     NEW_PROJECT,
40 } = ContextMenuActionNames;
41
42 const msCopyToClipboardMenuAction: MultiSelectMenuAction  = {
43     name: COPY_LINK_TO_CLIPBOARD,
44     icon: Link,
45     hasAlts: false,
46     isForMulti: false,
47     execute: (dispatch, resources) => {
48         dispatch<any>(copyToClipboardAction(resources));
49     },
50 };
51
52 const msEditProjectAction: MultiSelectMenuAction = {
53     name: EDIT_PROJECT,
54     icon: RenameIcon,
55     hasAlts: false,
56     isForMulti: false,
57     execute: (dispatch, resources) => {
58         dispatch<any>(openProjectUpdateDialog(resources[0]));
59     },
60 };
61
62 const msMoveToAction: MultiSelectMenuAction = {
63     name: MOVE_TO,
64     icon: MoveToIcon,
65     hasAlts: false,
66     isForMulti: true,
67     execute: (dispatch, resource) => {
68         dispatch<any>(openMoveProjectDialog(resource[0]));
69     },
70 };
71
72 const msOpenWith3rdPartyClientAction: MultiSelectMenuAction  = {
73     name: OPEN_WITH_3RD_PARTY_CLIENT,
74     icon: FolderSharedIcon,
75     hasAlts: false,
76     isForMulti: false,
77     execute: (dispatch, resources) => {
78         dispatch<any>(openWebDavS3InfoDialog(resources[0].uuid));
79     },
80 };
81
82 export const msToggleTrashAction: MultiSelectMenuAction = {
83     name: MOVE_TO_TRASH,
84     icon: TrashIcon,
85     hasAlts: true,
86     altName: 'Restore from Trash',
87     altIcon: RestoreFromTrashIcon,
88     isForMulti: true,
89     useAlts: (uuid, iconProps) => {
90         return uuid ? (getResource(uuid)(iconProps.resources) as any)?.isTrashed : false;
91     },
92     execute: (dispatch, resources) => {
93         for (const resource of [...resources]) {
94             dispatch<any>(toggleProjectTrashed(resource.uuid, resource.ownerUuid, resource.isTrashed!!, resources.length > 1));
95         }
96     },
97 };
98
99 const msFreezeProjectAction: MultiSelectMenuAction = {
100     name: FREEZE_PROJECT,
101     icon: FreezeIcon,
102     hasAlts: true,
103     altName: 'Unfreeze Project',
104     altIcon: UnfreezeIcon,
105     isForMulti: false,
106     useAlts: (uuid, iconProps) => {
107         return uuid ? !!(getResource(uuid)(iconProps.resources) as any).frozenByUuid : false;
108     },
109     execute: (dispatch, resources) => {
110         if ((resources[0] as any).frozenByUuid) {
111             dispatch<any>(unfreezeProject(resources[0].uuid));
112         } else {
113             dispatch<any>(freezeProject(resources[0].uuid));
114         }
115     },
116 };
117
118 const msNewProjectAction: MultiSelectMenuAction = {
119     name: NEW_PROJECT,
120     icon: NewProjectIcon,
121     hasAlts: false,
122     isForMulti: false,
123     execute: (dispatch, resources): void => {
124         dispatch<any>(openProjectCreateDialog(resources[0].uuid));
125     },
126 };
127
128 const msShareAction: MultiSelectMenuAction  = {
129     name: SHARE,
130     icon: ShareIcon,
131     hasAlts: false,
132     isForMulti: false,
133     execute: (dispatch, resources) => {
134         dispatch<any>(openSharingDialog(resources[0].uuid));
135     },
136 };
137
138 export const msProjectActionSet: MultiSelectMenuActionSet = [
139     [
140         ...msCommonActionSet,
141         msEditProjectAction,
142         msMoveToAction,
143         msToggleTrashAction,
144         msNewProjectAction,
145         msFreezeProjectAction,
146         msOpenWith3rdPartyClientAction,
147         msCopyToClipboardMenuAction,
148         msShareAction,
149     ],
150 ];
151
152 export const msCommonProjectActionFilter = new Set<string>([
153     ADD_TO_FAVORITES,
154     MOVE_TO_TRASH,
155     API_DETAILS,
156     COPY_LINK_TO_CLIPBOARD,
157     EDIT_PROJECT,
158     FREEZE_PROJECT,
159     MOVE_TO,
160     NEW_PROJECT,
161     OPEN_IN_NEW_TAB,
162     OPEN_WITH_3RD_PARTY_CLIENT,
163     SHARE,
164     VIEW_DETAILS,
165 ]);
166 export const msReadOnlyProjectActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS,]);
167 export const msFrozenProjectActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, FREEZE_PROJECT])
168 export const msAdminFrozenProjectActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, FREEZE_PROJECT, ADD_TO_PUBLIC_FAVORITES])
169
170 export const msFilterGroupActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, MOVE_TO_TRASH, EDIT_PROJECT, MOVE_TO])
171 export const msAdminFilterGroupActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_LINK_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_WITH_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, MOVE_TO_TRASH, EDIT_PROJECT, MOVE_TO, ADD_TO_PUBLIC_FAVORITES])