Edit Connection Feature added, edit existing connection in connection tree. (#10214)

* Added Edit Connection Command

* Wip changes for new connection dialog

* Testing

* WIP commit

* added ID check to ensure connection

* wip commit

* model id check implemented

* addfooterbutton now accepts events

* wip commit

* message explaining check

* temporary change

* connectionManagementService restored

* Revert "connectionManagementService restored"

This reverts commit 9704a63184a06a33bee2648ef0a899229d117cc0.

* formatting test

* editConnection promise testing

* edit existing connection command added

* WIP Connection Edit

* disconnect added to editConnection promise

* WIP on editExistingConnection

* changed isEdit to true

* Amir/edit connection (#10112)

* Get edit connection working

* Delete unused code

* check for isEdit as well

* connection tree test added

* WIP connection management tests

* comment out test to find out what's wrong

* fix for one error

* added note about test skipped

* changed signature of saveprofile

* saveprofile fixed

* wrote working test

* added additional test

* changed message

* Fixes made

* fix for matcher

Co-authored-by: Amir Omidi <amomidi@microsoft.com>
This commit is contained in:
Alex Ma
2020-05-05 13:21:05 -07:00
committed by GitHub
parent 5fe72d318b
commit 921e546fd7
12 changed files with 234 additions and 59 deletions

View File

@@ -225,6 +225,26 @@ export class ConnectionManagementService extends Disposable implements IConnecti
});
}
/**
* Opens the edit connection dialog
* @param model the existing connection profile to edit on.
*/
public async showEditConnectionDialog(model: interfaces.IConnectionProfile): Promise<void> {
if (!model) {
throw new Error('Connection Profile is undefined');
}
let params = {
connectionType: ConnectionType.default,
isEditConnection: true
};
try {
return await this._connectionDialogService.showDialog(this, params, model);
} catch (dialogError) {
this._logService.warn('failed to open the connection dialog. error: ' + dialogError);
}
}
/**
* Load the password for the profile
* @param connectionProfile Connection Profile
@@ -420,6 +440,8 @@ export class ConnectionManagementService extends Disposable implements IConnecti
connection.options['groupId'] = connection.groupId;
connection.options['databaseDisplayName'] = connection.databaseName;
let isEdit = options?.params?.isEditConnection ?? false;
if (!uri) {
uri = Utils.generateUri(connection);
}
@@ -449,6 +471,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
if (!tokenFillSuccess) {
throw new Error(nls.localize('connection.noAzureAccount', "Failed to get Azure account token for connection"));
}
return this.createNewConnection(uri, connection).then(async connectionResult => {
if (connectionResult && connectionResult.connected) {
// The connected succeeded so add it to our active connections now, optionally adding it to the MRU based on
@@ -459,8 +482,15 @@ export class ConnectionManagementService extends Disposable implements IConnecti
if (callbacks.onConnectSuccess) {
callbacks.onConnectSuccess(options.params, connectionResult.connectionProfile);
}
if (options.saveTheConnection) {
await this.saveToSettings(uri, connection).then(value => {
if (options.saveTheConnection || isEdit) {
let matcher: interfaces.ProfileMatcher;
if (isEdit) {
matcher = (a: interfaces.IConnectionProfile, b: interfaces.IConnectionProfile) => {
return a.id === b.id;
};
}
await this.saveToSettings(uri, connection, matcher).then(value => {
this._onAddConnectionProfile.fire(connection);
this.doActionsAfterConnectionComplete(value, options);
});
@@ -496,6 +526,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
});
}
private handleConnectionError(connection: interfaces.IConnectionProfile, uri: string, options: IConnectionCompletionOptions, callbacks: IConnectionCallbacks, connectionResult: IConnectionResult) {
let connectionNotAcceptedError = nls.localize('connectionNotAcceptedError', "Connection Not Accepted");
if (options.showFirewallRuleOnError && connectionResult.errorCode) {
@@ -529,7 +560,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
});
}
private doActionsAfterConnectionComplete(uri: string, options: IConnectionCompletionOptions,) {
private doActionsAfterConnectionComplete(uri: string, options: IConnectionCompletionOptions): void {
let connectionManagementInfo = this._connectionStatusManager.findConnection(uri);
if (options.showDashboard) {
this.showDashboardForConnectionManagementInfo(connectionManagementInfo.connectionProfile);
@@ -873,11 +904,10 @@ export class ConnectionManagementService extends Disposable implements IConnecti
});
}
private saveToSettings(id: string, connection: interfaces.IConnectionProfile): Promise<string> {
return this._connectionStore.saveProfile(connection).then(savedProfile => {
let newId = this._connectionStatusManager.updateConnectionProfile(savedProfile, id);
return newId;
});
private async saveToSettings(id: string, connection: interfaces.IConnectionProfile, matcher?: interfaces.ProfileMatcher): Promise<string> {
const savedProfile = await this._connectionStore.saveProfile(connection, undefined, matcher);
return this._connectionStatusManager.updateConnectionProfile(savedProfile, id);
}
/**