From 33dce95b152227c4f10f6251ab30690fe9895c0c Mon Sep 17 00:00:00 2001 From: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com> Date: Fri, 27 Jan 2023 16:11:17 -0800 Subject: [PATCH] Show tenant dropdown when selecting 'AzureMFA' for first time (#21763) (#21764) --- .../services/connection/browser/connectionWidget.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sql/workbench/services/connection/browser/connectionWidget.ts b/src/sql/workbench/services/connection/browser/connectionWidget.ts index 2b5a563ab3..22f476cae0 100644 --- a/src/sql/workbench/services/connection/browser/connectionWidget.ts +++ b/src/sql/workbench/services/connection/browser/connectionWidget.ts @@ -562,8 +562,8 @@ export class ConnectionWidget extends lifecycle.Disposable { this.fillInAzureAccountOptions().then(async () => { // Don't enable the control until we've populated it this._azureAccountDropdown.enable(); - // Populate tenants - await this.onAzureAccountSelected(); + // Populate tenants (select first by default for initialization of tenant dialog) + await this.onAzureAccountSelected(true); this._azureTenantDropdown.enable(); }).catch(err => this._logService.error(`Unexpected error populating Azure Account dropdown : ${err}`)); // Immediately show/hide appropriate elements though so user gets immediate feedback while we load accounts @@ -572,8 +572,8 @@ export class ConnectionWidget extends lifecycle.Disposable { this.fillInAzureAccountOptions().then(async () => { // Don't enable the control until we've populated it this._azureAccountDropdown.enable(); - // Populate tenants - await this.onAzureAccountSelected(); + // Populate tenants (select first by default for initialization of tenant dialog) + await this.onAzureAccountSelected(true); this._azureTenantDropdown.enable(); }).catch(err => this._logService.error(`Unexpected error populating Azure Account dropdown : ${err}`)); // Immediately show/hide appropriate elements though so user gets immediate feedback while we load accounts @@ -638,7 +638,7 @@ export class ConnectionWidget extends lifecycle.Disposable { } } - private async onAzureAccountSelected(): Promise { + private async onAzureAccountSelected(selectFirstByDefault: boolean = false): Promise { // Reset the dropdown's validation message if the old selection was not valid but the new one is this.validateAzureAccountSelection(false); @@ -670,6 +670,9 @@ export class ConnectionWidget extends lifecycle.Disposable { // The OR case can be removed once we no longer support ADAL let selectedAccount = this._azureAccountList.find(account => account.key.accountId === this._azureAccountDropdown.value || account.key.accountId.split('.')[0] === this._azureAccountDropdown.value); + if (!selectedAccount && selectFirstByDefault && this._azureAccountList.length > 0) { + selectedAccount = this._azureAccountList[0]; + } if (selectedAccount && selectedAccount.properties.tenants && selectedAccount.properties.tenants.length > 1) { // There are multiple tenants available so let the user select one let options = selectedAccount.properties.tenants.map(tenant => tenant.displayName);