Adding Azure AD tenant dropdown in migration wizard (#14637)

* Added dropdown to select azure tenant in accounts page

* Added dropdown label for tenant dropdown

* Moving deepcopy to  utils
Exporting tenant type from azurecore

* Removing unnecessary stylings

* removing unnecessary async
This commit is contained in:
Aasim Khan
2021-03-10 12:48:44 -08:00
committed by GitHub
parent 6389a5b0b0
commit ee2988f5fd
4 changed files with 104 additions and 3 deletions

View File

@@ -9,9 +9,12 @@ import { MigrationWizardPage } from '../models/migrationWizardPage';
import { MigrationStateModel, StateChangeEvent } from '../models/stateMachine';
import * as constants from '../constants/strings';
import { WIZARD_INPUT_COMPONENT_WIDTH } from './wizardController';
import { deepClone } from '../api/utils';
export class AccountsSelectionPage extends MigrationWizardPage {
private _azureAccountsDropdown!: azdata.DropDownComponent;
private _accountTenantDropdown!: azdata.DropDownComponent;
private _accountTenantFlexContainer!: azdata.FlexContainer;
constructor(wizard: azdata.window.Wizard, migrationStateModel: MigrationStateModel) {
super(wizard, azdata.window.createWizardPage(constants.ACCOUNTS_SELECTION_PAGE_TITLE), migrationStateModel);
@@ -22,7 +25,8 @@ export class AccountsSelectionPage extends MigrationWizardPage {
const form = view.modelBuilder.formContainer()
.withFormItems(
[
await this.createAzureAccountsDropdown(view)
await this.createAzureAccountsDropdown(view),
await this.createAzureTenantContainer(view),
]
);
await view.initializeModel(form.component());
@@ -48,10 +52,24 @@ export class AccountsSelectionPage extends MigrationWizardPage {
this._azureAccountsDropdown.onValueChanged(async (value) => {
if (value.selected) {
this.migrationStateModel._azureAccount = this.migrationStateModel.getAccount(value.index);
const selectedAzureAccount = this.migrationStateModel.getAccount(value.index);
// Making a clone of the account object to preserve the original tenants
this.migrationStateModel._azureAccount = deepClone(selectedAzureAccount);
if (this.migrationStateModel._azureAccount.properties.tenants.length > 1) {
this.migrationStateModel._accountTenants = selectedAzureAccount.properties.tenants;
this._accountTenantDropdown.values = await this.migrationStateModel.getTenantValues();
this._accountTenantFlexContainer.updateCssStyles({
'display': 'inline'
});
} else {
this._accountTenantFlexContainer.updateCssStyles({
'display': 'none'
});
}
this.migrationStateModel._subscriptions = undefined!;
this.migrationStateModel._targetSubscription = undefined!;
this.migrationStateModel._databaseBackup.subscription = undefined!;
}
});
@@ -71,7 +89,7 @@ export class AccountsSelectionPage extends MigrationWizardPage {
.withLayout({
flexFlow: 'column'
})
.withItems([this._azureAccountsDropdown, linkAccountButton], { CSSStyles: { 'margin': '2px', } })
.withItems([this._azureAccountsDropdown, linkAccountButton])
.component();
return {
@@ -80,6 +98,50 @@ export class AccountsSelectionPage extends MigrationWizardPage {
};
}
private createAzureTenantContainer(view: azdata.ModelView): azdata.FormComponent {
const azureTenantDropdownLabel = view.modelBuilder.text().withProps({
value: constants.AZURE_TENANT,
CSSStyles: {
'margin': '0px'
}
}).component();
this._accountTenantDropdown = view.modelBuilder.dropDown().withProps({
width: WIZARD_INPUT_COMPONENT_WIDTH
}).component();
this._accountTenantDropdown.onValueChanged(value => {
/**
* Replacing all the tenants in azure account with the tenant user has selected.
* All azure requests will only run on this tenant from now on
*/
if (value.selected) {
this.migrationStateModel._azureAccount.properties.tenants = [this.migrationStateModel.getTenant(value.index)];
}
});
this._accountTenantFlexContainer = view.modelBuilder.flexContainer()
.withLayout({
flexFlow: 'column'
})
.withItems([
azureTenantDropdownLabel,
this._accountTenantDropdown
])
.withProps({
CSSStyles: {
'display': 'none'
}
})
.component();
return {
title: '',
component: this._accountTenantFlexContainer
};
}
private async populateAzureAccountsDropdown(): Promise<void> {
this._azureAccountsDropdown.loading = true;
try {