diff --git a/src/sql/platform/dashboard/browser/interfaces.ts b/src/sql/platform/dashboard/browser/interfaces.ts index 5ed5a83068..1d86c98449 100644 --- a/src/sql/platform/dashboard/browser/interfaces.ts +++ b/src/sql/platform/dashboard/browser/interfaces.ts @@ -99,7 +99,7 @@ export interface IComponent extends IDisposable { setProperties?: (properties: { [key: string]: any; }) => void; enabled: boolean; readonly valid?: boolean; - validate(): Thenable; + validate(): Promise; setDataProvider(handle: number, componentId: string, context: any): void; refreshDataProvider(item: any): void; focus(): void; diff --git a/src/sql/platform/model/browser/modelViewService.ts b/src/sql/platform/model/browser/modelViewService.ts index 5fb75a0430..9a43e79ebc 100644 --- a/src/sql/platform/model/browser/modelViewService.ts +++ b/src/sql/platform/model/browser/modelViewService.ts @@ -42,7 +42,7 @@ export interface IModelView extends IView { refreshDataProvider(componentId: string, item: any): void; registerEvent(componentId: string, initial?: boolean): void; onEvent: Event; - validate(componentId: string): Thenable; + validate(componentId: string): Promise; readonly onDestroy: Event; focus(componentId: string): void; doAction(componentId: string, action: string, ...args: any[]): void; diff --git a/src/sql/workbench/browser/modelComponents/checkbox.component.ts b/src/sql/workbench/browser/modelComponents/checkbox.component.ts index 16131a2e73..eba30c1546 100644 --- a/src/sql/workbench/browser/modelComponents/checkbox.component.ts +++ b/src/sql/workbench/browser/modelComponents/checkbox.component.ts @@ -17,6 +17,7 @@ import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/work import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/platform/dashboard/browser/interfaces'; import { isNumber } from 'vs/base/common/types'; import { convertSize } from 'sql/base/browser/dom'; +import { onUnexpectedError } from 'vs/base/common/errors'; import { ILogService } from 'vs/platform/log/common/log'; @Component({ @@ -94,7 +95,7 @@ export default class CheckBoxComponent extends ComponentBase { + public async validate(): Promise { let validations = this._validations.map(validation => Promise.resolve(validation())); - return Promise.all(validations).then(values => { - let isValid = values.every(value => value === true); - if (this._valid !== isValid) { - this._valid = isValid; - this.fireEvent({ - eventType: ComponentEventType.validityChanged, - args: this._valid - }); - } - return isValid; - }); + const validationResults = await Promise.all(validations); + const isValid = validationResults.every(value => value === true); + if (this._valid !== isValid) { + this._valid = isValid; + this.fireEvent({ + eventType: ComponentEventType.validityChanged, + args: this._valid + }); + } + return isValid; } public focus(): void { @@ -320,7 +320,7 @@ export abstract class ContainerBase { if (event.eventType === ComponentEventType.validityChanged) { this.logService.debug(`Running validation on container ${this.descriptor.id} because validity of child component ${componentDescriptor.id} changed`); - this.validate(); + this.validate().catch(onUnexpectedError); } }); }, true); @@ -347,7 +347,7 @@ export abstract class ContainerBase { - return super.validate().then(valid => { - // TODO: tree validation? - return valid; - }); - } - ngOnDestroy(): void { this.baseDestroy(); } @@ -115,7 +108,6 @@ export default class FileBrowserTreeComponent extends ComponentBase { - return super.validate().then(valid => { - const otherErrorMsg = valid || this.inputElement.value === '' ? undefined : this.validationErrorMessage; - valid = valid && this.inputElement.validate(); + public async validate(): Promise { + let valid = await super.validate(); + const otherErrorMsg = valid || this.inputElement.value === '' ? undefined : this.validationErrorMessage; + valid = valid && this.inputElement.validate(); - // set aria label based on validity of input - if (valid) { - this.inputElement.setAriaLabel(this.ariaLabel); - } else { - if (otherErrorMsg) { - this.inputElement.showMessage({ type: MessageType.ERROR, content: otherErrorMsg }, true); - } - if (this.ariaLabel) { - this.inputElement.setAriaLabel(nls.localize('period', "{0}. {1}", this.ariaLabel, this.inputElement.inputElement.validationMessage)); - } else { - this.inputElement.setAriaLabel(this.inputElement.inputElement.validationMessage); - } + // set aria label based on validity of input + if (valid) { + this.inputElement.setAriaLabel(this.ariaLabel); + } else { + if (otherErrorMsg) { + this.inputElement.showMessage({ type: MessageType.ERROR, content: otherErrorMsg }, true); } - - return valid; - }); + if (this.ariaLabel) { + this.inputElement.setAriaLabel(nls.localize('period', "{0}. {1}", this.ariaLabel, this.inputElement.inputElement.validationMessage)); + } else { + this.inputElement.setAriaLabel(this.inputElement.inputElement.validationMessage); + } + } + return valid; } ngOnDestroy(): void { @@ -208,7 +207,7 @@ export default class InputBoxComponent extends ComponentBase { - return super.validate().then(valid => { - return valid; - }); - } - ngOnDestroy(): void { this.baseDestroy(); } @@ -99,8 +93,6 @@ export default class ListBoxComponent extends ComponentBase { return { text: value }; }), this.selectedRow); - - this.validate(); } // CSS-bound properties diff --git a/src/sql/workbench/browser/modelComponents/table.component.ts b/src/sql/workbench/browser/modelComponents/table.component.ts index 4075408bf5..aa024f17b9 100644 --- a/src/sql/workbench/browser/modelComponents/table.component.ts +++ b/src/sql/workbench/browser/modelComponents/table.component.ts @@ -30,6 +30,7 @@ import { convertSizeToNumber } from 'sql/base/browser/dom'; import { ButtonColumn, ButtonClickEventArgs } from 'sql/base/browser/ui/table/plugins/buttonColumn.plugin'; import { IUserFriendlyIcon, createIconCssClass, getIconKey } from 'sql/workbench/browser/modelComponents/iconUtils'; import { HeaderFilter } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin'; +import { onUnexpectedError } from 'vs/base/common/errors'; import { ILogService } from 'vs/platform/log/common/log'; export enum ColumnSizingMode { @@ -238,13 +239,6 @@ export default class TableComponent extends ComponentBase { - return super.validate().then(valid => { - // TODO: table validation? - return valid; - }); - } - ngOnDestroy(): void { this.baseDestroy(); } @@ -346,7 +340,7 @@ export default class TableComponent extends ComponentBase { + public validate(componentId: string): Promise { return new Promise(resolve => this.modelStore.eventuallyRunOnComponent(componentId, component => resolve(component.validate()), false)); }