-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathconstants.ts
More file actions
271 lines (253 loc) · 9.76 KB
/
constants.ts
File metadata and controls
271 lines (253 loc) · 9.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import {
ArrowShapeTurnUpRight,
Clock,
CodeTrunk,
Copy,
FolderArrowDown,
FontCursor,
Link,
Tag,
TrashBin,
} from '@gravity-ui/icons';
import type {ConnectorType} from 'shared/constants/connections';
import {ActionPanelEntryContextMenuQa} from 'shared/constants/qa/action-panel';
import {S3_BASED_CONNECTORS} from 'ui/constants/connections';
import {isEnabledFeature} from 'ui/utils/isEnabledFeature';
import {EntryScope, Feature, PLACE, isUsersFolder} from '../../../shared';
import {URL_QUERY} from '../../constants';
import {registry} from '../../registry';
import type {ContextMenuItem, ContextMenuParams} from './types';
import iconId from 'ui/assets/icons/id-square.svg';
export const ENTRY_CONTEXT_MENU_ACTION = {
RENAME: 'rename',
ADD_FAVORITES_ALIAS: 'add-favorites-alias',
EDIT_FAVORITES_ALIAS: 'edit-favorites-alias',
DELETE: 'delete',
MOVE: 'move',
COPY: 'copy',
ACCESS: 'access',
COPY_LINK: 'copy-link',
COPY_ID: 'copy-id',
SHARE: 'share',
REVISIONS: 'revisions',
MIGRATE_TO_WORKBOOK: 'migrate-to-workbook',
SHOW_RELATED_ENTITIES: 'show-related-entities',
} as const;
const CONTEXT_MENU_COPY = {
id: ENTRY_CONTEXT_MENU_ACTION.COPY,
action: ENTRY_CONTEXT_MENU_ACTION.COPY,
icon: Copy,
qa: ActionPanelEntryContextMenuQa.Copy,
text: 'value_duplicate',
enable: () => isEnabledFeature(Feature.EntryMenuItemCopy),
permissions: (entry: ContextMenuParams['entry']) => {
return entry?.workbookId
? {admin: true, edit: true, read: false, execute: false}
: undefined;
},
// remain Copy menu item in navigation, but show in actionPanel only if actual version is opened
isVisible({showSpecificItems, entry}: ContextMenuParams) {
if (!showSpecificItems && entry?.workbookId) {
return false;
}
const searchParams = new URLSearchParams(window.location.search);
const revId = searchParams.get(URL_QUERY.REV_ID);
return showSpecificItems ? !revId : true;
},
};
export const CONTEXT_MENU_COPY_LINK = {
id: ENTRY_CONTEXT_MENU_ACTION.COPY_LINK,
action: ENTRY_CONTEXT_MENU_ACTION.COPY_LINK,
icon: Link,
text: 'value_copy-link',
enable: () => true,
};
export const CONTEXT_MENU_COPY_ID = {
id: ENTRY_CONTEXT_MENU_ACTION.COPY_ID,
action: ENTRY_CONTEXT_MENU_ACTION.COPY_ID,
icon: iconId,
text: 'value_copy-id',
enable: () => true,
};
const getContextMenuAccess = () => {
const getAccessItem = registry.common.functions.get('getAccessEntryMenuItem');
return getAccessItem();
};
const getContextMenuMoveToWorkbooks = () => {
const getMoveToWorkbooksItem = registry.common.functions.get('getMoveToWorkbooksMenuItem');
return getMoveToWorkbooksItem();
};
const getAdditionalEntryContextMenuItems = (): ContextMenuItem[] => {
const fn = registry.common.functions.get('getAdditionalEntryContextMenuItems');
return fn();
};
const isVisibleEntryContextShareItem = ({entry, showSpecificItems}: ContextMenuParams): boolean =>
entry?.scope === EntryScope.Dash &&
showSpecificItems &&
isEnabledFeature(Feature.EnableEntryMenuItemShare);
export const getEntryContextMenu = (): ContextMenuItem[] => {
const {getTopLevelEntryScopes, getAllEntryScopes, getEntryScopesWithRevisionsList} =
registry.common.functions.getAll();
return [
{
id: ENTRY_CONTEXT_MENU_ACTION.REVISIONS,
action: ENTRY_CONTEXT_MENU_ACTION.REVISIONS,
icon: Clock,
text: 'value_revisions',
qa: ActionPanelEntryContextMenuQa.Revisions,
enable: () => true,
scopes: getAllEntryScopes(),
isSpecific: true,
isOnEditMode: false,
permissions: () => ({admin: true, edit: true, read: false, execute: false}),
isVisible({entry, isLimitedView}: ContextMenuParams) {
if (!entry || !entry.scope || isLimitedView) return false;
return getEntryScopesWithRevisionsList().includes(entry.scope as EntryScope);
},
},
{
id: ENTRY_CONTEXT_MENU_ACTION.RENAME,
action: ENTRY_CONTEXT_MENU_ACTION.RENAME,
icon: FontCursor,
text: 'value_rename',
enable: () => true,
permissions: (entry: ContextMenuParams['entry']) => {
// allow renaming entries in the workbook with the "edit" permission
return entry?.workbookId
? {admin: true, edit: true, read: false, execute: false}
: {admin: true, edit: false, read: false, execute: false};
},
scopes: getAllEntryScopes(),
isVisible({entry}: ContextMenuParams) {
return !isUsersFolder(entry?.key);
},
},
{
id: ENTRY_CONTEXT_MENU_ACTION.ADD_FAVORITES_ALIAS,
action: ENTRY_CONTEXT_MENU_ACTION.ADD_FAVORITES_ALIAS,
icon: Tag,
text: 'value_add-favorites-alias',
place: PLACE.FAVORITES,
enable: () => true,
scopes: getAllEntryScopes(),
isVisible({entry}: ContextMenuParams) {
return !entry?.displayAlias;
},
},
{
id: ENTRY_CONTEXT_MENU_ACTION.EDIT_FAVORITES_ALIAS,
action: ENTRY_CONTEXT_MENU_ACTION.EDIT_FAVORITES_ALIAS,
icon: Tag,
text: 'value_edit-favorites-alias',
place: PLACE.FAVORITES,
enable: () => true,
scopes: getAllEntryScopes(),
isVisible({entry}: ContextMenuParams) {
return Boolean(entry?.displayAlias);
},
},
{
id: ENTRY_CONTEXT_MENU_ACTION.DELETE,
action: ENTRY_CONTEXT_MENU_ACTION.DELETE,
icon: TrashBin,
text: 'value_delete',
enable: () => true,
permissions: (entry: ContextMenuParams['entry']) => {
// allow deleting an entry in the workbook with the "edit" permission
return entry?.workbookId
? {admin: true, edit: true, read: false, execute: false}
: {admin: true, edit: false, read: false, execute: false};
},
scopes: getAllEntryScopes(),
isVisible({entry}: ContextMenuParams) {
return !isUsersFolder(entry?.key);
},
qa: ActionPanelEntryContextMenuQa.Remove,
},
{
id: ENTRY_CONTEXT_MENU_ACTION.MOVE,
action: ENTRY_CONTEXT_MENU_ACTION.MOVE,
icon: FolderArrowDown,
text: 'value_move',
enable: () => isEnabledFeature(Feature.EntryMenuItemMove),
permissions: {admin: true, edit: false, read: false, execute: false},
scopes: getAllEntryScopes(),
isVisible({entry}: ContextMenuParams) {
return !isUsersFolder(entry?.key) && !entry?.workbookId;
},
},
// different Copy menu for dash/widgets and datasets/configs
{
...CONTEXT_MENU_COPY,
scopes: [EntryScope.Widget, ...getTopLevelEntryScopes()],
// allow to show if there are no permissions
},
{
...CONTEXT_MENU_COPY,
scopes: [EntryScope.Connection],
permissions: {admin: true, edit: true, read: false, execute: false},
isStrictPermissions: true, // strict check with disallow when there are no permissions object
isVisible(args) {
const entry = args.entry;
const isS3BasedConnector = S3_BASED_CONNECTORS.includes(
entry?.type as ConnectorType,
);
const isFileConnection =
entry?.scope === EntryScope.Connection && isS3BasedConnector;
if (!args.entry?.workbookId || isFileConnection) {
return false;
}
return CONTEXT_MENU_COPY.isVisible(args);
},
},
{
...CONTEXT_MENU_COPY,
scopes: [EntryScope.Dataset],
permissions: {admin: true, edit: true, read: false, execute: false},
isStrictPermissions: true, // strict check with disallow when there are no permissions object
},
getContextMenuAccess(),
{
...CONTEXT_MENU_COPY_LINK,
scopes: getAllEntryScopes(),
isVisible: (params) =>
!isVisibleEntryContextShareItem(params) &&
!isEnabledFeature(Feature.EnableNewAccessDialog),
},
{
...CONTEXT_MENU_COPY_ID,
scopes: [
EntryScope.Widget,
EntryScope.Dataset,
EntryScope.Connection,
...getTopLevelEntryScopes(),
],
},
{
id: ENTRY_CONTEXT_MENU_ACTION.SHARE,
action: ENTRY_CONTEXT_MENU_ACTION.SHARE,
icon: ArrowShapeTurnUpRight,
text: 'value_share',
enable: () => true,
scopes: getAllEntryScopes(),
isVisible: (params) =>
isVisibleEntryContextShareItem(params) &&
!isEnabledFeature(Feature.EnableNewAccessDialog),
},
{
id: ENTRY_CONTEXT_MENU_ACTION.SHOW_RELATED_ENTITIES,
action: ENTRY_CONTEXT_MENU_ACTION.SHOW_RELATED_ENTITIES,
icon: CodeTrunk,
text: 'value_show-related-entities',
enable: () => true,
scopes: [
EntryScope.Widget,
EntryScope.Dataset,
EntryScope.Connection,
...getTopLevelEntryScopes(),
],
},
...getAdditionalEntryContextMenuItems(),
getContextMenuMoveToWorkbooks(),
];
};