Skip to content

Commit 13cbca6

Browse files
committed
Implement reusable useHasNonGenuineConnections hook
1 parent 63edfa1 commit 13cbca6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

packages/compass-app-stores/src/provider.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
dataServiceLocator,
33
useConnectionInfo,
4+
useConnectionIds,
45
} from '@mongodb-js/compass-connections/provider';
56
import {
67
createServiceLocator,
@@ -93,6 +94,32 @@ export const mongoDBInstanceLocator = createServiceLocator(
9394
'mongoDBInstanceLocator'
9495
);
9596

97+
/**
98+
* Hook to check if there are any connected non-genuine MongoDB connections.
99+
* @return true if any connected connection is to a non-genuine MongoDB server.
100+
*/
101+
export function useHasNonGenuineConnections(): boolean {
102+
const instancesManager = mongoDBInstancesManagerLocator();
103+
104+
const activeNonGenuineConnectionIds = useConnectionIds((conn) => {
105+
if (conn.status !== 'connected') {
106+
return false;
107+
}
108+
109+
try {
110+
const instance = instancesManager.getMongoDBInstanceForConnection(
111+
conn.info.id
112+
);
113+
return instance.genuineMongoDB.isGenuine === false;
114+
} catch {
115+
// Instance not found or not ready yet
116+
return false;
117+
}
118+
});
119+
120+
return activeNonGenuineConnectionIds.length > 0;
121+
}
122+
96123
const NamespaceModelContext = React.createContext<Database | Collection | null>(
97124
null
98125
);

0 commit comments

Comments
 (0)