21535: changed wf and process to use new delete icon Arvados-DCO-1.1-Signed-off-by...
[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 { MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions";
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 } from 'components/icon/icon';
16 import { RestoreFromTrashIcon, TrashIcon, FolderSharedIcon, Link } from 'components/icon/icon';
17 import { getResource } from 'store/resources/resources';
18 import { openProjectCreateDialog } from 'store/projects/project-create-actions';
19 import { openProjectUpdateDialog } from 'store/projects/project-update-actions';
20 import { freezeProject, unfreezeProject } from 'store/projects/project-lock-actions';
21 import { openWebDavS3InfoDialog } from 'store/collections/collection-info-actions';
22 import { copyToClipboardAction } from 'store/open-in-new-tab/open-in-new-tab.actions';
23
24 const {
25     ADD_TO_FAVORITES,
26     ADD_TO_PUBLIC_FAVORITES,
27     OPEN_IN_NEW_TAB,
28     COPY_TO_CLIPBOARD,
29     VIEW_DETAILS,
30     API_DETAILS,
31     OPEN_W_3RD_PARTY_CLIENT,
32     EDIT_PROJECT,
33     SHARE,
34     MOVE_TO,
35     MOVE_TO_TRASH,
36     FREEZE_PROJECT,
37     NEW_PROJECT,
38 } = MultiSelectMenuActionNames;
39
40 const msCopyToClipboardMenuAction: MultiSelectMenuAction  = {
41     name: COPY_TO_CLIPBOARD,
42     icon: Link,
43     hasAlts: false,
44     isForMulti: false,
45     execute: (dispatch, resources) => {
46         dispatch<any>(copyToClipboardAction(resources));
47     },
48 };
49
50 const msEditProjectAction: MultiSelectMenuAction = {
51     name: EDIT_PROJECT,
52     icon: RenameIcon,
53     hasAlts: false,
54     isForMulti: false,
55     execute: (dispatch, resources) => {
56         dispatch<any>(openProjectUpdateDialog(resources[0]));
57     },
58 };
59
60 const msMoveToAction: MultiSelectMenuAction = {
61     name: MOVE_TO,
62     icon: MoveToIcon,
63     hasAlts: false,
64     isForMulti: true,
65     execute: (dispatch, resource) => {
66         dispatch<any>(openMoveProjectDialog(resource[0]));
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 msToggleTrashAction: MultiSelectMenuAction = {
81     name: MOVE_TO_TRASH,
82     icon: TrashIcon,
83     hasAlts: true,
84     altName: 'Restore from Trash',
85     altIcon: RestoreFromTrashIcon,
86     isForMulti: true,
87     useAlts: (uuid, iconProps) => {
88         return uuid ? (getResource(uuid)(iconProps.resources) as any).isTrashed : false;
89     },
90     execute: (dispatch, resources) => {
91         for (const resource of [...resources]) {
92             dispatch<any>(toggleProjectTrashed(resource.uuid, resource.ownerUuid, resource.isTrashed!!, resources.length > 1));
93         }
94     },
95 };
96
97 const msFreezeProjectAction: MultiSelectMenuAction = {
98     name: FREEZE_PROJECT,
99     icon: FreezeIcon,
100     hasAlts: true,
101     altName: 'Unfreeze Project',
102     altIcon: UnfreezeIcon,
103     isForMulti: false,
104     useAlts: (uuid, iconProps) => {
105         return uuid ? !!(getResource(uuid)(iconProps.resources) as any).frozenByUuid : false;
106     },
107     execute: (dispatch, resources) => {
108         if ((resources[0] as any).frozenByUuid) {
109             dispatch<any>(unfreezeProject(resources[0].uuid));
110         } else {
111             dispatch<any>(freezeProject(resources[0].uuid));
112         }
113     },
114 };
115
116 const msNewProjectAction: MultiSelectMenuAction = {
117     name: NEW_PROJECT,
118     icon: NewProjectIcon,
119     hasAlts: false,
120     isForMulti: false,
121     execute: (dispatch, resources): void => {
122         dispatch<any>(openProjectCreateDialog(resources[0].uuid));
123     },
124 };
125
126 export const msProjectActionSet: MultiSelectMenuActionSet = [
127     [
128         ...msCommonActionSet,
129         msEditProjectAction,
130         msMoveToAction,
131         msToggleTrashAction,
132         msNewProjectAction,
133         msFreezeProjectAction,
134         msOpenWith3rdPartyClientAction,
135         msCopyToClipboardMenuAction
136     ],
137 ];
138
139 export const msCommonProjectActionFilter = new Set<string>([
140     ADD_TO_FAVORITES,
141     MOVE_TO_TRASH,
142     API_DETAILS,
143     COPY_TO_CLIPBOARD,
144     EDIT_PROJECT,
145     FREEZE_PROJECT,
146     MOVE_TO,
147     NEW_PROJECT,
148     OPEN_IN_NEW_TAB,
149     OPEN_W_3RD_PARTY_CLIENT,
150     SHARE,
151     VIEW_DETAILS,
152 ]);
153 export const msReadOnlyProjectActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_W_3RD_PARTY_CLIENT, VIEW_DETAILS,]);
154 export const msFrozenProjectActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_W_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, FREEZE_PROJECT])
155 export const msAdminFrozenProjectActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_W_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, FREEZE_PROJECT, ADD_TO_PUBLIC_FAVORITES])
156
157 export const msFilterGroupActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_W_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, MOVE_TO_TRASH, EDIT_PROJECT, MOVE_TO])
158 export const msAdminFilterGroupActionFilter = new Set<string>([ADD_TO_FAVORITES, API_DETAILS, COPY_TO_CLIPBOARD, OPEN_IN_NEW_TAB, OPEN_W_3RD_PARTY_CLIENT, VIEW_DETAILS, SHARE, MOVE_TO_TRASH, EDIT_PROJECT, MOVE_TO, ADD_TO_PUBLIC_FAVORITES])