Skip to content
Closed
1 change: 1 addition & 0 deletions configs/testing-library-compass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^7.0.2",
"@testing-library/user-event": "^13.5.0",
"mongodb-build-info": "^1.8.1",
"mongodb-connection-string-url": "^3.0.1",
"react": "^17.0.2",
"react-redux": "^8.1.3",
Expand Down
26 changes: 19 additions & 7 deletions configs/testing-library-compass/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
DataService,
InstanceDetails,
} from 'mongodb-data-service';
import { identifyServerName } from 'mongodb-build-info';
import Sinon from 'sinon';
import React from 'react';
import type {
Expand Down Expand Up @@ -175,8 +176,22 @@ export class MockDataService
disconnect(): Promise<void> {
return Promise.resolve();
}
instance(): Promise<InstanceDetails> {
return Promise.resolve({
async instance(): Promise<InstanceDetails> {
const { connectionString } = this.connectionOptions;
const serverName = await identifyServerName({
connectionString,
adminCommand: () =>
Promise.reject(
new Error(
'MockDataService adminCommand: this is a mocked environment; no server commands available.'
)
),
});
const genuineMongoDB = {
serverName,
isGenuine: serverName === 'mongodb' || serverName === 'unknown',
};
return {
auth: {
user: null,
roles: [],
Expand All @@ -188,10 +203,7 @@ export class MockDataService
version: '100.0.0',
},
host: {},
genuineMongoDB: {
isGenuine: true,
dbType: 'mongodb',
},
genuineMongoDB,
dataLake: {
isDataLake: false,
version: null,
Expand All @@ -200,7 +212,7 @@ export class MockDataService
isAtlas: false,
isLocalAtlas: false,
csfleMode: 'unavailable',
});
};
}
}

Expand Down
94 changes: 74 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions packages/compass-app-stores/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { MongoDBInstanceProps } from 'mongodb-instance-model';
import { MongoDBInstance } from 'mongodb-instance-model';
import React, {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
Expand Down Expand Up @@ -93,6 +94,46 @@ export const mongoDBInstanceLocator = createServiceLocator(
'mongoDBInstanceLocator'
);

/**
* Hook to check if there are any connected non-genuine MongoDB connections.
* @return true if any connected connection is to a non-genuine MongoDB server.
*/
export function useHasNonGenuineConnections(): boolean {
const instancesManager = useContext(MongoDBInstancesManagerContext);

const hasNonGenuineConnections = useCallback(
function () {
if (!instancesManager) {
return false;
}
return Array.from(instancesManager.listMongoDBInstances().values()).some(
(instance) => {
return !instance.genuineMongoDB.isGenuine;
}
);
},
[instancesManager]
);

const [result, setResult] = useState(() => hasNonGenuineConnections());

useEffect(() => {
if (instancesManager) {
const updateResult = () => {
setResult(hasNonGenuineConnections);
};
instancesManager.on('instance-started', updateResult);
instancesManager.on('instance-removed', updateResult);
return () => {
instancesManager.off('instance-started', updateResult);
instancesManager.off('instance-removed', updateResult);
};
}
}, [instancesManager, setResult, hasNonGenuineConnections]);

return result;
}

const NamespaceModelContext = React.createContext<Database | Collection | null>(
null
);
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-connections-navigation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@mongodb-js/connection-form": "^1.72.1",
"@mongodb-js/connection-info": "^0.22.0",
"compass-preferences-model": "^2.64.0",
"mongodb-build-info": "^1.7.2",
"mongodb-build-info": "^1.8.1",
"react": "^17.0.2",
"react-virtualized-auto-sizer": "^1.0.6",
"react-window": "^1.8.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-connections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"compass-preferences-model": "^2.64.0",
"lodash": "^4.17.21",
"mongodb": "^6.19.0",
"mongodb-build-info": "^1.7.2",
"mongodb-build-info": "^1.8.1",
"mongodb-connection-string-url": "^3.0.1",
"mongodb-data-service": "^22.34.6",
"react": "^17.0.2",
Expand Down
Loading