mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Use faster, editable dropdown for Collations in database dialogs (#23974)
* Also fixed an issue where a manually edited text field doesn't get updated when selecting the same dropdown value from before the manual edit. --------- Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -161,7 +161,7 @@ export const MemberSectionHeader = localize('objectManagement.membersLabel', "Me
|
||||
export const SchemaText = localize('objectManagement.schemaLabel', "Schema");
|
||||
|
||||
// Database
|
||||
export const DatabaseExistsError = (dbName: string) => localize('objectManagement.databaseExistsError', "Database '{0}' already exists. Choose a different database name.", dbName);
|
||||
export const CollationNotValidError = (collationName: string) => localize('objectManagement.collationNotValidError', "The selected collation '{0}' is not valid. Please choose a different collation.", collationName);
|
||||
export const CollationText = localize('objectManagement.collationLabel', "Collation");
|
||||
export const RecoveryModelText = localize('objectManagement.recoveryModelLabel', "Recovery Model");
|
||||
export const CompatibilityLevelText = localize('objectManagement.compatibilityLevelLabel', "Compatibility Level");
|
||||
|
||||
@@ -134,6 +134,14 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
|
||||
}
|
||||
}
|
||||
|
||||
protected override async validateInput(): Promise<string[]> {
|
||||
let errors = await super.validateInput();
|
||||
if (this.viewInfo.collationNames?.length > 0 && !this.viewInfo.collationNames.some(name => name.toLowerCase() === this.objectInfo.collationName?.toLowerCase())) {
|
||||
errors.push(localizedConstants.CollationNotValidError(this.objectInfo.collationName ?? ''));
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
//#region Create Database
|
||||
private initializeGeneralSection(): azdata.GroupContainer {
|
||||
let containers: azdata.Component[] = [];
|
||||
@@ -167,7 +175,7 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
|
||||
this.objectInfo.collationName = this.viewInfo.collationNames[0];
|
||||
let collationDropbox = this.createDropdown(localizedConstants.CollationText, async () => {
|
||||
this.objectInfo.collationName = collationDropbox.value as string;
|
||||
}, this.viewInfo.collationNames, this.viewInfo.collationNames[0]);
|
||||
}, this.viewInfo.collationNames, this.viewInfo.collationNames[0], true, DefaultInputWidth, true, true);
|
||||
containers.push(this.createLabelInputContainer(localizedConstants.CollationText, collationDropbox));
|
||||
}
|
||||
|
||||
@@ -277,7 +285,7 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
|
||||
// Collation
|
||||
let collationDropbox = this.createDropdown(localizedConstants.CollationText, async (newValue) => {
|
||||
this.objectInfo.collationName = newValue as string;
|
||||
}, this.viewInfo.collationNames, this.objectInfo.collationName);
|
||||
}, this.viewInfo.collationNames, this.objectInfo.collationName, true, DefaultInputWidth, true, true);
|
||||
containers.push(this.createLabelInputContainer(localizedConstants.CollationText, collationDropbox));
|
||||
|
||||
// Recovery Model
|
||||
|
||||
@@ -27,7 +27,6 @@ export const DefaultTableListItemEnabledStateGetter: TableListItemEnabledStateGe
|
||||
export const DefaultTableListItemValueGetter: TableListItemValueGetter<any> = (item: any) => [item?.toString() ?? ''];
|
||||
export const DefaultTableListItemComparer: TableListItemComparer<any> = (item1: any, item2: any) => item1 === item2;
|
||||
|
||||
|
||||
export abstract class DialogBase<DialogResult> {
|
||||
protected readonly disposables: vscode.Disposable[] = [];
|
||||
protected readonly dialogObject: azdata.window.Dialog;
|
||||
@@ -287,7 +286,7 @@ export abstract class DialogBase<DialogResult> {
|
||||
return this.createButtonContainer([addButton, removeButton]);
|
||||
}
|
||||
|
||||
protected createDropdown(ariaLabel: string, handler: (newValue: string) => Promise<void>, values: string[], value: string | undefined, enabled: boolean = true, width: number = DefaultInputWidth): azdata.DropDownComponent {
|
||||
protected createDropdown(ariaLabel: string, handler: (newValue: string) => Promise<void>, values: string[], value: string | undefined, enabled: boolean = true, width: number = DefaultInputWidth, editable?: boolean, strictSelection?: boolean): azdata.DropDownComponent {
|
||||
// Automatically add an empty item to the beginning of the list if the current value is not specified.
|
||||
// This is needed when no meaningful default value can be provided.
|
||||
// Create a new array so that the original array isn't modified.
|
||||
@@ -301,7 +300,9 @@ export abstract class DialogBase<DialogResult> {
|
||||
values: dropdownValues,
|
||||
value: value,
|
||||
width: width,
|
||||
enabled: enabled
|
||||
enabled: enabled,
|
||||
editable: editable,
|
||||
strictSelection: strictSelection
|
||||
}).component();
|
||||
this.disposables.push(dropdown.onValueChanged(async () => {
|
||||
await handler(<string>dropdown.value!);
|
||||
|
||||
Reference in New Issue
Block a user