From d2d24e38275b657e8fcbf7512cbe5b971cd1c152 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Fri, 3 Mar 2023 15:34:51 -0800 Subject: [PATCH] dispose view after the operation is done (#22144) --- .../mssql/src/objectManagement/ui/loginDialog.ts | 2 +- .../ui/objectManagementDialogBase.ts | 16 +++++++++++++--- .../mssql/src/objectManagement/ui/userDialog.ts | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/extensions/mssql/src/objectManagement/ui/loginDialog.ts b/extensions/mssql/src/objectManagement/ui/loginDialog.ts index 8e4cee0e7a..530f81b980 100644 --- a/extensions/mssql/src/objectManagement/ui/loginDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/loginDialog.ts @@ -84,7 +84,7 @@ export class LoginDialog extends ObjectManagementDialogBase { + protected async disposeView(): Promise { await this.objectManagementService.disposeLoginView(this.contextId); } diff --git a/extensions/mssql/src/objectManagement/ui/objectManagementDialogBase.ts b/extensions/mssql/src/objectManagement/ui/objectManagementDialogBase.ts index 576fbca789..ddb4d5b32b 100644 --- a/extensions/mssql/src/objectManagement/ui/objectManagementDialogBase.ts +++ b/extensions/mssql/src/objectManagement/ui/objectManagementDialogBase.ts @@ -60,7 +60,7 @@ export abstract class ObjectManagementDialogBase { await this.dispose(); })); + this.disposables.push(this.dialogObject.onClosed(async (reason: azdata.window.CloseReason) => { await this.dispose(reason); })); this._helpButton = azdata.window.createButton(HelpText, 'left'); this.disposables.push(this._helpButton.onClick(async () => { await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(docUrl)); @@ -81,9 +81,14 @@ export abstract class ObjectManagementDialogBase; protected abstract initializeUI(): Promise; protected abstract onComplete(): Promise; - protected abstract onDispose(): Promise; + protected async onDispose(): Promise { } protected abstract validateInput(): Promise; + /** + * Dispose the information related to this view in the backend service. + */ + protected abstract disposeView(): Promise; + protected onObjectValueChange(): void { this.dialogObject.okButton.enabled = JSON.stringify(this.objectInfo) !== JSON.stringify(this._originalObjectInfo); } @@ -165,6 +170,8 @@ export abstract class ObjectManagementDialogBase { + private async dispose(reason: azdata.window.CloseReason): Promise { await this.onDispose(); this.disposables.forEach(disposable => disposable.dispose()); + if (reason !== 'ok') { + await this.disposeView(); + } } protected async runValidation(showErrorMessage: boolean = true): Promise { diff --git a/extensions/mssql/src/objectManagement/ui/userDialog.ts b/extensions/mssql/src/objectManagement/ui/userDialog.ts index eec1b51ab6..49fb6f85dc 100644 --- a/extensions/mssql/src/objectManagement/ui/userDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/userDialog.ts @@ -69,7 +69,7 @@ export class UserDialog extends ObjectManagementDialogBase { + protected async disposeView(): Promise { await this.objectManagementService.disposeUserView(this.contextId); }