mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Allow WithValidation on ComponentBuilder to register async callbacks (#12950)
This commit is contained in:
2
src/sql/azdata.d.ts
vendored
2
src/sql/azdata.d.ts
vendored
@@ -2612,7 +2612,7 @@ declare module 'azdata' {
|
|||||||
export interface ComponentBuilder<TComponent extends Component, TPropertyBag extends ComponentProperties> {
|
export interface ComponentBuilder<TComponent extends Component, TPropertyBag extends ComponentProperties> {
|
||||||
component(): TComponent;
|
component(): TComponent;
|
||||||
withProperties<U>(properties: U): ComponentBuilder<TComponent, TPropertyBag>;
|
withProperties<U>(properties: U): ComponentBuilder<TComponent, TPropertyBag>;
|
||||||
withValidation(validation: (component: TComponent) => boolean): ComponentBuilder<TComponent, TPropertyBag>;
|
withValidation(validation: (component: TComponent) => boolean | Thenable<boolean>): ComponentBuilder<TComponent, TPropertyBag>;
|
||||||
}
|
}
|
||||||
export interface ContainerBuilder<TComponent extends Component, TLayout, TItemLayout, TPropertyBag extends ComponentProperties> extends ComponentBuilder<TComponent, TPropertyBag> {
|
export interface ContainerBuilder<TComponent extends Component, TLayout, TItemLayout, TPropertyBag extends ComponentProperties> extends ComponentBuilder<TComponent, TPropertyBag> {
|
||||||
withLayout(layout: TLayout): ContainerBuilder<TComponent, TLayout, TItemLayout, TPropertyBag>;
|
withLayout(layout: TLayout): ContainerBuilder<TComponent, TLayout, TItemLayout, TPropertyBag>;
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ class ModelBuilderImpl implements azdata.ModelBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public runCustomValidations(componentId: string): boolean {
|
public runCustomValidations(componentId: string): Thenable<boolean> {
|
||||||
let component = this._componentBuilders.get(componentId).componentWrapper();
|
let component = this._componentBuilders.get(componentId).componentWrapper();
|
||||||
return component.runCustomValidations();
|
return component.runCustomValidations();
|
||||||
}
|
}
|
||||||
@@ -323,7 +323,7 @@ class ComponentBuilderImpl<T extends azdata.Component, TPropertyBag extends azda
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
withValidation(validation: (component: T) => boolean): azdata.ComponentBuilder<T, TPropertyBag> {
|
withValidation(validation: (component: T) => boolean | Thenable<boolean>): azdata.ComponentBuilder<T, TPropertyBag> {
|
||||||
this._component.customValidations.push(validation);
|
this._component.customValidations.push(validation);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -574,7 +574,7 @@ class ComponentWrapper implements azdata.Component {
|
|||||||
public properties: { [key: string]: any } = {};
|
public properties: { [key: string]: any } = {};
|
||||||
public layout: any;
|
public layout: any;
|
||||||
public itemConfigs: InternalItemConfig[];
|
public itemConfigs: InternalItemConfig[];
|
||||||
public customValidations: ((component: ThisType<ComponentWrapper>) => boolean)[] = [];
|
public customValidations: ((component: ThisType<ComponentWrapper>) => boolean | Thenable<boolean>)[] = [];
|
||||||
private _valid: boolean = true;
|
private _valid: boolean = true;
|
||||||
private _onValidityChangedEmitter = new Emitter<boolean>();
|
private _onValidityChangedEmitter = new Emitter<boolean>();
|
||||||
public readonly onValidityChanged = this._onValidityChangedEmitter.event;
|
public readonly onValidityChanged = this._onValidityChangedEmitter.event;
|
||||||
@@ -808,14 +808,14 @@ class ComponentWrapper implements azdata.Component {
|
|||||||
this._onErrorEmitter.fire(err);
|
this._onErrorEmitter.fire(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
public runCustomValidations(): boolean {
|
public async runCustomValidations(): Promise<boolean> {
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
try {
|
try {
|
||||||
this.customValidations.forEach(validation => {
|
await Promise.all(this.customValidations.map(async validation => {
|
||||||
if (!validation(this)) {
|
if (!await validation(this)) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
}
|
}
|
||||||
@@ -1988,7 +1988,7 @@ class ModelViewImpl implements azdata.ModelView {
|
|||||||
return this._proxy.$validate(this._handle, this._component.id);
|
return this._proxy.$validate(this._handle, this._component.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public runCustomValidations(componentId: string): boolean {
|
public runCustomValidations(componentId: string): Thenable<boolean> {
|
||||||
return this._modelBuilder.runCustomValidations(componentId);
|
return this._modelBuilder.runCustomValidations(componentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2035,6 +2035,6 @@ export class ExtHostModelView implements ExtHostModelViewShape {
|
|||||||
|
|
||||||
$runCustomValidations(handle: number, componentId: string): Thenable<boolean> {
|
$runCustomValidations(handle: number, componentId: string): Thenable<boolean> {
|
||||||
const view = this._modelViews.get(handle);
|
const view = this._modelViews.get(handle);
|
||||||
return Promise.resolve(view.runCustomValidations(componentId));
|
return view.runCustomValidations(componentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user