Select default database dropdown values based on a default index value (#24013)

This commit is contained in:
Cory Rivera
2023-07-28 14:37:37 -07:00
committed by GitHub
parent 5c5b73525d
commit 9727a761c9
3 changed files with 73 additions and 48 deletions

View File

@@ -1,6 +1,6 @@
{ {
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "4.9.0.6", "version": "4.9.0.8",
"downloadFileNames": { "downloadFileNames": {
"Windows_86": "win-x86-net7.0.zip", "Windows_86": "win-x86-net7.0.zip",
"Windows_64": "win-x64-net7.0.zip", "Windows_64": "win-x64-net7.0.zip",

View File

@@ -457,24 +457,29 @@ export interface Database extends ObjectManagement.SqlObject {
} }
export interface DatabaseViewInfo extends ObjectManagement.ObjectViewInfo<Database> { export interface DatabaseViewInfo extends ObjectManagement.ObjectViewInfo<Database> {
loginNames: string[];
collationNames: string[];
compatibilityLevels: string[];
containmentTypes: string[];
recoveryModels: string[];
files: DatabaseFile[];
isAzureDB: boolean; isAzureDB: boolean;
azureBackupRedundancyLevels: string[]; loginNames?: OptionsCollection;
azureServiceLevelObjectives: AzureEditionDetails[]; collationNames?: OptionsCollection;
azureEditions: string[]; compatibilityLevels?: OptionsCollection;
azureMaxSizes: AzureEditionDetails[]; containmentTypes?: OptionsCollection;
pageVerifyOptions: string[]; recoveryModels?: OptionsCollection;
restrictAccessOptions: string[]; files?: DatabaseFile[];
azureBackupRedundancyLevels?: string[];
azureServiceLevelObjectives?: AzureEditionDetails[];
azureEditions?: string[];
azureMaxSizes?: AzureEditionDetails[];
pageVerifyOptions?: string[];
restrictAccessOptions?: string[];
}
export interface OptionsCollection {
options: string[];
defaultValueIndex: number;
} }
export interface AzureEditionDetails { export interface AzureEditionDetails {
editionDisplayName: string; editionDisplayName: string;
details: string[]; editionOptions: OptionsCollection;
} }
export interface Server extends ObjectManagement.SqlObject { export interface Server extends ObjectManagement.SqlObject {

View File

@@ -136,7 +136,8 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
protected override async validateInput(): Promise<string[]> { protected override async validateInput(): Promise<string[]> {
let errors = await super.validateInput(); let errors = await super.validateInput();
if (this.viewInfo.collationNames?.length > 0 && !this.viewInfo.collationNames.some(name => name.toLowerCase() === this.objectInfo.collationName?.toLowerCase())) { let collationNames = this.viewInfo.collationNames?.options;
if (collationNames?.length > 0 && !collationNames.some(name => name.toLowerCase() === this.objectInfo.collationName?.toLowerCase())) {
errors.push(localizedConstants.CollationNotValidError(this.objectInfo.collationName ?? '')); errors.push(localizedConstants.CollationNotValidError(this.objectInfo.collationName ?? ''));
} }
return errors; return errors;
@@ -158,11 +159,13 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
}, props); }, props);
containers.push(this.createLabelInputContainer(localizedConstants.NameText, this.nameInput)); containers.push(this.createLabelInputContainer(localizedConstants.NameText, this.nameInput));
if (this.viewInfo.loginNames?.length > 0) { let loginNames = this.viewInfo.loginNames?.options;
this.objectInfo.owner = this.viewInfo.loginNames[0]; if (loginNames?.length > 0) {
let defaultIndex = this.viewInfo.loginNames.defaultValueIndex;
this.objectInfo.owner = loginNames[defaultIndex];
let ownerDropbox = this.createDropdown(localizedConstants.OwnerText, async () => { let ownerDropbox = this.createDropdown(localizedConstants.OwnerText, async () => {
this.objectInfo.owner = ownerDropbox.value as string; this.objectInfo.owner = ownerDropbox.value as string;
}, this.viewInfo.loginNames, this.viewInfo.loginNames[0]); }, loginNames, loginNames[defaultIndex]);
containers.push(this.createLabelInputContainer(localizedConstants.OwnerText, ownerDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.OwnerText, ownerDropbox));
} }
@@ -171,35 +174,43 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
private initializeOptionsSection(): azdata.GroupContainer { private initializeOptionsSection(): azdata.GroupContainer {
let containers: azdata.Component[] = []; let containers: azdata.Component[] = [];
if (this.viewInfo.collationNames?.length > 0) { let collationNames = this.viewInfo.collationNames?.options;
this.objectInfo.collationName = this.viewInfo.collationNames[0]; if (collationNames?.length > 0) {
let defaultIndex = this.viewInfo.collationNames.defaultValueIndex;
this.objectInfo.collationName = collationNames[defaultIndex];
let collationDropbox = this.createDropdown(localizedConstants.CollationText, async () => { let collationDropbox = this.createDropdown(localizedConstants.CollationText, async () => {
this.objectInfo.collationName = collationDropbox.value as string; this.objectInfo.collationName = collationDropbox.value as string;
}, this.viewInfo.collationNames, this.viewInfo.collationNames[0], true, DefaultInputWidth, true, true); }, collationNames, collationNames[defaultIndex], true, DefaultInputWidth, true, true);
containers.push(this.createLabelInputContainer(localizedConstants.CollationText, collationDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.CollationText, collationDropbox));
} }
if (this.viewInfo.recoveryModels?.length > 0) { let recoveryModels = this.viewInfo.recoveryModels?.options;
this.objectInfo.recoveryModel = this.viewInfo.recoveryModels[0]; if (recoveryModels?.length > 0) {
let defaultIndex = this.viewInfo.recoveryModels.defaultValueIndex;
this.objectInfo.recoveryModel = recoveryModels[defaultIndex];
let recoveryDropbox = this.createDropdown(localizedConstants.RecoveryModelText, async () => { let recoveryDropbox = this.createDropdown(localizedConstants.RecoveryModelText, async () => {
this.objectInfo.recoveryModel = recoveryDropbox.value as string; this.objectInfo.recoveryModel = recoveryDropbox.value as string;
}, this.viewInfo.recoveryModels, this.viewInfo.recoveryModels[0]); }, recoveryModels, recoveryModels[defaultIndex]);
containers.push(this.createLabelInputContainer(localizedConstants.RecoveryModelText, recoveryDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.RecoveryModelText, recoveryDropbox));
} }
if (this.viewInfo.compatibilityLevels?.length > 0) { let compatibilityLevels = this.viewInfo.compatibilityLevels?.options;
this.objectInfo.compatibilityLevel = this.viewInfo.compatibilityLevels[0]; if (compatibilityLevels?.length > 0) {
let defaultIndex = this.viewInfo.compatibilityLevels.defaultValueIndex;
this.objectInfo.compatibilityLevel = compatibilityLevels[defaultIndex];
let compatibilityDropbox = this.createDropdown(localizedConstants.CompatibilityLevelText, async () => { let compatibilityDropbox = this.createDropdown(localizedConstants.CompatibilityLevelText, async () => {
this.objectInfo.compatibilityLevel = compatibilityDropbox.value as string; this.objectInfo.compatibilityLevel = compatibilityDropbox.value as string;
}, this.viewInfo.compatibilityLevels, this.viewInfo.compatibilityLevels[0]); }, compatibilityLevels, compatibilityLevels[defaultIndex]);
containers.push(this.createLabelInputContainer(localizedConstants.CompatibilityLevelText, compatibilityDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.CompatibilityLevelText, compatibilityDropbox));
} }
if (this.viewInfo.containmentTypes?.length > 0) { let containmentTypes = this.viewInfo.containmentTypes?.options;
this.objectInfo.containmentType = this.viewInfo.containmentTypes[0]; if (containmentTypes?.length > 0) {
let defaultIndex = this.viewInfo.containmentTypes.defaultValueIndex;
this.objectInfo.containmentType = containmentTypes[defaultIndex];
let containmentDropbox = this.createDropdown(localizedConstants.ContainmentTypeText, async () => { let containmentDropbox = this.createDropdown(localizedConstants.ContainmentTypeText, async () => {
this.objectInfo.containmentType = containmentDropbox.value as string; this.objectInfo.containmentType = containmentDropbox.value as string;
}, this.viewInfo.containmentTypes, this.viewInfo.containmentTypes[0]); }, containmentTypes, containmentTypes[defaultIndex]);
containers.push(this.createLabelInputContainer(localizedConstants.ContainmentTypeText, containmentDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.ContainmentTypeText, containmentDropbox));
} }
@@ -282,29 +293,34 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
//#region Database Properties - Options Tab //#region Database Properties - Options Tab
private initializeOptionsGeneralSection(): void { private initializeOptionsGeneralSection(): void {
let containers: azdata.Component[] = []; let containers: azdata.Component[] = [];
// Collation // Collation
let collationNames = this.viewInfo.collationNames.options;
let collationDropbox = this.createDropdown(localizedConstants.CollationText, async (newValue) => { let collationDropbox = this.createDropdown(localizedConstants.CollationText, async (newValue) => {
this.objectInfo.collationName = newValue as string; this.objectInfo.collationName = newValue as string;
}, this.viewInfo.collationNames, this.objectInfo.collationName, true, DefaultInputWidth, true, true); }, collationNames, this.objectInfo.collationName, true, DefaultInputWidth, true, true);
containers.push(this.createLabelInputContainer(localizedConstants.CollationText, collationDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.CollationText, collationDropbox));
// Recovery Model // Recovery Model
let displayOptionsArray = this.viewInfo.recoveryModels.length === 0 ? [this.objectInfo.recoveryModel] : this.viewInfo.recoveryModels; let recoveryModels = this.viewInfo.recoveryModels.options;
let isEnabled = this.viewInfo.recoveryModels.length === 0 ? false : true; let displayOptionsArray = recoveryModels.length === 0 ? [this.objectInfo.recoveryModel] : recoveryModels;
let isEnabled = recoveryModels.length === 0 ? false : true;
let recoveryDropbox = this.createDropdown(localizedConstants.RecoveryModelText, async (newValue) => { let recoveryDropbox = this.createDropdown(localizedConstants.RecoveryModelText, async (newValue) => {
this.objectInfo.recoveryModel = newValue as string; this.objectInfo.recoveryModel = newValue as string;
}, displayOptionsArray, this.objectInfo.recoveryModel, isEnabled); }, displayOptionsArray, this.objectInfo.recoveryModel, isEnabled);
containers.push(this.createLabelInputContainer(localizedConstants.RecoveryModelText, recoveryDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.RecoveryModelText, recoveryDropbox));
// Compatibility Level // Compatibility Level
let compatibilityLevels = this.viewInfo.compatibilityLevels.options;
let compatibilityDropbox = this.createDropdown(localizedConstants.CompatibilityLevelText, async (newValue) => { let compatibilityDropbox = this.createDropdown(localizedConstants.CompatibilityLevelText, async (newValue) => {
this.objectInfo.compatibilityLevel = newValue as string; this.objectInfo.compatibilityLevel = newValue as string;
}, this.viewInfo.compatibilityLevels, this.objectInfo.compatibilityLevel); }, compatibilityLevels, this.objectInfo.compatibilityLevel);
containers.push(this.createLabelInputContainer(localizedConstants.CompatibilityLevelText, compatibilityDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.CompatibilityLevelText, compatibilityDropbox));
// Containment Type // Containment Type
displayOptionsArray = this.viewInfo.containmentTypes.length === 0 ? [this.objectInfo.containmentType] : this.viewInfo.containmentTypes; let containmentTypes = this.viewInfo.containmentTypes.options;
isEnabled = this.viewInfo.containmentTypes.length === 0 ? false : true; displayOptionsArray = containmentTypes.length === 0 ? [this.objectInfo.containmentType] : containmentTypes;
isEnabled = containmentTypes.length === 0 ? false : true;
let containmentDropbox = this.createDropdown(localizedConstants.ContainmentTypeText, async (newValue) => { let containmentDropbox = this.createDropdown(localizedConstants.ContainmentTypeText, async (newValue) => {
this.objectInfo.containmentType = newValue as string; this.objectInfo.containmentType = newValue as string;
}, displayOptionsArray, this.objectInfo.containmentType, isEnabled); }, displayOptionsArray, this.objectInfo.containmentType, isEnabled);
@@ -422,20 +438,22 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
this.objectInfo.azureEdition = defaultEdition; this.objectInfo.azureEdition = defaultEdition;
// Service Level Objective options // Service Level Objective options
let sloDetails = this.viewInfo.azureServiceLevelObjectives?.find(details => details.editionDisplayName === defaultEdition); let sloDetails = this.viewInfo.azureServiceLevelObjectives.find(details => details.editionDisplayName === defaultEdition);
let serviceLevels = sloDetails?.details ?? []; let serviceLevels = sloDetails?.editionOptions.options ?? [];
this.objectInfo.azureServiceLevelObjective = serviceLevels[0]; let defaultIndex = sloDetails?.editionOptions.defaultValueIndex ?? 0;
this.objectInfo.azureServiceLevelObjective = serviceLevels[defaultIndex];
let serviceLevelDropbox = this.createDropdown(localizedConstants.CurrentSLOText, async () => { let serviceLevelDropbox = this.createDropdown(localizedConstants.CurrentSLOText, async () => {
this.objectInfo.azureServiceLevelObjective = serviceLevelDropbox.value as string; this.objectInfo.azureServiceLevelObjective = serviceLevelDropbox.value as string;
}, serviceLevels, serviceLevels[0]); }, serviceLevels, serviceLevels[defaultIndex]);
// Maximum Database Size options // Maximum Database Size options
let sizeDetails = this.viewInfo.azureMaxSizes?.find(details => details.editionDisplayName === defaultEdition); let sizeDetails = this.viewInfo.azureMaxSizes.find(details => details.editionDisplayName === defaultEdition);
let maxSizes = sizeDetails?.details ?? []; let maxSizes = sizeDetails?.editionOptions.options ?? [];
this.objectInfo.azureMaxSize = maxSizes[0]; defaultIndex = sizeDetails?.editionOptions.defaultValueIndex ?? 0;
this.objectInfo.azureMaxSize = maxSizes[defaultIndex];
let sizeDropbox = this.createDropdown(localizedConstants.MaxSizeText, async () => { let sizeDropbox = this.createDropdown(localizedConstants.MaxSizeText, async () => {
this.objectInfo.azureMaxSize = sizeDropbox.value as string; this.objectInfo.azureMaxSize = sizeDropbox.value as string;
}, maxSizes, maxSizes[0]); }, maxSizes, maxSizes[defaultIndex]);
// Azure Database Edition options // Azure Database Edition options
let editionDropbox = this.createDropdown(localizedConstants.EditionText, async () => { let editionDropbox = this.createDropdown(localizedConstants.EditionText, async () => {
@@ -444,15 +462,17 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
// Update dropboxes for SLO and Size, since they're edition specific // Update dropboxes for SLO and Size, since they're edition specific
sloDetails = this.viewInfo.azureServiceLevelObjectives?.find(details => details.editionDisplayName === edition); sloDetails = this.viewInfo.azureServiceLevelObjectives?.find(details => details.editionDisplayName === edition);
serviceLevels = sloDetails?.details ?? []; serviceLevels = sloDetails?.editionOptions.options ?? [];
defaultIndex = sloDetails?.editionOptions.defaultValueIndex ?? 0;
serviceLevelDropbox.loading = true; serviceLevelDropbox.loading = true;
await serviceLevelDropbox.updateProperties({ value: serviceLevels[0], values: serviceLevels }); await serviceLevelDropbox.updateProperties({ value: serviceLevels[defaultIndex], values: serviceLevels });
serviceLevelDropbox.loading = false; serviceLevelDropbox.loading = false;
sizeDetails = this.viewInfo.azureMaxSizes?.find(details => details.editionDisplayName === edition); sizeDetails = this.viewInfo.azureMaxSizes?.find(details => details.editionDisplayName === edition);
maxSizes = sizeDetails?.details ?? []; maxSizes = sizeDetails?.editionOptions.options ?? [];
defaultIndex = sizeDetails?.editionOptions.defaultValueIndex ?? 0;
sizeDropbox.loading = true; sizeDropbox.loading = true;
await sizeDropbox.updateProperties({ value: maxSizes[0], values: maxSizes }); await sizeDropbox.updateProperties({ value: maxSizes[defaultIndex], values: maxSizes });
sizeDropbox.loading = false; sizeDropbox.loading = false;
}, this.viewInfo.azureEditions, defaultEdition); }, this.viewInfo.azureEditions, defaultEdition);