Refactor create inputbox method (#24113)

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
Barbara Valdez
2023-08-15 13:36:02 -07:00
committed by GitHub
parent 8cbbf9eaeb
commit 3fbca593be
9 changed files with 284 additions and 67 deletions

View File

@@ -143,10 +143,26 @@ export abstract class DialogBase<DialogResult> {
}
protected createPasswordInputBox(ariaLabel: string, textChangeHandler: (newValue: string) => Promise<void>, value: string = '', enabled: boolean = true, width: number = DefaultInputWidth): azdata.InputBoxComponent {
return this.createInputBox(ariaLabel, textChangeHandler, value, enabled, 'password', width);
return this.createInputBox(textChangeHandler, {
ariaLabel: ariaLabel,
value: value,
enabled: enabled,
inputType: 'password',
width: width
});
}
protected createInputBoxWithProperties(textChangeHandler: (newValue: string) => Promise<void>, properties: azdata.InputBoxProperties, customValidation?: () => Promise<boolean>): azdata.InputBoxComponent {
/**
* Creates an input box. If properties are not passed in, then an input box is created with the following default properties:
* inputType - text
* width - DefaultInputWidth
* value - empty
* enabled - true
* @param textChangeHandler - Function called on text changed.
* @param properties - Inputbox properties.
* @param customValidation - Dynamic validation function.
*/
protected createInputBox(textChangeHandler: (newValue: string) => Promise<void>, properties: azdata.InputBoxProperties, customValidation?: () => Promise<boolean>): azdata.InputBoxComponent {
properties.width = properties.width ?? DefaultInputWidth;
properties.inputType = properties.inputType ?? 'text';
properties.value = properties.value ?? '';
@@ -164,16 +180,6 @@ export abstract class DialogBase<DialogResult> {
return inputBoxComponent;
}
protected createInputBox(ariaLabel: string, textChangeHandler: (newValue: string) => Promise<void>, value: string = '', enabled: boolean = true, type: azdata.InputBoxInputType = 'text', width: number = DefaultInputWidth, required?: boolean, min?: number, max?: number): azdata.InputBoxComponent {
const inputbox = this.modelView.modelBuilder.inputBox().withProps({ inputType: type, enabled: enabled, ariaLabel: ariaLabel, value: value, width: width, required: required, min: min, max: max }).component();
this.disposables.push(inputbox.onTextChanged(async () => {
await textChangeHandler(inputbox.value!);
this.onFormFieldChange();
await this.runValidation(false);
}));
return inputbox;
}
protected createGroup(header: string, items: azdata.Component[], collapsible: boolean = true, collapsed: boolean = false): azdata.GroupContainer {
return this.modelView.modelBuilder.groupContainer().withLayout({
header: header,