diff --git a/src/sql/workbench/services/accountManagement/browser/accountPicker.ts b/src/sql/workbench/services/accountManagement/browser/accountPicker.ts index 5073e9dd0b..18161d9edd 100644 --- a/src/sql/workbench/services/accountManagement/browser/accountPicker.ts +++ b/src/sql/workbench/services/accountManagement/browser/accountPicker.ts @@ -12,6 +12,7 @@ export const IAccountPickerService = createDecorator('Acc export interface IAccountPickerService { _serviceBrand: undefined; renderAccountPicker(rootContainer: HTMLElement): void; + setInitialAccountTenant(account: string, tenant: string): void; addAccountCompleteEvent: Event; addAccountErrorEvent: Event; addAccountStartEvent: Event; diff --git a/src/sql/workbench/services/accountManagement/browser/accountPickerImpl.ts b/src/sql/workbench/services/accountManagement/browser/accountPickerImpl.ts index 86b8b37797..a9f730584d 100644 --- a/src/sql/workbench/services/accountManagement/browser/accountPickerImpl.ts +++ b/src/sql/workbench/services/accountManagement/browser/accountPickerImpl.ts @@ -30,6 +30,8 @@ export class AccountPicker extends Disposable { public static ACCOUNTPICKERLIST_HEIGHT = 47; public static ACCOUNTTENANTLIST_HEIGHT = 32; public viewModel: AccountPickerViewModel; + public initialAccount: string; + public initialTenant: string; private _accountList?: List; private _rootContainer?: HTMLElement; @@ -189,6 +191,9 @@ export class AccountPicker extends Disposable { this.viewModel.initialize() .then((accounts: azdata.Account[]) => { this.updateAccountList(accounts); + // Need to set account selection after account list has been updated + this.setAccountSelection(); + this.setTenantSelection(); }); } @@ -199,8 +204,46 @@ export class AccountPicker extends Disposable { } } + public setInitialTenant(tenant: string): void { + this.initialTenant = tenant; + } + + public setInitialAccount(account: string): void { + this.initialAccount = account; + } + // PRIVATE HELPERS ///////////////////////////////////////////////////// + private setAccountSelection(): void { + let index = 0; + let accountFound = false; + while (index < this._accountList.length) { + if (this.initialAccount === this._accountList.element(index).key.accountId) { + accountFound = true; + break; + } + index++ + } + if (accountFound) { + this._accountList.setSelection([index]); + } + } + + private setTenantSelection(): void { + let index = 0; + let tenantFound = false; + while (index < this._tenantList.length) { + if (this.initialTenant === this._tenantList.element(index).id) { + tenantFound = true; + break; + } + index++ + } + if (tenantFound) { + this._tenantList.setSelection([index]); + } + } + private createLabelElement(content: string, isHeader?: boolean) { let className = 'dialog-label'; if (isHeader) { diff --git a/src/sql/workbench/services/accountManagement/browser/accountPickerService.ts b/src/sql/workbench/services/accountManagement/browser/accountPickerService.ts index f3c2aaca45..faa7af1cef 100644 --- a/src/sql/workbench/services/accountManagement/browser/accountPickerService.ts +++ b/src/sql/workbench/services/accountManagement/browser/accountPickerService.ts @@ -9,6 +9,7 @@ import * as azdata from 'azdata'; import { IAccountPickerService } from 'sql/workbench/services/accountManagement/browser/accountPicker'; import { AccountPicker } from 'sql/workbench/services/accountManagement/browser/accountPickerImpl'; +import { ILogService } from 'vs/platform/log/common/log'; export class AccountPickerService implements IAccountPickerService { _serviceBrand: undefined; @@ -32,7 +33,8 @@ export class AccountPickerService implements IAccountPickerService { public get onTenantSelectionChangeEvent(): Event { return this._onTenantSelectionChangeEvent.event; } constructor( - @IInstantiationService private _instantiationService: IInstantiationService + @IInstantiationService private _instantiationService: IInstantiationService, + @ILogService private readonly _logService: ILogService ) { // Create event emitters this._addAccountCompleteEmitter = new Emitter(); @@ -53,6 +55,17 @@ export class AccountPickerService implements IAccountPickerService { } } + public setInitialAccountTenant(account: string, tenant: string): void { + if (this._accountPicker) { + this._accountPicker.setInitialAccount(account); + this._accountPicker.setInitialTenant(tenant); + this._logService.info(`Set initial account: ${account} and tenant: ${tenant}`) + } else { + this._logService.error('Account Picker was undefined. Could not set initial account/tenant for firewall dialog.'); + } + } + + /** * Render account picker */ diff --git a/src/sql/workbench/services/accountManagement/test/browser/accountPickerService.test.ts b/src/sql/workbench/services/accountManagement/test/browser/accountPickerService.test.ts index ac6408dd54..d525be842e 100644 --- a/src/sql/workbench/services/accountManagement/test/browser/accountPickerService.test.ts +++ b/src/sql/workbench/services/accountManagement/test/browser/accountPickerService.test.ts @@ -14,6 +14,7 @@ import { TestAccountManagementService } from 'sql/platform/accounts/test/common/ import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService'; import { AccountPickerService } from 'sql/workbench/services/accountManagement/browser/accountPickerService'; +import { NullLogService } from 'vs/platform/log/common/log'; // SUITE STATE ///////////////////////////////////////////////////////////// let mockAddAccountCompleteEmitter: Emitter; @@ -37,9 +38,10 @@ suite('Account picker service tests', () => { // Setup: // ... Create instantiation service let instantiationService = createInstantiationService(); + let logService = new NullLogService(); - // ... Create instance of the service and reder account picker - let service = new AccountPickerService(instantiationService); + // ... Create instance of the service and render account picker + let service = new AccountPickerService(instantiationService, logService); service.renderAccountPicker(TypeMoq.It.isAny()); // Then: diff --git a/src/sql/workbench/services/resourceProvider/browser/firewallRuleDialog.ts b/src/sql/workbench/services/resourceProvider/browser/firewallRuleDialog.ts index 5b53d8ca1e..4a6d0b5ed5 100644 --- a/src/sql/workbench/services/resourceProvider/browser/firewallRuleDialog.ts +++ b/src/sql/workbench/services/resourceProvider/browser/firewallRuleDialog.ts @@ -322,6 +322,10 @@ export class FirewallRuleDialog extends Modal { } } + public setInitialAccountTenant(account: string, tenant: string) { + this._accountPickerService.setInitialAccountTenant(account, tenant); + } + public onAccountSelectionChange(account: azdata.Account | undefined): void { this.viewModel.selectedAccount = account; if (account && !account.isStale) { diff --git a/src/sql/workbench/services/resourceProvider/browser/firewallRuleDialogController.ts b/src/sql/workbench/services/resourceProvider/browser/firewallRuleDialogController.ts index 2d35f399f3..a6756b22af 100644 --- a/src/sql/workbench/services/resourceProvider/browser/firewallRuleDialogController.ts +++ b/src/sql/workbench/services/resourceProvider/browser/firewallRuleDialogController.ts @@ -48,6 +48,7 @@ export class FirewallRuleDialogController { this._connection = connection; this._resourceProviderId = resourceProviderId; this._firewallRuleDialog.viewModel.updateDefaultValues(ipAddress); + this._firewallRuleDialog.setInitialAccountTenant(connection.azureAccount, connection.azureTenantId); this._firewallRuleDialog.open(); this._deferredPromise = new Deferred(); return this._deferredPromise.promise;