mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-30 17:23:29 -05:00
* Modify where we add active connections so that we can use the saveTheConnection option to decide whether to add a connection to the MRU. This was necessary because the old location was called from onConnectionComplete which is sent by the SqlToolsService - and that doesn't get any UI related information like the options. The new location is still only called after the connection completes and will be added only if the connection succeeds. Added new test and updated existing tests to handle new logic (plus a bit of async-refactoring). * Fix couple spacing issues * Add logic back in to short-circuit if we already have the connection in the active connections list. * Fix spaces -> tabs
This commit is contained in:
@@ -277,20 +277,30 @@ export class ConnectionStore {
|
||||
* Password values are stored to a separate credential store if the "savePassword" option is true
|
||||
*
|
||||
* @param {IConnectionCredentials} conn the connection to add
|
||||
* @param {boolean} addToMru Whether to add this connection to the MRU
|
||||
* @returns {Promise<void>} a Promise that returns when the connection was saved
|
||||
*/
|
||||
public addActiveConnection(conn: IConnectionProfile, isConnectionToDefaultDb: boolean = false): Promise<void> {
|
||||
if (this.getActiveConnections().some(existingConn => existingConn.id === conn.id)) {
|
||||
return Promise.resolve(undefined);
|
||||
} else {
|
||||
return this.addConnectionToMemento(conn, Constants.activeConnections, undefined, conn.savePassword).then(() => {
|
||||
let maxConnections = this.getMaxRecentConnectionsCount();
|
||||
if (isConnectionToDefaultDb) {
|
||||
conn.databaseName = '';
|
||||
}
|
||||
return this.addConnectionToMemento(conn, Constants.recentConnections, maxConnections);
|
||||
});
|
||||
public async addActiveConnection(conn: IConnectionProfile, addToMru: boolean): Promise<void> {
|
||||
if (addToMru) {
|
||||
await this.addConnectionToMru(conn);
|
||||
}
|
||||
|
||||
// Only add connections we don't already know about
|
||||
if (!this.getActiveConnections().some(existingConn => existingConn.id === conn.id)) {
|
||||
await this.addConnectionToMemento(conn, Constants.activeConnections, undefined, conn.savePassword);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified connection to the MRU list
|
||||
* @param conn The connection to add
|
||||
*/
|
||||
private async addConnectionToMru(conn: IConnectionProfile): Promise<void> {
|
||||
let maxConnections = this.getMaxRecentConnectionsCount();
|
||||
if (ConnectionProfile.isConnectionToDefaultDb(conn)) {
|
||||
conn.databaseName = '';
|
||||
}
|
||||
await this.addConnectionToMemento(conn, Constants.recentConnections, maxConnections);
|
||||
}
|
||||
|
||||
public addConnectionToMemento(conn: IConnectionProfile, mementoKey: string, maxConnections?: number, savePassword?: boolean): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user