dispose view after the operation is done (#22144)

This commit is contained in:
Alan Ren
2023-03-03 15:34:51 -08:00
committed by GitHub
parent 07eb964c32
commit d2d24e3827
3 changed files with 15 additions and 5 deletions

View File

@@ -84,7 +84,7 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
}
}
protected async onDispose(): Promise<void> {
protected async disposeView(): Promise<void> {
await this.objectManagementService.disposeLoginView(this.contextId);
}

View File

@@ -60,7 +60,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
const dialogTitle = isNewObject ? NewObjectDialogTitle(objectTypeDisplayName) : ObjectPropertiesDialogTitle(objectTypeDisplayName, objectName);
this.dialogObject = azdata.window.createModelViewDialog(dialogTitle, getDialogName(objectType, isNewObject), dialogWidth);
this.dialogObject.okButton.label = OkText;
this.disposables.push(this.dialogObject.onClosed(async () => { 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<ObjectInfoType extends ObjectMa
protected abstract initializeData(): Promise<ViewInfoType>;
protected abstract initializeUI(): Promise<void>;
protected abstract onComplete(): Promise<void>;
protected abstract onDispose(): Promise<void>;
protected async onDispose(): Promise<void> { }
protected abstract validateInput(): Promise<string[]>;
/**
* Dispose the information related to this view in the backend service.
*/
protected abstract disposeView(): Promise<void>;
protected onObjectValueChange(): void {
this.dialogObject.okButton.enabled = JSON.stringify(this.objectInfo) !== JSON.stringify(this._originalObjectInfo);
}
@@ -165,6 +170,8 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, actionName, err).withAdditionalProperties({
objectType: this.objectType
}).send();
} finally {
await this.disposeView();
}
}
});
@@ -180,9 +187,12 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
}
}
private async dispose(): Promise<void> {
private async dispose(reason: azdata.window.CloseReason): Promise<void> {
await this.onDispose();
this.disposables.forEach(disposable => disposable.dispose());
if (reason !== 'ok') {
await this.disposeView();
}
}
protected async runValidation(showErrorMessage: boolean = true): Promise<boolean> {

View File

@@ -69,7 +69,7 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
}
}
protected async onDispose(): Promise<void> {
protected async disposeView(): Promise<void> {
await this.objectManagementService.disposeUserView(this.contextId);
}