-
Notifications
You must be signed in to change notification settings - Fork 247
feat: update atlas cluster states COMPASS-8228 #6884
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3b30da4
init
syn-zhu e12899d
refactor
syn-zhu 82b9518
Update base-navigation-item.tsx
syn-zhu 8f1a3f1
Update connections-store-redux.ts
syn-zhu b96fb95
Refactor
syn-zhu 6b232a9
Update connection-storage.tsx
syn-zhu 2860e70
refactor
syn-zhu 68b30a4
Update base-navigation-item.tsx
syn-zhu 2a14569
remove unused'
syn-zhu dd54676
Revert "remove unused'"
syn-zhu 01cf00a
comments
syn-zhu 2bce9f0
Update connections-store-redux.ts
syn-zhu 8a70b1c
Update connections-store-redux.ts
syn-zhu 291d6cf
fix tests
syn-zhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { useStore } from '../stores/store-context'; | ||
| import { useCallback } from 'react'; | ||
| import { connectable } from '../utils/connection-supports'; | ||
|
|
||
| export function useConnectable(): (connectionId: string) => boolean { | ||
| const store = useStore(); | ||
| const getConnectable = useCallback( | ||
| (connectionId: string) => { | ||
| const conn = store.getState().connections.byId[connectionId]; | ||
| if (!conn) { | ||
| return false; | ||
| } | ||
|
|
||
| return connectable(conn.info); | ||
| }, | ||
| [store] | ||
| ); | ||
|
|
||
| return getConnectable; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ import EventEmitter from 'events'; | |
| import { showNonGenuineMongoDBWarningModal as _showNonGenuineMongoDBWarningModal } from '../components/non-genuine-connection-modal'; | ||
| import ConnectionString from 'mongodb-connection-string-url'; | ||
| import type { ExtraConnectionData as ExtraConnectionDataForTelemetry } from '@mongodb-js/compass-telemetry'; | ||
| import { connectable } from '../utils/connection-supports'; | ||
|
|
||
| export type ConnectionsEventMap = { | ||
| connected: ( | ||
|
|
@@ -530,9 +531,12 @@ function mergeConnections( | |
| ? newConnections | ||
| : [newConnections]; | ||
|
|
||
| const removedConnectionIds = new Set(connectionsState.ids); | ||
|
|
||
| let newConnectionsById = connectionsState.byId; | ||
|
|
||
| for (const connectionInfo of newConnections) { | ||
| removedConnectionIds.delete(connectionInfo.id); | ||
| const existingConnection = newConnectionsById[connectionInfo.id]; | ||
|
|
||
| // If we got a new connection, just create a default state for this | ||
|
|
@@ -557,6 +561,30 @@ function mergeConnections( | |
| info: connectionInfo, | ||
| }, | ||
| }; | ||
|
|
||
| // TODO: if an Atlas connection is going from PAUSED state to unpaused, we should | ||
syn-zhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // reconnect the data service, since it would previously have been disconnected | ||
| // due to non-retryable error code. | ||
| } | ||
| } | ||
|
|
||
| // If an Atlas connection was removed, it means that the cluster was deleted | ||
| for (const connectionId of removedConnectionIds) { | ||
| const removedConnection = newConnectionsById[connectionId]; | ||
| if (removedConnection.info.atlasMetadata) { | ||
| newConnectionsById = { | ||
| ...newConnectionsById, | ||
| [connectionId]: { | ||
| ...removedConnection, | ||
| info: { | ||
| ...removedConnection.info, | ||
| atlasMetadata: { | ||
| ...removedConnection.info.atlasMetadata, | ||
| clusterState: 'DELETED', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1399,7 +1427,9 @@ function getDescriptionForNonRetryableError(error: Error): string { | |
| // to the generic error description. | ||
| const reason = error.message.match(/code: \d+, reason: (.*)$/)?.[1]; | ||
| return reason && reason.length > 0 | ||
| ? reason | ||
| ? reason.endsWith('.') | ||
| ? reason.slice(0, -1) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL negative numbers work with slice |
||
| : reason // Remove trailing period | ||
| : NonRetryableErrorDescriptionFallbacks[ | ||
| Number( | ||
| error.message.match(/code: (\d+),/)?.[1] | ||
|
|
@@ -1489,6 +1519,10 @@ const connectWithOptions = ( | |
| return; | ||
| } | ||
|
|
||
| if (!connectable(connectionInfo)) { | ||
| return; | ||
| } | ||
|
|
||
| const isAutoconnectAttempt = isAutoconnectInfo( | ||
| getState(), | ||
| connectionInfo.id | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.