-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: close connection string input when opening form VSCODE-507 (#656)
- Loading branch information
Showing
7 changed files
with
91 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -90,6 +90,8 @@ export default class ConnectionController { | |
private _currentConnectionId: null | string = null; | ||
|
||
_connectionAttempt: null | ConnectionAttempt = null; | ||
_connectionStringInputCancellationToken: null | vscode.CancellationTokenSource = | ||
null; | ||
private _connectingConnectionId: null | string = null; | ||
private _disconnecting = false; | ||
|
||
|
@@ -144,33 +146,44 @@ export default class ConnectionController { | |
|
||
log.info('connectWithURI command called'); | ||
|
||
try { | ||
connectionString = await vscode.window.showInputBox({ | ||
value: '', | ||
ignoreFocusOut: true, | ||
placeHolder: | ||
'e.g. mongodb+srv://username:[email protected]/admin', | ||
prompt: 'Enter your connection string (SRV or standard)', | ||
validateInput: (uri: string) => { | ||
if ( | ||
!uri.startsWith('mongodb://') && | ||
!uri.startsWith('mongodb+srv://') | ||
) { | ||
return 'MongoDB connection strings begin with "mongodb://" or "mongodb+srv://"'; | ||
} | ||
const cancellationToken = new vscode.CancellationTokenSource(); | ||
this._connectionStringInputCancellationToken = cancellationToken; | ||
|
||
try { | ||
// eslint-disable-next-line no-new | ||
new ConnectionString(uri); | ||
} catch (error) { | ||
return formatError(error).message; | ||
} | ||
|
||
return null; | ||
try { | ||
connectionString = await vscode.window.showInputBox( | ||
{ | ||
value: '', | ||
ignoreFocusOut: true, | ||
placeHolder: | ||
'e.g. mongodb+srv://username:[email protected]/admin', | ||
prompt: 'Enter your connection string (SRV or standard)', | ||
validateInput: (uri: string) => { | ||
if ( | ||
!uri.startsWith('mongodb://') && | ||
!uri.startsWith('mongodb+srv://') | ||
) { | ||
return 'MongoDB connection strings begin with "mongodb://" or "mongodb+srv://"'; | ||
} | ||
|
||
try { | ||
// eslint-disable-next-line no-new | ||
new ConnectionString(uri); | ||
} catch (error) { | ||
return formatError(error).message; | ||
} | ||
|
||
return null; | ||
}, | ||
}, | ||
}); | ||
cancellationToken.token | ||
); | ||
} catch (e) { | ||
return false; | ||
} finally { | ||
if (this._connectionStringInputCancellationToken === cancellationToken) { | ||
this._connectionStringInputCancellationToken.dispose(); | ||
this._connectionStringInputCancellationToken = null; | ||
} | ||
} | ||
|
||
if (!connectionString) { | ||
|
@@ -687,6 +700,10 @@ export default class ConnectionController { | |
this.eventEmitter.removeListener(eventType, listener); | ||
} | ||
|
||
closeConnectionStringInput() { | ||
this._connectionStringInputCancellationToken?.cancel(); | ||
} | ||
|
||
isConnecting(): boolean { | ||
return !!this._connectionAttempt; | ||
} | ||
|
This file contains 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 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 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 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 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 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