1
1
import React , { useCallback , useMemo } from 'react' ;
2
2
import AutoSizer from 'react-virtualized-auto-sizer' ;
3
- import { getVirtualTreeItems } from './tree-data' ;
3
+ import { getConnectionId , getVirtualTreeItems } from './tree-data' ;
4
4
import { ROW_HEIGHT } from './constants' ;
5
5
import type { Actions } from './constants' ;
6
6
import { VirtualTree } from './virtual-list/virtual-list' ;
@@ -18,6 +18,7 @@ import {
18
18
spacing ,
19
19
useId ,
20
20
} from '@mongodb-js/compass-components' ;
21
+ import { useConnectable } from '@mongodb-js/compass-connections/provider' ;
21
22
import type { WorkspaceTab } from '@mongodb-js/compass-workspaces' ;
22
23
import { usePreference } from 'compass-preferences-model/provider' ;
23
24
import type { NavigationItemActions } from './item-actions' ;
@@ -55,8 +56,10 @@ const ConnectionsNavigationTree: React.FunctionComponent<
55
56
const isRenameCollectionEnabled = usePreference (
56
57
'enableRenameCollectionModal'
57
58
) ;
59
+ const showDisabledConnections = ! ! usePreference ( 'showDisabledConnections' ) ;
58
60
59
61
const id = useId ( ) ;
62
+ const getConnectable = useConnectable ( ) ;
60
63
61
64
const treeData = useMemo ( ( ) => {
62
65
return getVirtualTreeItems ( {
@@ -69,6 +72,13 @@ const ConnectionsNavigationTree: React.FunctionComponent<
69
72
70
73
const onDefaultAction : OnDefaultAction < SidebarActionableItem > = useCallback (
71
74
( item , evt ) => {
75
+ if ( showDisabledConnections ) {
76
+ const connectionId = getConnectionId ( item ) ;
77
+ if ( ! getConnectable ( connectionId ) ) {
78
+ return ;
79
+ }
80
+ }
81
+
72
82
if ( item . type === 'connection' ) {
73
83
if ( item . connectionStatus === 'connected' ) {
74
84
onItemAction ( item , 'select-connection' ) ;
@@ -83,7 +93,7 @@ const ConnectionsNavigationTree: React.FunctionComponent<
83
93
}
84
94
}
85
95
} ,
86
- [ onItemAction ]
96
+ [ onItemAction , getConnectable , showDisabledConnections ]
87
97
) ;
88
98
89
99
const activeItemId = useMemo ( ( ) => {
@@ -144,6 +154,14 @@ const ConnectionsNavigationTree: React.FunctionComponent<
144
154
145
155
const getItemActionsAndConfig = useCallback (
146
156
( item : SidebarTreeItem ) => {
157
+ if ( showDisabledConnections ) {
158
+ const connectionId = getConnectionId ( item ) ;
159
+ if ( ! getConnectable ( connectionId ) ) {
160
+ return {
161
+ actions : [ ] ,
162
+ } ;
163
+ }
164
+ }
147
165
switch ( item . type ) {
148
166
case 'placeholder' :
149
167
return {
@@ -192,7 +210,12 @@ const ConnectionsNavigationTree: React.FunctionComponent<
192
210
} ;
193
211
}
194
212
} ,
195
- [ isRenameCollectionEnabled , getCollapseAfterForConnectedItem ]
213
+ [
214
+ isRenameCollectionEnabled ,
215
+ getCollapseAfterForConnectedItem ,
216
+ getConnectable ,
217
+ showDisabledConnections ,
218
+ ]
196
219
) ;
197
220
198
221
const isTestEnv = process . env . NODE_ENV === 'test' ;
0 commit comments