mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Genericify components (#12158)
* Genericify components * Fix compile issue * Fix feedback * Genericify azdata components (#12164) * azdata generics * Add the withProps method to azdata proposed as there may be mistakes with the interfaces in the generics * Fix build issues because of other extensions * Remove extra spaces
This commit is contained in:
@@ -430,22 +430,27 @@ class TestFlexContainer extends TestComponentBase implements azdata.FlexContaine
|
||||
}
|
||||
}
|
||||
|
||||
class TestComponentBuilder<T extends azdata.Component> implements azdata.ComponentBuilder<T> {
|
||||
class TestComponentBuilder<T extends azdata.Component, TPropertyBag> implements azdata.ComponentBuilder<T, TPropertyBag> {
|
||||
constructor(private _component: T) {
|
||||
}
|
||||
component(): T {
|
||||
return this._component;
|
||||
}
|
||||
withProperties<U>(properties: U): azdata.ComponentBuilder<T> {
|
||||
withProperties<U>(properties: U): azdata.ComponentBuilder<T, TPropertyBag> {
|
||||
this._component.updateProperties(properties);
|
||||
return this;
|
||||
}
|
||||
withValidation(validation: (component: T) => boolean): azdata.ComponentBuilder<T> {
|
||||
withValidation(validation: (component: T) => boolean): azdata.ComponentBuilder<T, TPropertyBag> {
|
||||
return this;
|
||||
}
|
||||
|
||||
withProps(properties: TPropertyBag): azdata.ComponentBuilder<T, TPropertyBag> {
|
||||
this._component.updateProperties(properties);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
class TestLoadingBuilder extends TestComponentBuilder<azdata.LoadingComponent> implements azdata.LoadingComponentBuilder {
|
||||
class TestLoadingBuilder extends TestComponentBuilder<azdata.LoadingComponent, azdata.LoadingComponentProperties> implements azdata.LoadingComponentBuilder {
|
||||
withItem(component: azdata.Component): azdata.LoadingComponentBuilder {
|
||||
this.component().component = component;
|
||||
return this;
|
||||
@@ -456,12 +461,12 @@ export function createViewContext(): TestContext {
|
||||
let onClick: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
|
||||
|
||||
let form: azdata.FormContainer = new TestFormContainer();
|
||||
let textBuilder: azdata.ComponentBuilder<azdata.TextComponent> = new TestComponentBuilder(new TestTextComponent());
|
||||
let buttonBuilder: azdata.ComponentBuilder<azdata.ButtonComponent> = new TestComponentBuilder(new TestButtonComponent(onClick));
|
||||
let radioButtonBuilder: azdata.ComponentBuilder<azdata.ButtonComponent> = new TestComponentBuilder(new TestRadioButtonComponent(onClick));
|
||||
let declarativeTableBuilder: azdata.ComponentBuilder<azdata.DeclarativeTableComponent> = new TestComponentBuilder(new TestDeclarativeTableComponent(onClick));
|
||||
let textBuilder: azdata.ComponentBuilder<azdata.TextComponent, azdata.TextComponentProperties> = new TestComponentBuilder(new TestTextComponent());
|
||||
let buttonBuilder: azdata.ComponentBuilder<azdata.ButtonComponent, azdata.ButtonProperties> = new TestComponentBuilder(new TestButtonComponent(onClick));
|
||||
let radioButtonBuilder: azdata.ComponentBuilder<azdata.RadioButtonComponent, azdata.RadioButtonProperties> = new TestComponentBuilder(new TestRadioButtonComponent(onClick));
|
||||
let declarativeTableBuilder: azdata.ComponentBuilder<azdata.DeclarativeTableComponent, azdata.DeclarativeTableProperties> = new TestComponentBuilder(new TestDeclarativeTableComponent(onClick));
|
||||
let loadingBuilder: azdata.LoadingComponentBuilder = new TestLoadingBuilder(new TestLoadingComponent());
|
||||
let dropdownBuilder: azdata.ComponentBuilder<azdata.DropDownComponent> = new TestComponentBuilder(new TestDropdownComponent(onClick));
|
||||
let dropdownBuilder: azdata.ComponentBuilder<azdata.DropDownComponent, azdata.DropDownProperties> = new TestComponentBuilder(new TestDropdownComponent(onClick));
|
||||
|
||||
let formBuilder: azdata.FormBuilder = Object.assign({}, {
|
||||
component: () => form,
|
||||
@@ -473,7 +478,8 @@ export function createViewContext(): TestContext {
|
||||
withProperties: () => formBuilder,
|
||||
withValidation: () => formBuilder,
|
||||
withItems: () => formBuilder,
|
||||
withLayout: () => formBuilder
|
||||
withLayout: () => formBuilder,
|
||||
withProps: () => formBuilder
|
||||
});
|
||||
|
||||
let div: azdata.DivContainer = new TestDivContainer();
|
||||
@@ -487,7 +493,8 @@ export function createViewContext(): TestContext {
|
||||
withProperties: () => divBuilder,
|
||||
withValidation: () => divBuilder,
|
||||
withItems: () => divBuilder,
|
||||
withLayout: () => divBuilder
|
||||
withLayout: () => divBuilder,
|
||||
withProps: () => divBuilder
|
||||
});
|
||||
|
||||
let flex: azdata.FlexContainer = new TestFlexContainer();
|
||||
@@ -501,7 +508,8 @@ export function createViewContext(): TestContext {
|
||||
withProperties: () => flexBuilder,
|
||||
withValidation: () => flexBuilder,
|
||||
withItems: () => flexBuilder,
|
||||
withLayout: () => flexBuilder
|
||||
withLayout: () => flexBuilder,
|
||||
withProps: () => flexBuilder
|
||||
});
|
||||
|
||||
let view: azdata.ModelView = {
|
||||
|
||||
@@ -150,15 +150,17 @@ describe('Manage Package Dialog', () => {
|
||||
let flex: azdata.FlexContainer = Object.assign({}, componentBase, container, {
|
||||
});
|
||||
|
||||
let buttonBuilder: azdata.ComponentBuilder<azdata.ButtonComponent> = {
|
||||
let buttonBuilder: azdata.ComponentBuilder<azdata.ButtonComponent, azdata.ButtonProperties> = {
|
||||
component: () => button,
|
||||
withProperties: () => buttonBuilder,
|
||||
withValidation: () => buttonBuilder
|
||||
withValidation: () => buttonBuilder,
|
||||
withProps: () => buttonBuilder
|
||||
};
|
||||
let radioButtonBuilder: azdata.ComponentBuilder<azdata.ButtonComponent> = {
|
||||
let radioButtonBuilder: azdata.ComponentBuilder<azdata.RadioButtonComponent, azdata.RadioButtonProperties> = {
|
||||
component: () => radioButton,
|
||||
withProperties: () => radioButtonBuilder,
|
||||
withValidation: () => radioButtonBuilder
|
||||
withValidation: () => radioButtonBuilder,
|
||||
withProps: () => radioButtonBuilder
|
||||
};
|
||||
let inputBox: () => azdata.InputBoxComponent = () => Object.assign({}, componentBase, {
|
||||
onTextChanged: undefined!,
|
||||
@@ -187,17 +189,19 @@ describe('Manage Package Dialog', () => {
|
||||
component: undefined!
|
||||
});
|
||||
|
||||
let declarativeTableBuilder: azdata.ComponentBuilder<azdata.DeclarativeTableComponent> = {
|
||||
let declarativeTableBuilder: azdata.ComponentBuilder<azdata.DeclarativeTableComponent, azdata.DeclarativeTableProperties> = {
|
||||
component: () => declarativeTable(),
|
||||
withProperties: () => declarativeTableBuilder,
|
||||
withValidation: () => declarativeTableBuilder
|
||||
withValidation: () => declarativeTableBuilder,
|
||||
withProps: () => declarativeTableBuilder
|
||||
};
|
||||
|
||||
let loadingBuilder: azdata.LoadingComponentBuilder = {
|
||||
component: () => loadingComponent(),
|
||||
withProperties: () => loadingBuilder,
|
||||
withValidation: () => loadingBuilder,
|
||||
withItem: () => loadingBuilder
|
||||
withItem: () => loadingBuilder,
|
||||
withProps: () => loadingBuilder
|
||||
};
|
||||
|
||||
let formBuilder: azdata.FormBuilder = Object.assign({}, {
|
||||
@@ -210,7 +214,8 @@ describe('Manage Package Dialog', () => {
|
||||
withProperties: () => formBuilder,
|
||||
withValidation: () => formBuilder,
|
||||
withItems: () => formBuilder,
|
||||
withLayout: () => formBuilder
|
||||
withLayout: () => formBuilder,
|
||||
withProps: () => formBuilder
|
||||
});
|
||||
|
||||
let flexBuilder: azdata.FlexBuilder = Object.assign({}, {
|
||||
@@ -218,32 +223,36 @@ describe('Manage Package Dialog', () => {
|
||||
withProperties: () => flexBuilder,
|
||||
withValidation: () => flexBuilder,
|
||||
withItems: () => flexBuilder,
|
||||
withLayout: () => flexBuilder
|
||||
withLayout: () => flexBuilder,
|
||||
withProps: () => flexBuilder
|
||||
});
|
||||
|
||||
let inputBoxBuilder: azdata.ComponentBuilder<azdata.InputBoxComponent> = {
|
||||
let inputBoxBuilder: azdata.ComponentBuilder<azdata.InputBoxComponent, azdata.InputBoxProperties> = {
|
||||
component: () => {
|
||||
let r = inputBox();
|
||||
return r;
|
||||
},
|
||||
withProperties: () => inputBoxBuilder,
|
||||
withValidation: () => inputBoxBuilder
|
||||
withValidation: () => inputBoxBuilder,
|
||||
withProps: () => inputBoxBuilder
|
||||
};
|
||||
let imageBuilder: azdata.ComponentBuilder<azdata.ImageComponent> = {
|
||||
let imageBuilder: azdata.ComponentBuilder<azdata.ImageComponent, azdata.ImageComponentProperties> = {
|
||||
component: () => {
|
||||
let r = image();
|
||||
return r;
|
||||
},
|
||||
withProperties: () => imageBuilder,
|
||||
withValidation: () => imageBuilder
|
||||
withValidation: () => imageBuilder,
|
||||
withProps: () => imageBuilder
|
||||
};
|
||||
let dropdownBuilder: azdata.ComponentBuilder<azdata.DropDownComponent> = {
|
||||
let dropdownBuilder: azdata.ComponentBuilder<azdata.DropDownComponent, azdata.DropDownProperties> = {
|
||||
component: () => {
|
||||
let r = dropdown();
|
||||
return r;
|
||||
},
|
||||
withProperties: () => dropdownBuilder,
|
||||
withValidation: () => dropdownBuilder
|
||||
withValidation: () => dropdownBuilder,
|
||||
withProps: () => dropdownBuilder
|
||||
};
|
||||
|
||||
let view: azdata.ModelView = {
|
||||
|
||||
Reference in New Issue
Block a user