improve dropdown autopopulation behavior (#23420)

This commit is contained in:
brian-harris
2023-06-20 07:45:00 -07:00
committed by GitHub
parent f36ed0bb02
commit 6e014aff92
6 changed files with 94 additions and 71 deletions

View File

@@ -146,8 +146,10 @@ export class SelectMigrationServiceDialog {
this._serviceContext.azureAccount = selectedAccount
? utils.deepClone(selectedAccount)
: undefined!;
} else {
this._serviceContext.azureAccount = undefined;
}
utils.clearDropDown(this._accountTenantDropdown);
await utils.clearDropDown(this._accountTenantDropdown);
await this._populateTentantsDropdown();
}));
@@ -194,8 +196,10 @@ export class SelectMigrationServiceDialog {
this._serviceContext.tenant = selectedTenant
? utils.deepClone(selectedTenant)
: undefined!;
} else {
this._serviceContext.tenant = undefined;
}
utils.clearDropDown(this._azureSubscriptionDropdown);
await utils.clearDropDown(this._azureSubscriptionDropdown);
await this._populateSubscriptionDropdown();
}));
@@ -235,8 +239,10 @@ export class SelectMigrationServiceDialog {
this._serviceContext.subscription = selectedSubscription
? utils.deepClone(selectedSubscription)
: undefined!;
} else {
this._serviceContext.subscription = undefined;
}
utils.clearDropDown(this._azureLocationDropdown);
await utils.clearDropDown(this._azureLocationDropdown);
await this._populateLocationDropdown();
}));
@@ -264,8 +270,10 @@ export class SelectMigrationServiceDialog {
this._serviceContext.location = selectedLocation
? utils.deepClone(selectedLocation)
: undefined!;
} else {
this._serviceContext.location = undefined;
}
utils.clearDropDown(this._azureResourceGroupDropdown);
await utils.clearDropDown(this._azureResourceGroupDropdown);
await this._populateResourceGroupDropdown();
}));
@@ -293,8 +301,10 @@ export class SelectMigrationServiceDialog {
this._serviceContext.resourceGroup = selectedResourceGroup
? utils.deepClone(selectedResourceGroup)
: undefined!;
} else {
this._serviceContext.resourceGroup = undefined;
}
utils.clearDropDown(this._azureServiceDropdown);
await utils.clearDropDown(this._azureServiceDropdown);
this._populateMigrationServiceDropdown();
}));
@@ -322,6 +332,8 @@ export class SelectMigrationServiceDialog {
this._serviceContext.migrationService = selectedDms
? utils.deepClone(selectedDms)
: undefined!;
} else {
this._serviceContext.migrationService = undefined;
}
await this._updateButtonState();
}));
@@ -353,14 +365,14 @@ export class SelectMigrationServiceDialog {
private async _populateAzureAccountsDropdown(): Promise<void> {
try {
this._azureAccountsDropdown.loading = true;
await utils.clearDropDown(this._azureAccountsDropdown);
this._azureAccounts = await utils.getAzureAccounts();
this._azureAccountsDropdown.values = await utils.getAzureAccountsDropdownValues(this._azureAccounts);
if (this._azureAccountsDropdown.values.length > 0) {
utils.selectDefaultDropdownValue(
this._azureAccountsDropdown,
this._serviceContext.azureAccount?.displayInfo?.userId,
false);
}
utils.selectDefaultDropdownValue(
this._azureAccountsDropdown,
this._serviceContext.azureAccount?.displayInfo?.userId,
false);
} catch (error) {
logError(TelemetryViews.SelectMigrationServiceDialog, '_populateAzureAccountsDropdown', error);
void vscode.window.showErrorMessage(
@@ -374,18 +386,17 @@ export class SelectMigrationServiceDialog {
private async _populateTentantsDropdown(): Promise<void> {
try {
this._accountTenantDropdown.loading = true;
this._accountTenants = utils.getAzureTenants(this._serviceContext.azureAccount);
this._accountTenantDropdown.values = utils.getAzureTenantsDropdownValues(this._accountTenants);
await this._accountTenantFlexContainer.updateCssStyles(
this._accountTenants.length > 1
? STYLE_ShOW
: STYLE_HIDE);
if (this._accountTenantDropdown.values.length > 0) {
utils.selectDefaultDropdownValue(
this._accountTenantDropdown,
this._serviceContext.tenant?.id,
false);
}
utils.selectDefaultDropdownValue(
this._accountTenantDropdown,
this._serviceContext.tenant?.id,
false);
} catch (error) {
logError(TelemetryViews.SelectMigrationServiceDialog, '_populateTentantsDropdown', error);
void vscode.window.showErrorMessage(
@@ -393,24 +404,21 @@ export class SelectMigrationServiceDialog {
error.message);
} finally {
this._accountTenantDropdown.loading = false;
utils.clearDropDown(this._azureSubscriptionDropdown);
await this._populateSubscriptionDropdown();
}
}
private async _populateSubscriptionDropdown(): Promise<void> {
try {
this._azureSubscriptionDropdown.loading = true;
this._subscriptions = await utils.getAzureSubscriptions(
this._serviceContext.azureAccount,
this._serviceContext.tenant?.id);
this._azureSubscriptionDropdown.values = await utils.getAzureSubscriptionsDropdownValues(this._subscriptions);
if (this._azureSubscriptionDropdown.values.length > 0) {
utils.selectDefaultDropdownValue(
this._azureSubscriptionDropdown,
this._serviceContext.subscription?.id,
false);
}
utils.selectDefaultDropdownValue(
this._azureSubscriptionDropdown,
this._serviceContext.subscription?.id,
false);
} catch (error) {
logError(TelemetryViews.SelectMigrationServiceDialog, '_populateSubscriptionDropdown', error);
void vscode.window.showErrorMessage(
@@ -424,6 +432,7 @@ export class SelectMigrationServiceDialog {
private async _populateLocationDropdown(): Promise<void> {
try {
this._azureLocationDropdown.loading = true;
this._sqlMigrationServices = await utils.getAzureSqlMigrationServices(
this._serviceContext.azureAccount,
this._serviceContext.subscription);
@@ -431,14 +440,11 @@ export class SelectMigrationServiceDialog {
this._serviceContext.azureAccount,
this._serviceContext.subscription,
this._sqlMigrationServices);
this._azureLocationDropdown.values = utils.getAzureLocationsDropdownValues(this._locations);
if (this._azureLocationDropdown.values.length > 0) {
utils.selectDefaultDropdownValue(
this._azureLocationDropdown,
this._serviceContext.location?.displayName,
true);
}
utils.selectDefaultDropdownValue(
this._azureLocationDropdown,
this._serviceContext.location?.displayName,
true);
} catch (error) {
logError(TelemetryViews.SelectMigrationServiceDialog, '_populateLocationDropdown', error);
void vscode.window.showErrorMessage(
@@ -452,19 +458,17 @@ export class SelectMigrationServiceDialog {
private async _populateResourceGroupDropdown(): Promise<void> {
try {
this._azureResourceGroupDropdown.loading = true;
this._resourceGroups = utils.getServiceResourceGroupsByLocation(
this._sqlMigrationServices,
this._serviceContext.location!);
this._azureResourceGroupDropdown.values = utils.getResourceDropdownValues(
this._resourceGroups,
constants.RESOURCE_GROUP_NOT_FOUND);
if (this._azureResourceGroupDropdown.values.length > 0) {
utils.selectDefaultDropdownValue(
this._azureResourceGroupDropdown,
this._serviceContext.resourceGroup?.id,
false);
}
utils.selectDefaultDropdownValue(
this._azureResourceGroupDropdown,
this._serviceContext.resourceGroup?.id,
false);
} catch (error) {
logError(TelemetryViews.SelectMigrationServiceDialog, '_populateResourceGroupDropdown', error);
void vscode.window.showErrorMessage(
@@ -478,18 +482,16 @@ export class SelectMigrationServiceDialog {
private _populateMigrationServiceDropdown(): void {
try {
this._azureServiceDropdown.loading = true;
this._azureServiceDropdown.values = utils.getAzureResourceDropdownValues(
this._sqlMigrationServices,
this._serviceContext.location!,
this._serviceContext.resourceGroup?.name,
constants.SQL_MIGRATION_SERVICE_NOT_FOUND_ERROR);
if (this._azureServiceDropdown.values.length > 0) {
utils.selectDefaultDropdownValue(
this._azureServiceDropdown,
this._serviceContext?.migrationService?.id,
false);
}
utils.selectDefaultDropdownValue(
this._azureServiceDropdown,
this._serviceContext?.migrationService?.id,
false);
} catch (error) {
logError(TelemetryViews.SelectMigrationServiceDialog, '_populateMigrationServiceDropdown', error);
void vscode.window.showErrorMessage(