Skip to content

Commit d71c4cf

Browse files
committed
rf: combine and cleanup actions and remove type cast
1 parent 2424a9e commit d71c4cf

File tree

2 files changed

+80
-93
lines changed

2 files changed

+80
-93
lines changed

packages/compass-connections-navigation/src/context-menus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function itemActionsToContextMenuGroups(
1616
actions.map(({ label, action }) => ({
1717
label,
1818
onAction() {
19-
onItemAction(item, action as Actions);
19+
onItemAction(item, action);
2020
},
2121
}))
2222
);

packages/compass-connections-navigation/src/item-actions.ts

Lines changed: 79 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,47 @@ export const collectionItemActions = ({
246246
return actions;
247247
};
248248

249+
const connectionContextMenuActions = ({
250+
isPerformanceTabAvailable,
251+
isPerformanceTabSupported,
252+
isAtlas,
253+
}: {
254+
isPerformanceTabAvailable: boolean;
255+
isPerformanceTabSupported: boolean;
256+
isAtlas: boolean;
257+
}): NavigationItemActions => {
258+
return stripNullActions([
259+
isPerformanceTabAvailable
260+
? {
261+
action: 'connection-performance-metrics',
262+
icon: 'Gauge',
263+
label: 'View performance metrics',
264+
isDisabled: !isPerformanceTabSupported,
265+
disabledDescription: 'Not supported',
266+
}
267+
: null,
268+
isAtlas
269+
? null
270+
: {
271+
action: 'open-connection-info',
272+
icon: 'InfoWithCircle',
273+
label: 'Show connection info',
274+
},
275+
{
276+
action: 'refresh-databases',
277+
label: 'Refresh databases',
278+
icon: 'Refresh',
279+
},
280+
{ separator: true },
281+
{
282+
action: 'connection-disconnect',
283+
icon: 'Disconnect',
284+
label: 'Disconnect',
285+
variant: 'destructive',
286+
},
287+
]);
288+
};
289+
249290
export const databaseContextMenuActions = ({
250291
hasWriteActionsDisabled,
251292
isShellEnabled,
@@ -291,42 +332,18 @@ export const databaseContextMenuActions = ({
291332
label: 'Open MongoDB shell',
292333
}
293334
: null,
294-
isPerformanceTabAvailable
295-
? {
296-
action: 'connection-performance-metrics',
297-
icon: 'Gauge',
298-
label: 'View performance metrics',
299-
isDisabled: !isPerformanceTabSupported,
300-
disabledDescription: 'Not supported',
301-
}
302-
: null,
303-
isAtlas
304-
? null
305-
: {
306-
action: 'open-connection-info',
307-
icon: 'InfoWithCircle',
308-
label: 'Show connection info',
309-
},
310-
{
311-
action: 'refresh-databases',
312-
label: 'Refresh databases',
313-
icon: 'Refresh',
314-
},
315-
{ separator: true },
316-
{
317-
action: 'connection-disconnect',
318-
icon: 'Disconnect',
319-
label: 'Disconnect',
320-
variant: 'destructive',
321-
},
335+
...connectionContextMenuActions({
336+
isPerformanceTabAvailable,
337+
isPerformanceTabSupported,
338+
isAtlas,
339+
}),
322340
]);
323341
};
324342

325343
export const collectionContextMenuActions = ({
326344
hasWriteActionsDisabled,
327345
type,
328346
isRenameCollectionEnabled,
329-
isShellEnabled,
330347
isPerformanceTabAvailable,
331348
isPerformanceTabSupported,
332349
isAtlas,
@@ -348,11 +365,11 @@ export const collectionContextMenuActions = ({
348365
},
349366
];
350367

368+
let writeActions: NavigationItemActions = [];
369+
351370
if (!hasWriteActionsDisabled) {
352371
if (type === 'view') {
353-
actions.push({ separator: true });
354-
// For views: show Duplicate view, Modify view, Drop view
355-
actions.push(
372+
writeActions = [
356373
{
357374
action: 'duplicate-view',
358375
label: 'Duplicate view',
@@ -367,70 +384,40 @@ export const collectionContextMenuActions = ({
367384
action: 'drop-collection',
368385
label: 'Drop view',
369386
icon: 'Trash',
370-
}
371-
);
387+
},
388+
];
372389
} else {
373-
actions.push({ separator: true });
374-
// For collections: show Rename collection, Drop collection
375-
if (type !== 'timeseries' && isRenameCollectionEnabled) {
376-
actions.push({
377-
action: 'rename-collection',
378-
label: 'Rename collection',
379-
icon: 'Edit',
380-
});
381-
}
382-
actions.push({
383-
action: 'create-collection',
384-
icon: 'Plus',
385-
label: 'Create collection',
386-
});
387-
actions.push({
388-
action: 'drop-collection',
389-
label: 'Drop collection',
390-
icon: 'Trash',
391-
});
390+
writeActions = stripNullActions([
391+
type !== 'timeseries' && isRenameCollectionEnabled
392+
? {
393+
action: 'rename-collection',
394+
label: 'Rename collection',
395+
icon: 'Edit',
396+
}
397+
: null,
398+
{
399+
action: 'create-collection',
400+
icon: 'Plus',
401+
label: 'Create collection',
402+
},
403+
{
404+
action: 'drop-collection',
405+
label: 'Drop collection',
406+
icon: 'Trash',
407+
},
408+
]);
392409
}
393410
}
394411

395-
// Add connection-level actions
396-
const connectionActions = stripNullActions([
412+
return [
413+
...actions,
397414
{ separator: true },
398-
isShellEnabled
399-
? {
400-
action: 'open-shell',
401-
icon: 'Shell',
402-
label: 'Open MongoDB shell',
403-
}
404-
: null,
405-
isPerformanceTabAvailable
406-
? {
407-
action: 'connection-performance-metrics',
408-
icon: 'Gauge',
409-
label: 'View performance metrics',
410-
isDisabled: !isPerformanceTabSupported,
411-
disabledDescription: 'Not supported',
412-
}
413-
: null,
414-
isAtlas
415-
? null
416-
: {
417-
action: 'open-connection-info',
418-
icon: 'InfoWithCircle',
419-
label: 'Show connection info',
420-
},
421-
{
422-
action: 'refresh-databases',
423-
label: 'Refresh collection',
424-
icon: 'Refresh',
425-
},
415+
...writeActions,
426416
{ separator: true },
427-
{
428-
action: 'connection-disconnect',
429-
icon: 'Disconnect',
430-
label: 'Disconnect',
431-
variant: 'destructive',
432-
},
433-
]);
434-
435-
return [...actions, ...connectionActions];
417+
...connectionContextMenuActions({
418+
isPerformanceTabAvailable,
419+
isPerformanceTabSupported,
420+
isAtlas,
421+
}),
422+
];
436423
};

0 commit comments

Comments
 (0)