Skip to content

Commit 01cf00a

Browse files
committed
comments
1 parent dd54676 commit 01cf00a

File tree

5 files changed

+23
-36
lines changed

5 files changed

+23
-36
lines changed

packages/compass-connections-navigation/src/connections-navigation-tree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
spacing,
1919
useId,
2020
} from '@mongodb-js/compass-components';
21-
import { useConnectableRef } from '@mongodb-js/compass-connections/provider';
21+
import { useConnectable } from '@mongodb-js/compass-connections/provider';
2222
import type { WorkspaceTab } from '@mongodb-js/compass-workspaces';
2323
import { usePreference } from 'compass-preferences-model/provider';
2424
import type { NavigationItemActions } from './item-actions';
@@ -58,7 +58,7 @@ const ConnectionsNavigationTree: React.FunctionComponent<
5858
);
5959

6060
const id = useId();
61-
const { getConnectable } = useConnectableRef();
61+
const getConnectable = useConnectable();
6262

6363
const treeData = useMemo(() => {
6464
return getVirtualTreeItems({

packages/compass-connections-navigation/src/styled-navigation-item.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export default function StyledNavigationItem({
3030
() => (isDarkMode ? palette.gray.light1 : palette.gray.dark1),
3131
[isDarkMode]
3232
);
33-
34-
const connectionId = getConnectionId(item);
35-
const isConnectable = useConnectable(connectionId);
33+
const getConnectable = useConnectable();
3634

3735
const style: React.CSSProperties & AcceptedStyles = useMemo(() => {
3836
const style: AcceptedStyles = {};
37+
const connectionId = getConnectionId(item);
38+
const isConnectable = getConnectable(connectionId);
3939
const isDisconnectedConnection =
4040
item.type === 'connection' && item.connectionStatus !== 'connected';
4141
const isNonExistentNamespace =
@@ -59,9 +59,9 @@ export default function StyledNavigationItem({
5959
return style;
6060
}, [
6161
inactiveColor,
62-
isConnectable,
6362
item,
6463
colorCode,
64+
getConnectable,
6565
connectionColorToHex,
6666
connectionColorToHexActive,
6767
]);
Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
1-
import { useSelector, useStore } from '../stores/store-context';
2-
import { useRef, useState } from 'react';
1+
import { useStore } from '../stores/store-context';
2+
import { useCallback } from 'react';
33
import { connectable } from '../utils/connection-supports';
44

5-
export function useConnectable(connectionId: string): boolean {
6-
return useSelector((state) => {
7-
const connection = state.connections.byId[connectionId];
5+
export function useConnectable(): (connectionId: string) => boolean {
6+
const store = useStore();
7+
const getConnectable = useCallback(
8+
(connectionId: string) => {
9+
const conn = store.getState().connections.byId[connectionId];
10+
if (!conn) {
11+
return false;
12+
}
813

9-
if (!connection) {
10-
return false;
11-
}
14+
return connectable(conn.info);
15+
},
16+
[store]
17+
);
1218

13-
return connectable(connection.info);
14-
});
15-
}
16-
17-
export function useConnectableRef(): {
18-
getConnectable(this: void, connectionId: string): boolean;
19-
} {
20-
const storeRef = useRef(useStore());
21-
const [ref] = useState(() => {
22-
return {
23-
getConnectable(connectionId: string) {
24-
const conn = storeRef.current.getState().connections.byId[connectionId];
25-
if (!conn) {
26-
return false;
27-
}
28-
29-
return connectable(conn.info);
30-
},
31-
};
32-
});
33-
return ref;
19+
return getConnectable;
3420
}

packages/compass-connections/src/provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export type { ConnectionsService } from './stores/store-context';
6969

7070
export { useConnectionSupports } from './hooks/use-connection-supports';
7171

72-
export { useConnectable, useConnectableRef } from './hooks/use-connectable';
72+
export { useConnectable } from './hooks/use-connectable';
7373

7474
const ConnectionStatus = {
7575
/**

packages/compass-web/src/connection-storage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ const VISIBLE_CLUSTER_STATES: AtlasClusterMetadata['clusterState'][] = [
254254
'PAUSED',
255255
'CREATING',
256256
'DELETING',
257+
'DELETED',
257258
];
258259

259260
/**

0 commit comments

Comments
 (0)