Firewall Dialog Account/Tenant Selection (#22695)

* preselect account in firewall dialog from connection details

* cleanup

* fix element reference

* add initial tenant selection

* fix compile & cleanup

* pr comments

* change to private
This commit is contained in:
Christopher Suh
2023-04-12 15:59:31 -07:00
committed by GitHub
parent 62c2fd3290
commit 897f026d1e
6 changed files with 67 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ export const IAccountPickerService = createDecorator<IAccountPickerService>('Acc
export interface IAccountPickerService {
_serviceBrand: undefined;
renderAccountPicker(rootContainer: HTMLElement): void;
setInitialAccountTenant(account: string, tenant: string): void;
addAccountCompleteEvent: Event<void>;
addAccountErrorEvent: Event<string>;
addAccountStartEvent: Event<void>;

View File

@@ -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<azdata.Account>;
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) {

View File

@@ -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<string | undefined> { 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<void>();
@@ -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
*/

View File

@@ -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<void>;
@@ -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:

View File

@@ -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) {

View File

@@ -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;