File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {
20
20
ButtonVariant ,
21
21
cx ,
22
22
Placeholder ,
23
+ useContextMenuItems ,
23
24
} from '@mongodb-js/compass-components' ;
24
25
import { ConnectionsNavigationTree } from '@mongodb-js/compass-connections-navigation' ;
25
26
import type { MapDispatchToProps , MapStateToProps } from 'react-redux' ;
@@ -484,6 +485,15 @@ const ConnectionsNavigation: React.FC<ConnectionsNavigationProps> = ({
484
485
[ onCollapseAll , onNewConnection , openConnectionImportExportModal ]
485
486
) ;
486
487
488
+ const ref = useContextMenuItems (
489
+ ( ) =>
490
+ connectionListTitleActions . map ( ( { label, action } ) => ( {
491
+ label,
492
+ onAction : ( ) => onConnectionListTitleAction ( action ) ,
493
+ } ) ) ,
494
+ [ connectionListTitleActions , onConnectionListTitleAction ]
495
+ ) ;
496
+
487
497
// auto-expanding on a workspace change
488
498
useEffect ( ( ) => {
489
499
if (
@@ -516,7 +526,7 @@ const ConnectionsNavigation: React.FC<ConnectionsNavigationProps> = ({
516
526
) : undefined ;
517
527
518
528
return (
519
- < div className = { connectionsContainerStyles } >
529
+ < div className = { connectionsContainerStyles } ref = { ref } >
520
530
< div
521
531
className = { connectionListHeaderStyles }
522
532
data-testid = "connections-header"
Original file line number Diff line number Diff line change @@ -240,6 +240,25 @@ describe('Multiple Connections Sidebar Component', function () {
240
240
) . to . equal ( 'Search clusters' ) ;
241
241
} ) ;
242
242
} ) ;
243
+
244
+ it ( 'should have context-menu with expected actions' , function ( ) {
245
+ doRender ( undefined , [ ] ) ;
246
+ const header = screen . getByTestId ( 'connections-header' ) ;
247
+ userEvent . click ( header , { button : 2 } ) ;
248
+ const menu = screen . getByTestId ( 'context-menu' ) ;
249
+ expect ( within ( menu ) . getByTestId ( 'menu-group-0-item-0' ) ) . to . have . text (
250
+ 'Collapse all connections'
251
+ ) ;
252
+ expect ( within ( menu ) . getByTestId ( 'menu-group-0-item-1' ) ) . to . have . text (
253
+ 'Add new connection'
254
+ ) ;
255
+ expect ( within ( menu ) . getByTestId ( 'menu-group-0-item-2' ) ) . to . have . text (
256
+ 'Import connections'
257
+ ) ;
258
+ expect ( within ( menu ) . getByTestId ( 'menu-group-0-item-3' ) ) . to . have . text (
259
+ 'Export connections'
260
+ ) ;
261
+ } ) ;
243
262
} ) ;
244
263
245
264
describe ( 'connections list' , function ( ) {
You can’t perform that action at this time.
0 commit comments