mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Convert ModelView validate to Promise (#13390)
* Convert ModelView validate to Promise * more cleanup
This commit is contained in:
@@ -99,7 +99,7 @@ export interface IComponent extends IDisposable {
|
|||||||
setProperties?: (properties: { [key: string]: any; }) => void;
|
setProperties?: (properties: { [key: string]: any; }) => void;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
readonly valid?: boolean;
|
readonly valid?: boolean;
|
||||||
validate(): Thenable<boolean>;
|
validate(): Promise<boolean>;
|
||||||
setDataProvider(handle: number, componentId: string, context: any): void;
|
setDataProvider(handle: number, componentId: string, context: any): void;
|
||||||
refreshDataProvider(item: any): void;
|
refreshDataProvider(item: any): void;
|
||||||
focus(): void;
|
focus(): void;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export interface IModelView extends IView {
|
|||||||
refreshDataProvider(componentId: string, item: any): void;
|
refreshDataProvider(componentId: string, item: any): void;
|
||||||
registerEvent(componentId: string, initial?: boolean): void;
|
registerEvent(componentId: string, initial?: boolean): void;
|
||||||
onEvent: Event<IModelViewEventArgs>;
|
onEvent: Event<IModelViewEventArgs>;
|
||||||
validate(componentId: string): Thenable<boolean>;
|
validate(componentId: string): Promise<boolean>;
|
||||||
readonly onDestroy: Event<void>;
|
readonly onDestroy: Event<void>;
|
||||||
focus(componentId: string): void;
|
focus(componentId: string): void;
|
||||||
doAction(componentId: string, action: string, ...args: any[]): void;
|
doAction(componentId: string, action: string, ...args: any[]): void;
|
||||||
|
|||||||
@@ -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 { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/platform/dashboard/browser/interfaces';
|
||||||
import { isNumber } from 'vs/base/common/types';
|
import { isNumber } from 'vs/base/common/types';
|
||||||
import { convertSize } from 'sql/base/browser/dom';
|
import { convertSize } from 'sql/base/browser/dom';
|
||||||
|
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -94,7 +95,7 @@ export default class CheckBoxComponent extends ComponentBase<azdata.CheckBoxProp
|
|||||||
if (this.required) {
|
if (this.required) {
|
||||||
this._input.required = this.required;
|
this._input.required = this.required;
|
||||||
}
|
}
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CSS-bound properties
|
// CSS-bound properties
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { EventType, addDisposableListener } from 'vs/base/browser/dom';
|
|||||||
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||||
import { IComponentDescriptor, IComponent, IModelStore, IComponentEventArgs, ComponentEventType } from 'sql/platform/dashboard/browser/interfaces';
|
import { IComponentDescriptor, IComponent, IModelStore, IComponentEventArgs, ComponentEventType } from 'sql/platform/dashboard/browser/interfaces';
|
||||||
import { convertSize } from 'sql/base/browser/dom';
|
import { convertSize } from 'sql/base/browser/dom';
|
||||||
|
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
export type IUserFriendlyIcon = string | URI | { light: string | URI; dark: string | URI };
|
export type IUserFriendlyIcon = string | URI | { light: string | URI; dark: string | URI };
|
||||||
@@ -97,7 +98,7 @@ export abstract class ComponentBase<TPropertyBag extends azdata.ComponentPropert
|
|||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
this.updateStyles();
|
this.updateStyles();
|
||||||
this.layout();
|
this.layout();
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper Function to update single property
|
// Helper Function to update single property
|
||||||
@@ -106,7 +107,7 @@ export abstract class ComponentBase<TPropertyBag extends azdata.ComponentPropert
|
|||||||
this.properties[key] = value;
|
this.properties[key] = value;
|
||||||
this.updateStyles();
|
this.updateStyles();
|
||||||
this.layout();
|
this.layout();
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ export abstract class ComponentBase<TPropertyBag extends azdata.ComponentPropert
|
|||||||
eventType: ComponentEventType.PropertiesChanged,
|
eventType: ComponentEventType.PropertiesChanged,
|
||||||
args: this.getProperties()
|
args: this.getProperties()
|
||||||
});
|
});
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get enabled(): boolean {
|
public get enabled(): boolean {
|
||||||
@@ -246,10 +247,10 @@ export abstract class ComponentBase<TPropertyBag extends azdata.ComponentPropert
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public validate(): Thenable<boolean> {
|
public async validate(): Promise<boolean> {
|
||||||
let validations = this._validations.map(validation => Promise.resolve(validation()));
|
let validations = this._validations.map(validation => Promise.resolve(validation()));
|
||||||
return Promise.all(validations).then(values => {
|
const validationResults = await Promise.all(validations);
|
||||||
let isValid = values.every(value => value === true);
|
const isValid = validationResults.every(value => value === true);
|
||||||
if (this._valid !== isValid) {
|
if (this._valid !== isValid) {
|
||||||
this._valid = isValid;
|
this._valid = isValid;
|
||||||
this.fireEvent({
|
this.fireEvent({
|
||||||
@@ -258,7 +259,6 @@ export abstract class ComponentBase<TPropertyBag extends azdata.ComponentPropert
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return isValid;
|
return isValid;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public focus(): void {
|
public focus(): void {
|
||||||
@@ -320,7 +320,7 @@ export abstract class ContainerBase<T, TPropertyBag extends azdata.ComponentProp
|
|||||||
component.registerEventHandler(async event => {
|
component.registerEventHandler(async event => {
|
||||||
if (event.eventType === ComponentEventType.validityChanged) {
|
if (event.eventType === ComponentEventType.validityChanged) {
|
||||||
this.logService.debug(`Running validation on container ${this.descriptor.id} because validity of child component ${componentDescriptor.id} changed`);
|
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);
|
}, true);
|
||||||
@@ -347,7 +347,7 @@ export abstract class ContainerBase<T, TPropertyBag extends azdata.ComponentProp
|
|||||||
this.items = [];
|
this.items = [];
|
||||||
this.onItemsUpdated();
|
this.onItemsUpdated();
|
||||||
this._changeRef.detectChanges();
|
this._changeRef.detectChanges();
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setProperties(properties: { [key: string]: any; }): void {
|
public setProperties(properties: { [key: string]: any; }): void {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import { SimpleProgressIndicator } from 'sql/workbench/services/progress/browser
|
|||||||
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
|
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
|
||||||
import { IComponent, IComponentDescriptor, IModelStore } from 'sql/platform/dashboard/browser/interfaces';
|
import { IComponent, IComponentDescriptor, IModelStore } from 'sql/platform/dashboard/browser/interfaces';
|
||||||
import { convertSizeToNumber } from 'sql/base/browser/dom';
|
import { convertSizeToNumber } from 'sql/base/browser/dom';
|
||||||
|
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -101,7 +102,7 @@ export default class DiffEditorComponent extends ComponentBase<azdata.DiffEditor
|
|||||||
this._editorModel = model as TextDiffEditorModel;
|
this._editorModel = model as TextDiffEditorModel;
|
||||||
this.updateModel();
|
this.updateModel();
|
||||||
this.layout();
|
this.layout();
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._register(this._editor);
|
this._register(this._editor);
|
||||||
@@ -173,7 +174,7 @@ export default class DiffEditorComponent extends ComponentBase<azdata.DiffEditor
|
|||||||
this._minimumHeight = this.minimumHeight;
|
this._minimumHeight = this.minimumHeight;
|
||||||
this._title = this.title;
|
this._title = this.title;
|
||||||
this.layout();
|
this.layout();
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CSS-bound properties
|
// CSS-bound properties
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
|
|||||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/platform/dashboard/browser/interfaces';
|
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/platform/dashboard/browser/interfaces';
|
||||||
import { localize } from 'vs/nls';
|
import { localize } from 'vs/nls';
|
||||||
|
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -162,7 +163,7 @@ export default class DropDownComponent extends ComponentBase<azdata.DropDownProp
|
|||||||
|
|
||||||
this._selectBox.selectElem.required = this.required;
|
this._selectBox.selectElem.required = this.required;
|
||||||
this._editableDropdown.inputElement.required = this.required;
|
this._editableDropdown.inputElement.required = this.required;
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getValues(): string[] {
|
private getValues(): string[] {
|
||||||
|
|||||||
@@ -91,13 +91,6 @@ export default class FileBrowserTreeComponent extends ComponentBase<azdata.FileB
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public validate(): Thenable<boolean> {
|
|
||||||
return super.validate().then(valid => {
|
|
||||||
// TODO: tree validation?
|
|
||||||
return valid;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.baseDestroy();
|
this.baseDestroy();
|
||||||
}
|
}
|
||||||
@@ -115,7 +108,6 @@ export default class FileBrowserTreeComponent extends ComponentBase<azdata.FileB
|
|||||||
|
|
||||||
public setProperties(properties: { [key: string]: any; }): void {
|
public setProperties(properties: { [key: string]: any; }): void {
|
||||||
super.setProperties(properties);
|
super.setProperties(properties);
|
||||||
this.validate();
|
|
||||||
if (this.ownerUri) {
|
if (this.ownerUri) {
|
||||||
this.initialize();
|
this.initialize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { assign } from 'vs/base/common/objects';
|
|||||||
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/platform/dashboard/browser/interfaces';
|
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/platform/dashboard/browser/interfaces';
|
||||||
import { isNumber } from 'vs/base/common/types';
|
import { isNumber } from 'vs/base/common/types';
|
||||||
import { convertSize, convertSizeToNumber } from 'sql/base/browser/dom';
|
import { convertSize, convertSizeToNumber } from 'sql/base/browser/dom';
|
||||||
|
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -157,8 +158,8 @@ export default class InputBoxComponent extends ComponentBase<azdata.InputBoxProp
|
|||||||
return this.multiline ? '' : 'none';
|
return this.multiline ? '' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
public validate(): Thenable<boolean> {
|
public async validate(): Promise<boolean> {
|
||||||
return super.validate().then(valid => {
|
let valid = await super.validate();
|
||||||
const otherErrorMsg = valid || this.inputElement.value === '' ? undefined : this.validationErrorMessage;
|
const otherErrorMsg = valid || this.inputElement.value === '' ? undefined : this.validationErrorMessage;
|
||||||
valid = valid && this.inputElement.validate();
|
valid = valid && this.inputElement.validate();
|
||||||
|
|
||||||
@@ -175,9 +176,7 @@ export default class InputBoxComponent extends ComponentBase<azdata.InputBoxProp
|
|||||||
this.inputElement.setAriaLabel(this.inputElement.inputElement.validationMessage);
|
this.inputElement.setAriaLabel(this.inputElement.inputElement.validationMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
@@ -208,7 +207,7 @@ export default class InputBoxComponent extends ComponentBase<azdata.InputBoxProp
|
|||||||
public setProperties(properties: { [key: string]: any; }): void {
|
public setProperties(properties: { [key: string]: any; }): void {
|
||||||
super.setProperties(properties);
|
super.setProperties(properties);
|
||||||
this.setInputProperties(this.inputElement);
|
this.setInputProperties(this.inputElement);
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setInputProperties(input: InputBox): void {
|
private setInputProperties(input: InputBox): void {
|
||||||
|
|||||||
@@ -80,12 +80,6 @@ export default class ListBoxComponent extends ComponentBase<azdata.ListBoxProper
|
|||||||
this.baseInit();
|
this.baseInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public validate(): Thenable<boolean> {
|
|
||||||
return super.validate().then(valid => {
|
|
||||||
return valid;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.baseDestroy();
|
this.baseDestroy();
|
||||||
}
|
}
|
||||||
@@ -99,8 +93,6 @@ export default class ListBoxComponent extends ComponentBase<azdata.ListBoxProper
|
|||||||
public setProperties(properties: { [key: string]: any; }): void {
|
public setProperties(properties: { [key: string]: any; }): void {
|
||||||
super.setProperties(properties);
|
super.setProperties(properties);
|
||||||
this._input.setOptions(this.values.map(value => { return { text: value }; }), this.selectedRow);
|
this._input.setOptions(this.values.map(value => { return { text: value }; }), this.selectedRow);
|
||||||
|
|
||||||
this.validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CSS-bound properties
|
// CSS-bound properties
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import { convertSizeToNumber } from 'sql/base/browser/dom';
|
|||||||
import { ButtonColumn, ButtonClickEventArgs } from 'sql/base/browser/ui/table/plugins/buttonColumn.plugin';
|
import { ButtonColumn, ButtonClickEventArgs } from 'sql/base/browser/ui/table/plugins/buttonColumn.plugin';
|
||||||
import { IUserFriendlyIcon, createIconCssClass, getIconKey } from 'sql/workbench/browser/modelComponents/iconUtils';
|
import { IUserFriendlyIcon, createIconCssClass, getIconKey } from 'sql/workbench/browser/modelComponents/iconUtils';
|
||||||
import { HeaderFilter } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin';
|
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';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
export enum ColumnSizingMode {
|
export enum ColumnSizingMode {
|
||||||
@@ -238,13 +239,6 @@ export default class TableComponent extends ComponentBase<azdata.TableComponentP
|
|||||||
this.baseInit();
|
this.baseInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public validate(): Thenable<boolean> {
|
|
||||||
return super.validate().then(valid => {
|
|
||||||
// TODO: table validation?
|
|
||||||
return valid;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.baseDestroy();
|
this.baseDestroy();
|
||||||
}
|
}
|
||||||
@@ -346,7 +340,7 @@ export default class TableComponent extends ComponentBase<azdata.TableComponentP
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.layoutTable();
|
this.layoutTable();
|
||||||
this.validate();
|
this.validate().catch(onUnexpectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateTableCells(cellInfos): void {
|
private updateTableCells(cellInfos): void {
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
|
|||||||
return this._onEventEmitter.event;
|
return this._onEventEmitter.event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public validate(componentId: string): Thenable<boolean> {
|
public validate(componentId: string): Promise<boolean> {
|
||||||
return new Promise(resolve => this.modelStore.eventuallyRunOnComponent(componentId, component => resolve(component.validate()), false));
|
return new Promise(resolve => this.modelStore.eventuallyRunOnComponent(componentId, component => resolve(component.validate()), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user