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

@@ -2,7 +2,7 @@
"name": "sql-migration", "name": "sql-migration",
"displayName": "%displayName%", "displayName": "%displayName%",
"description": "%description%", "description": "%description%",
"version": "1.4.6", "version": "1.4.7",
"publisher": "Microsoft", "publisher": "Microsoft",
"preview": false, "preview": false,
"license": "https://raw.githubusercontent.com/Microsoft/azuredatastudio/main/LICENSE.txt", "license": "https://raw.githubusercontent.com/Microsoft/azuredatastudio/main/LICENSE.txt",

View File

@@ -241,9 +241,9 @@ export function selectDefaultDropdownValue(dropDown: DropDownComponent, value?:
if (value) { if (value) {
const searchValue = value.toLowerCase(); const searchValue = value.toLowerCase();
if (useDisplayName) { if (useDisplayName) {
selectedIndex = dropDown.values.findIndex((v: any) => (v as CategoryValue)?.displayName?.toLowerCase() === searchValue); selectedIndex = dropDown.values?.findIndex((v: any) => (v as CategoryValue)?.displayName?.toLowerCase() === searchValue);
} else { } else {
selectedIndex = dropDown.values.findIndex((v: any) => (v as CategoryValue)?.name?.toLowerCase() === searchValue); selectedIndex = dropDown.values?.findIndex((v: any) => (v as CategoryValue)?.name?.toLowerCase() === searchValue);
} }
} else { } else {
selectedIndex = -1; selectedIndex = -1;
@@ -1169,7 +1169,7 @@ export function createRegistrationInstructions(view: ModelView, testConnectionBu
}).component(); }).component();
} }
export function clearDropDown(dropDown: DropDownComponent): void { export async function clearDropDown(dropDown: DropDownComponent): Promise<void> {
dropDown.values = []; await dropDown.updateProperty('value', undefined);
dropDown.value = undefined; await dropDown.updateProperty('values', []);
} }

View File

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

View File

@@ -327,8 +327,7 @@ export class IntergrationRuntimePage extends MigrationWizardPage {
} else { } else {
this.migrationStateModel._sqlMigrationServiceSubscription = undefined!; this.migrationStateModel._sqlMigrationServiceSubscription = undefined!;
} }
await utils.clearDropDown(this._resourceGroupDropdown);
utils.clearDropDown(this._resourceGroupDropdown);
await this.loadResourceGroupDropdown(); await this.loadResourceGroupDropdown();
})); }));
@@ -372,7 +371,7 @@ export class IntergrationRuntimePage extends MigrationWizardPage {
else { else {
this.migrationStateModel._sqlMigrationServiceResourceGroup = undefined!; this.migrationStateModel._sqlMigrationServiceResourceGroup = undefined!;
} }
utils.clearDropDown(this._dmsDropdown); await utils.clearDropDown(this._dmsDropdown);
this.loadDmsDropdown(); this.loadDmsDropdown();
})); }));

View File

@@ -377,8 +377,10 @@ export class LoginMigrationTargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._azureAccount = selectedAccount this.migrationStateModel._azureAccount = selectedAccount
? utils.deepClone(selectedAccount)! ? utils.deepClone(selectedAccount)!
: undefined!; : undefined!;
} else {
this.migrationStateModel._azureAccount = undefined!;
} }
utils.clearDropDown(this._accountTenantDropdown); await utils.clearDropDown(this._accountTenantDropdown);
await this.populateTenantsDropdown(); await this.populateTenantsDropdown();
})); }));
@@ -430,8 +432,10 @@ export class LoginMigrationTargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._azureTenant = selectedTenant this.migrationStateModel._azureTenant = selectedTenant
? utils.deepClone(selectedTenant) ? utils.deepClone(selectedTenant)
: undefined!; : undefined!;
} else {
this.migrationStateModel._azureTenant = undefined!;
} }
utils.clearDropDown(this._azureSubscriptionDropdown); await utils.clearDropDown(this._azureSubscriptionDropdown);
await this.populateSubscriptionDropdown(); await this.populateSubscriptionDropdown();
})); }));
@@ -472,9 +476,11 @@ export class LoginMigrationTargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._targetSubscription = (selectedSubscription) this.migrationStateModel._targetSubscription = (selectedSubscription)
? utils.deepClone(selectedSubscription)! ? utils.deepClone(selectedSubscription)!
: undefined!; : undefined!;
} else {
this.migrationStateModel._targetSubscription = undefined!;
} }
this.migrationStateModel.refreshDatabaseBackupPage = true; this.migrationStateModel.refreshDatabaseBackupPage = true;
utils.clearDropDown(this._azureLocationDropdown); await utils.clearDropDown(this._azureLocationDropdown);
await this.populateLocationDropdown(); await this.populateLocationDropdown();
})); }));
@@ -503,9 +509,11 @@ export class LoginMigrationTargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._location = (selectedLocation) this.migrationStateModel._location = (selectedLocation)
? utils.deepClone(selectedLocation)! ? utils.deepClone(selectedLocation)!
: undefined!; : undefined!;
} else {
this.migrationStateModel._location = undefined!;
} }
this.migrationStateModel.refreshDatabaseBackupPage = true; this.migrationStateModel.refreshDatabaseBackupPage = true;
utils.clearDropDown(this._azureResourceGroupDropdown); await utils.clearDropDown(this._azureResourceGroupDropdown);
await this.populateResourceGroupDropdown(); await this.populateResourceGroupDropdown();
})); }));
@@ -732,8 +740,10 @@ export class LoginMigrationTargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._resourceGroup = (selectedResourceGroup) this.migrationStateModel._resourceGroup = (selectedResourceGroup)
? utils.deepClone(selectedResourceGroup)! ? utils.deepClone(selectedResourceGroup)!
: undefined!; : undefined!;
} else {
this.migrationStateModel._resourceGroup = undefined!;
} }
utils.clearDropDown(this._azureResourceDropdown); await utils.clearDropDown(this._azureResourceDropdown);
await this.populateResourceInstanceDropdown(); await this.populateResourceInstanceDropdown();
})); }));

View File

@@ -267,12 +267,12 @@ export class TargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._resourceGroup = undefined!; this.migrationStateModel._resourceGroup = undefined!;
this.migrationStateModel._targetServerInstance = undefined!; this.migrationStateModel._targetServerInstance = undefined!;
utils.clearDropDown(this._azureAccountsDropdown); await utils.clearDropDown(this._azureAccountsDropdown);
utils.clearDropDown(this._accountTenantDropdown); await utils.clearDropDown(this._accountTenantDropdown);
utils.clearDropDown(this._azureSubscriptionDropdown); await utils.clearDropDown(this._azureSubscriptionDropdown);
utils.clearDropDown(this._azureLocationDropdown); await utils.clearDropDown(this._azureLocationDropdown);
utils.clearDropDown(this._azureResourceGroupDropdown); await utils.clearDropDown(this._azureResourceGroupDropdown);
utils.clearDropDown(this._azureResourceDropdown); await utils.clearDropDown(this._azureResourceDropdown);
} }
await this.populateAzureAccountsDropdown(); await this.populateAzureAccountsDropdown();
@@ -313,8 +313,10 @@ export class TargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._azureAccount = (selectedAccount) this.migrationStateModel._azureAccount = (selectedAccount)
? utils.deepClone(selectedAccount)! ? utils.deepClone(selectedAccount)!
: undefined!; : undefined!;
} else {
this.migrationStateModel._azureAccount = undefined!;
} }
utils.clearDropDown(this._accountTenantDropdown); await utils.clearDropDown(this._accountTenantDropdown);
await this.populateTenantsDropdown(); await this.populateTenantsDropdown();
})); }));
@@ -366,8 +368,10 @@ export class TargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._azureTenant = selectedTenant this.migrationStateModel._azureTenant = selectedTenant
? utils.deepClone(selectedTenant) ? utils.deepClone(selectedTenant)
: undefined!; : undefined!;
} else {
this.migrationStateModel._azureTenant = undefined!;
} }
utils.clearDropDown(this._azureSubscriptionDropdown); await utils.clearDropDown(this._azureSubscriptionDropdown);
await this.populateSubscriptionDropdown(); await this.populateSubscriptionDropdown();
})); }));
@@ -408,9 +412,11 @@ export class TargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._targetSubscription = (selectedSubscription) this.migrationStateModel._targetSubscription = (selectedSubscription)
? utils.deepClone(selectedSubscription)! ? utils.deepClone(selectedSubscription)!
: undefined!; : undefined!;
} else {
this.migrationStateModel._targetSubscription = undefined!;
} }
this.migrationStateModel.refreshDatabaseBackupPage = true; this.migrationStateModel.refreshDatabaseBackupPage = true;
utils.clearDropDown(this._azureLocationDropdown); await utils.clearDropDown(this._azureLocationDropdown);
await this.populateLocationDropdown(); await this.populateLocationDropdown();
})); }));
@@ -439,9 +445,11 @@ export class TargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._location = (selectedLocation) this.migrationStateModel._location = (selectedLocation)
? utils.deepClone(selectedLocation)! ? utils.deepClone(selectedLocation)!
: undefined!; : undefined!;
} else {
this.migrationStateModel._location = undefined!;
} }
this.migrationStateModel.refreshDatabaseBackupPage = true; this.migrationStateModel.refreshDatabaseBackupPage = true;
utils.clearDropDown(this._azureResourceGroupDropdown); await utils.clearDropDown(this._azureResourceGroupDropdown);
await this.populateResourceGroupDropdown(); await this.populateResourceGroupDropdown();
})); }));
@@ -667,8 +675,10 @@ export class TargetSelectionPage extends MigrationWizardPage {
this.migrationStateModel._resourceGroup = (selectedResourceGroup) this.migrationStateModel._resourceGroup = (selectedResourceGroup)
? utils.deepClone(selectedResourceGroup)! ? utils.deepClone(selectedResourceGroup)!
: undefined!; : undefined!;
} else {
this.migrationStateModel._resourceGroup = undefined!;
} }
utils.clearDropDown(this._azureResourceDropdown); await utils.clearDropDown(this._azureResourceDropdown);
await this.populateResourceInstanceDropdown(); await this.populateResourceInstanceDropdown();
})); }));
@@ -775,6 +785,8 @@ export class TargetSelectionPage extends MigrationWizardPage {
await this._validateFields(); await this._validateFields();
} else { } else {
this.migrationStateModel._targetServerInstance = undefined!; this.migrationStateModel._targetServerInstance = undefined!;
this.migrationStateModel._vmInstanceView = undefined!;
if (isSqlDbTarget) { if (isSqlDbTarget) {
this._targetUserNameInputBox.value = ''; this._targetUserNameInputBox.value = '';
} }