mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
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:
@@ -12,6 +12,7 @@ export const IAccountPickerService = createDecorator<IAccountPickerService>('Acc
|
|||||||
export interface IAccountPickerService {
|
export interface IAccountPickerService {
|
||||||
_serviceBrand: undefined;
|
_serviceBrand: undefined;
|
||||||
renderAccountPicker(rootContainer: HTMLElement): void;
|
renderAccountPicker(rootContainer: HTMLElement): void;
|
||||||
|
setInitialAccountTenant(account: string, tenant: string): void;
|
||||||
addAccountCompleteEvent: Event<void>;
|
addAccountCompleteEvent: Event<void>;
|
||||||
addAccountErrorEvent: Event<string>;
|
addAccountErrorEvent: Event<string>;
|
||||||
addAccountStartEvent: Event<void>;
|
addAccountStartEvent: Event<void>;
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ export class AccountPicker extends Disposable {
|
|||||||
public static ACCOUNTPICKERLIST_HEIGHT = 47;
|
public static ACCOUNTPICKERLIST_HEIGHT = 47;
|
||||||
public static ACCOUNTTENANTLIST_HEIGHT = 32;
|
public static ACCOUNTTENANTLIST_HEIGHT = 32;
|
||||||
public viewModel: AccountPickerViewModel;
|
public viewModel: AccountPickerViewModel;
|
||||||
|
public initialAccount: string;
|
||||||
|
public initialTenant: string;
|
||||||
private _accountList?: List<azdata.Account>;
|
private _accountList?: List<azdata.Account>;
|
||||||
private _rootContainer?: HTMLElement;
|
private _rootContainer?: HTMLElement;
|
||||||
|
|
||||||
@@ -189,6 +191,9 @@ export class AccountPicker extends Disposable {
|
|||||||
this.viewModel.initialize()
|
this.viewModel.initialize()
|
||||||
.then((accounts: azdata.Account[]) => {
|
.then((accounts: azdata.Account[]) => {
|
||||||
this.updateAccountList(accounts);
|
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 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) {
|
private createLabelElement(content: string, isHeader?: boolean) {
|
||||||
let className = 'dialog-label';
|
let className = 'dialog-label';
|
||||||
if (isHeader) {
|
if (isHeader) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import * as azdata from 'azdata';
|
|||||||
|
|
||||||
import { IAccountPickerService } from 'sql/workbench/services/accountManagement/browser/accountPicker';
|
import { IAccountPickerService } from 'sql/workbench/services/accountManagement/browser/accountPicker';
|
||||||
import { AccountPicker } from 'sql/workbench/services/accountManagement/browser/accountPickerImpl';
|
import { AccountPicker } from 'sql/workbench/services/accountManagement/browser/accountPickerImpl';
|
||||||
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
export class AccountPickerService implements IAccountPickerService {
|
export class AccountPickerService implements IAccountPickerService {
|
||||||
_serviceBrand: undefined;
|
_serviceBrand: undefined;
|
||||||
@@ -32,7 +33,8 @@ export class AccountPickerService implements IAccountPickerService {
|
|||||||
public get onTenantSelectionChangeEvent(): Event<string | undefined> { return this._onTenantSelectionChangeEvent.event; }
|
public get onTenantSelectionChangeEvent(): Event<string | undefined> { return this._onTenantSelectionChangeEvent.event; }
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@IInstantiationService private _instantiationService: IInstantiationService
|
@IInstantiationService private _instantiationService: IInstantiationService,
|
||||||
|
@ILogService private readonly _logService: ILogService
|
||||||
) {
|
) {
|
||||||
// Create event emitters
|
// Create event emitters
|
||||||
this._addAccountCompleteEmitter = new Emitter<void>();
|
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
|
* Render account picker
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { TestAccountManagementService } from 'sql/platform/accounts/test/common/
|
|||||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||||
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||||
import { AccountPickerService } from 'sql/workbench/services/accountManagement/browser/accountPickerService';
|
import { AccountPickerService } from 'sql/workbench/services/accountManagement/browser/accountPickerService';
|
||||||
|
import { NullLogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
// SUITE STATE /////////////////////////////////////////////////////////////
|
// SUITE STATE /////////////////////////////////////////////////////////////
|
||||||
let mockAddAccountCompleteEmitter: Emitter<void>;
|
let mockAddAccountCompleteEmitter: Emitter<void>;
|
||||||
@@ -37,9 +38,10 @@ suite('Account picker service tests', () => {
|
|||||||
// Setup:
|
// Setup:
|
||||||
// ... Create instantiation service
|
// ... Create instantiation service
|
||||||
let instantiationService = createInstantiationService();
|
let instantiationService = createInstantiationService();
|
||||||
|
let logService = new NullLogService();
|
||||||
|
|
||||||
// ... Create instance of the service and reder account picker
|
// ... Create instance of the service and render account picker
|
||||||
let service = new AccountPickerService(instantiationService);
|
let service = new AccountPickerService(instantiationService, logService);
|
||||||
service.renderAccountPicker(TypeMoq.It.isAny());
|
service.renderAccountPicker(TypeMoq.It.isAny());
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
|
|||||||
@@ -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 {
|
public onAccountSelectionChange(account: azdata.Account | undefined): void {
|
||||||
this.viewModel.selectedAccount = account;
|
this.viewModel.selectedAccount = account;
|
||||||
if (account && !account.isStale) {
|
if (account && !account.isStale) {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export class FirewallRuleDialogController {
|
|||||||
this._connection = connection;
|
this._connection = connection;
|
||||||
this._resourceProviderId = resourceProviderId;
|
this._resourceProviderId = resourceProviderId;
|
||||||
this._firewallRuleDialog.viewModel.updateDefaultValues(ipAddress);
|
this._firewallRuleDialog.viewModel.updateDefaultValues(ipAddress);
|
||||||
|
this._firewallRuleDialog.setInitialAccountTenant(connection.azureAccount, connection.azureTenantId);
|
||||||
this._firewallRuleDialog.open();
|
this._firewallRuleDialog.open();
|
||||||
this._deferredPromise = new Deferred();
|
this._deferredPromise = new Deferred();
|
||||||
return this._deferredPromise.promise;
|
return this._deferredPromise.promise;
|
||||||
|
|||||||
Reference in New Issue
Block a user