-
Notifications
You must be signed in to change notification settings - Fork 244
chore(data-service): use identifyServerName from mongodb-build-info COMPASS-9930
#7507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f8c61c8
02bda77
dd4a17f
f89f301
2b11c54
5fe10f1
6ab09ca
8fa3973
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ import type { MongoDBInstanceProps } from 'mongodb-instance-model'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { MongoDBInstance } from 'mongodb-instance-model'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import React, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createContext, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useCallback, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useContext, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useMemo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+118
to
+132
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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]); | |
| const [result, setResult] = useState(() => hasNonGenuineConnections()); | |
| useEffect(() => { | |
| if (instancesManager) { | |
| const updateResult = () => { | |
| setResult(hasNonGenuineConnections()); | |
| }; | |
| instancesManager.on('instance-started', updateResult); | |
| instancesManager.on('instance-removed', updateResult); | |
| // Set initial value in case the event hasn't fired yet | |
| updateResult(); | |
| return () => { | |
| instancesManager.off('instance-started', updateResult); | |
| instancesManager.off('instance-removed', updateResult); | |
| }; | |
| } | |
| }, [instancesManager]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot it's already wrapped in useCallback? 🙃
Uh oh!
There was an error while loading. Please reload this page.