Strict compile for sql/workbench/services/dialog (#12578)

* Strict compile for sql/workbench/services/dialog

* fix errors
This commit is contained in:
Charles Gagnon
2020-09-23 13:15:59 -07:00
committed by GitHub
parent e1235a7346
commit 4e07685588
8 changed files with 72 additions and 68 deletions

View File

@@ -83,7 +83,7 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
public $setDialogDetails(handle: number, details: IModelViewDialogDetails): Thenable<void> { public $setDialogDetails(handle: number, details: IModelViewDialogDetails): Thenable<void> {
let dialog = this._dialogs.get(handle); let dialog = this._dialogs.get(handle);
if (!dialog) { if (!dialog) {
dialog = new Dialog(details.title); dialog = new Dialog(details.title, details.width);
let okButton = this.getButton(details.okButton); let okButton = this.getButton(details.okButton);
let cancelButton = this.getButton(details.cancelButton); let cancelButton = this.getButton(details.cancelButton);
dialog.okButton = okButton; dialog.okButton = okButton;
@@ -91,10 +91,11 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
dialog.onValidityChanged(valid => this._proxy.$onPanelValidityChanged(handle, valid)); dialog.onValidityChanged(valid => this._proxy.$onPanelValidityChanged(handle, valid));
dialog.registerCloseValidator(() => this.validateDialogClose(handle)); dialog.registerCloseValidator(() => this.validateDialogClose(handle));
this._dialogs.set(handle, dialog); this._dialogs.set(handle, dialog);
} } else {
dialog.title = details.title; dialog.title = details.title;
dialog.width = details.width; dialog.width = details.width;
}
if (details.content && typeof details.content !== 'string') { if (details.content && typeof details.content !== 'string') {
dialog.content = details.content.map(tabHandle => this.getTab(tabHandle)); dialog.content = details.content.map(tabHandle => this.getTab(tabHandle));
} else { } else {
@@ -165,13 +166,13 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
public $setWizardDetails(handle: number, details: IModelViewWizardDetails): Thenable<void> { public $setWizardDetails(handle: number, details: IModelViewWizardDetails): Thenable<void> {
let wizard = this._wizards.get(handle); let wizard = this._wizards.get(handle);
if (!wizard) { if (!wizard) {
wizard = new Wizard(details.title); wizard = new Wizard(details.title,
this.getButton(details.doneButton),
this.getButton(details.cancelButton),
this.getButton(details.nextButton),
this.getButton(details.backButton),
this.getButton(details.generateScriptButton));
wizard.width = details.width; wizard.width = details.width;
wizard.backButton = this.getButton(details.backButton);
wizard.cancelButton = this.getButton(details.cancelButton);
wizard.generateScriptButton = this.getButton(details.generateScriptButton);
wizard.doneButton = this.getButton(details.doneButton);
wizard.nextButton = this.getButton(details.nextButton);
wizard.onPageChanged(info => this._proxy.$onWizardPageChanged(handle, info)); wizard.onPageChanged(info => this._proxy.$onWizardPageChanged(handle, info));
wizard.onPageAdded(() => this.handleWizardPageAddedOrRemoved(handle)); wizard.onPageAdded(() => this.handleWizardPageAddedOrRemoved(handle));
wizard.onPageRemoved(() => this.handleWizardPageAddedOrRemoved(handle)); wizard.onPageRemoved(() => this.handleWizardPageAddedOrRemoved(handle));

View File

@@ -26,11 +26,10 @@ import { InputBox } from 'sql/platform/browser/inputbox/inputBox.component';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Registry } from 'vs/platform/registry/common/platform'; import { Registry } from 'vs/platform/registry/common/platform';
import { IBootstrapParams, ISelector } from 'sql/workbench/services/bootstrap/common/bootstrapParams'; import { IBootstrapParams, ISelector } from 'sql/workbench/services/bootstrap/common/bootstrapParams';
import { startsWith } from 'vs/base/common/strings';
import { PanelModule } from 'sql/base/browser/ui/panel/panel.module'; import { PanelModule } from 'sql/base/browser/ui/panel/panel.module';
import { PropertiesContainerModule } from 'sql/base/browser/ui/propertiesContainer/propertiesContainer.module'; import { PropertiesContainerModule } from 'sql/base/browser/ui/propertiesContainer/propertiesContainer.module';
export const DialogModule = (params, selector: string, instantiationService: IInstantiationService): any => { export const DialogModule = (params: IBootstrapParams, selector: string, instantiationService: IInstantiationService): any => {
/* Model-backed components */ /* Model-backed components */
let extensionComponents = Registry.as<IComponentRegistry>(Extensions.ComponentContribution).getAllCtors(); let extensionComponents = Registry.as<IComponentRegistry>(Extensions.ComponentContribution).getAllCtors();
@@ -73,7 +72,7 @@ export const DialogModule = (params, selector: string, instantiationService: IIn
} }
ngDoBootstrap(appRef: ApplicationRef) { ngDoBootstrap(appRef: ApplicationRef) {
let componentClass = startsWith(this.selector, WizardNavigation.SELECTOR) ? WizardNavigation : DialogContainer; let componentClass = this.selector.startsWith(WizardNavigation.SELECTOR) ? WizardNavigation : DialogContainer;
const factoryWrapper: any = this._resolver.resolveComponentFactory<WizardNavigation | DialogContainer>(componentClass); const factoryWrapper: any = this._resolver.resolveComponentFactory<WizardNavigation | DialogContainer>(componentClass);
factoryWrapper.factory.selector = this.selector; factoryWrapper.factory.selector = this.selector;
appRef.bootstrap(factoryWrapper); appRef.bootstrap(factoryWrapper);

View File

@@ -48,7 +48,7 @@ export class DialogContainer implements AfterViewInit {
public _dialogPane: DialogPane; public _dialogPane: DialogPane;
public modelViewId: string; public modelViewId: string;
@ViewChild(ModelViewContent) private _modelViewContent: ModelViewContent; @ViewChild(ModelViewContent) private _modelViewContent!: ModelViewContent;
constructor( constructor(
@Inject(forwardRef(() => ElementRef)) private _el: ElementRef, @Inject(forwardRef(() => ElementRef)) private _el: ElementRef,
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,

View File

@@ -24,16 +24,16 @@ import { attachTabbedPanelStyler } from 'sql/workbench/common/styler';
import { localize } from 'vs/nls'; import { localize } from 'vs/nls';
export class DialogPane extends Disposable implements IThemable { export class DialogPane extends Disposable implements IThemable {
private _tabbedPanel: TabbedPanel; private _tabbedPanel: TabbedPanel | undefined;
private _moduleRefs: NgModuleRef<{}>[] = []; private _moduleRefs: NgModuleRef<{}>[] = [];
// Validation // Validation
private _modelViewValidityMap = new Map<string, boolean>(); private _modelViewValidityMap = new Map<string, boolean>();
private _body: HTMLElement; private _body!: HTMLElement;
private _selectedTabIndex: number = 0; //TODO: can be an option private _selectedTabIndex: number = 0; //TODO: can be an option
private _onLayoutChange = new Emitter<LayoutRequestParams>(); private _onLayoutChange = new Emitter<LayoutRequestParams>();
private _selectedTabContent: string; private _selectedTabContent: string = '';
public pageNumber?: number; public pageNumber?: number;
constructor( constructor(
@@ -68,11 +68,11 @@ export class DialogPane extends Disposable implements IThemable {
tabContainer.style.display = 'none'; tabContainer.style.display = 'none';
this._body.appendChild(tabContainer); this._body.appendChild(tabContainer);
this.initializeModelViewContainer(tabContainer, tab.content, tab); this.initializeModelViewContainer(tabContainer, tab.content, tab);
this._tabbedPanel.onTabChange(e => { this._tabbedPanel!.onTabChange(e => {
tabContainer.style.height = (this.getTabDimension().height - this._tabbedPanel.headersize) + 'px'; tabContainer.style.height = (this.getTabDimension().height - this._tabbedPanel!.headersize) + 'px';
this._onLayoutChange.fire({ modelViewId: tab.content }); this._onLayoutChange.fire({ modelViewId: tab.content });
}); });
this._tabbedPanel.pushTab({ this._tabbedPanel!.pushTab({
title: tab.title, title: tab.title,
identifier: 'dialogPane.' + this.title + '.' + tabIndex, identifier: 'dialogPane.' + this.title + '.' + tabIndex,
view: { view: {
@@ -130,7 +130,7 @@ export class DialogPane extends Disposable implements IThemable {
dialogPane: this dialogPane: this
} as DialogComponentParams, } as DialogComponentParams,
undefined, undefined,
(moduleRef) => { (moduleRef: NgModuleRef<{}>) => {
return this._moduleRefs.push(moduleRef); return this._moduleRefs.push(moduleRef);
}); });
} }
@@ -155,8 +155,8 @@ export class DialogPane extends Disposable implements IThemable {
* Called by the theme registry on theme change to style the component * Called by the theme registry on theme change to style the component
*/ */
public style(styles: IModalDialogStyles): void { public style(styles: IModalDialogStyles): void {
this._body.style.backgroundColor = styles.dialogBodyBackground ? styles.dialogBodyBackground.toString() : undefined; this._body.style.backgroundColor = styles.dialogBodyBackground ? styles.dialogBodyBackground.toString() : '';
this._body.style.color = styles.dialogForeground ? styles.dialogForeground.toString() : undefined; this._body.style.color = styles.dialogForeground ? styles.dialogForeground.toString() : '';
} }
private _setValidity(modelViewId: string, valid: boolean) { private _setValidity(modelViewId: string, valid: boolean) {

View File

@@ -74,12 +74,10 @@ export class WizardModal extends Modal {
attachButtonStyler(this.backButton, this._themeService, { buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND }); attachButtonStyler(this.backButton, this._themeService, { buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND });
} }
if (this._wizard.customButtons) {
this._wizard.customButtons.forEach(button => { this._wizard.customButtons.forEach(button => {
let buttonElement = this.addDialogButton(button); let buttonElement = this.addDialogButton(button);
this.updateButtonElement(buttonElement, button); this.updateButtonElement(buttonElement, button);
}); });
}
this._previousButton = this.addDialogButton(this._wizard.backButton, () => this.showPage(this._wizard.currentPage - 1)); this._previousButton = this.addDialogButton(this._wizard.backButton, () => this.showPage(this._wizard.currentPage - 1));
this._nextButton = this.addDialogButton(this._wizard.nextButton, () => this.showPage(this._wizard.currentPage + 1, true, true), true, true); this._nextButton = this.addDialogButton(this._wizard.nextButton, () => this.showPage(this._wizard.currentPage + 1, true, true), true, true);

View File

@@ -12,8 +12,8 @@ import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
import { IBootstrapParams } from 'sql/workbench/services/bootstrap/common/bootstrapParams'; import { IBootstrapParams } from 'sql/workbench/services/bootstrap/common/bootstrapParams';
export class WizardNavigationParams implements IBootstrapParams { export class WizardNavigationParams implements IBootstrapParams {
wizard: Wizard; wizard!: Wizard;
navigationHandler: (index: number) => void; navigationHandler!: (index: number) => void;
} }
@Component({ @Component({
@@ -39,7 +39,7 @@ export class WizardNavigation implements AfterViewInit {
private _onResize = new Emitter<void>(); private _onResize = new Emitter<void>();
public readonly onResize: Event<void> = this._onResize.event; public readonly onResize: Event<void> = this._onResize.event;
@ViewChild('container', { read: ElementRef }) private _container: ElementRef; @ViewChild('container', { read: ElementRef }) private _container!: ElementRef;
constructor( constructor(
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
@Inject(IBootstrapParams) private _params: WizardNavigationParams, @Inject(IBootstrapParams) private _params: WizardNavigationParams,
@@ -77,6 +77,9 @@ export class WizardNavigation implements AfterViewInit {
private style(): void { private style(): void {
let theme = this._themeService.getColorTheme(); let theme = this._themeService.getColorTheme();
let navigationBackgroundColor = theme.getColor(SIDE_BAR_BACKGROUND); let navigationBackgroundColor = theme.getColor(SIDE_BAR_BACKGROUND);
if (!navigationBackgroundColor) {
return;
}
if (theme.type === 'light') { if (theme.type === 'light') {
navigationBackgroundColor = navigationBackgroundColor.lighten(0.03); navigationBackgroundColor = navigationBackgroundColor.lighten(0.03);
} else if (theme.type === 'dark') { } else if (theme.type === 'dark') {

View File

@@ -26,7 +26,7 @@ export class ModelViewPane {
} }
export class DialogTab extends ModelViewPane { export class DialogTab extends ModelViewPane {
public content: string; public content: string = '';
constructor(public title: string, content?: string) { constructor(public title: string, content?: string) {
super(); super();
@@ -36,37 +36,38 @@ export class DialogTab extends ModelViewPane {
} }
} }
export type CloseValidator = () => boolean | Thenable<boolean>;
export class Dialog extends ModelViewPane { export class Dialog extends ModelViewPane {
private static readonly DONE_BUTTON_LABEL = localize('dialogModalDoneButtonLabel', "Done"); private static readonly DONE_BUTTON_LABEL = localize('dialogModalDoneButtonLabel', "Done");
private static readonly CANCEL_BUTTON_LABEL = localize('dialogModalCancelButtonLabel', "Cancel"); private static readonly CANCEL_BUTTON_LABEL = localize('dialogModalCancelButtonLabel', "Cancel");
public content: string | DialogTab[]; public content: string | DialogTab[] = '';
public width: DialogWidth;
public okButton: DialogButton = new DialogButton(Dialog.DONE_BUTTON_LABEL, true); public okButton: DialogButton = new DialogButton(Dialog.DONE_BUTTON_LABEL, true);
public cancelButton: DialogButton = new DialogButton(Dialog.CANCEL_BUTTON_LABEL, true); public cancelButton: DialogButton = new DialogButton(Dialog.CANCEL_BUTTON_LABEL, true);
public customButtons: DialogButton[]; public customButtons: DialogButton[] = [];
private _onMessageChange = new Emitter<DialogMessage>(); private _onMessageChange = new Emitter<DialogMessage | undefined>();
public readonly onMessageChange = this._onMessageChange.event; public readonly onMessageChange = this._onMessageChange.event;
private _message: DialogMessage; private _message: DialogMessage | undefined;
private _closeValidator: () => boolean | Thenable<boolean>; private _closeValidator: CloseValidator | undefined;
constructor(public title: string, content?: string | DialogTab[]) { constructor(public title: string, public width: DialogWidth, content?: string | DialogTab[]) {
super(); super();
if (content) { if (content) {
this.content = content; this.content = content;
} }
} }
public get message(): DialogMessage { public get message(): DialogMessage | undefined {
return this._message; return this._message;
} }
public set message(value: DialogMessage) { public set message(value: DialogMessage | undefined) {
this._message = value; this._message = value;
this._onMessageChange.fire(this._message); this._onMessageChange.fire(this._message);
} }
public registerCloseValidator(validator: () => boolean | Thenable<boolean>): void { public registerCloseValidator(validator: CloseValidator): void {
this._closeValidator = validator; this._closeValidator = validator;
} }
@@ -83,7 +84,7 @@ export class DialogButton implements azdata.window.Button {
private _label: string; private _label: string;
private _enabled: boolean; private _enabled: boolean;
private _hidden: boolean; private _hidden: boolean;
private _focused: boolean; private _focused: boolean | undefined;
private _position?: azdata.window.DialogButtonPosition; private _position?: azdata.window.DialogButtonPosition;
private _onClick: Emitter<void> = new Emitter<void>(); private _onClick: Emitter<void> = new Emitter<void>();
public readonly onClick: Event<void> = this._onClick.event; public readonly onClick: Event<void> = this._onClick.event;
@@ -123,11 +124,11 @@ export class DialogButton implements azdata.window.Button {
this._onUpdate.fire(); this._onUpdate.fire();
} }
public get focused(): boolean { public get focused(): boolean | undefined {
return this._focused; return this._focused;
} }
public set focused(focused: boolean) { public set focused(focused: boolean | undefined) {
this._focused = focused; this._focused = focused;
this._onUpdate.fire(); this._onUpdate.fire();
} }
@@ -150,9 +151,9 @@ export class DialogButton implements azdata.window.Button {
} }
export class WizardPage extends DialogTab { export class WizardPage extends DialogTab {
public customButtons: DialogButton[]; public customButtons: DialogButton[] = [];
private _enabled: boolean; private _enabled: boolean = false;
private _description: string; private _description: string | undefined;
private _onUpdate: Emitter<void> = new Emitter<void>(); private _onUpdate: Emitter<void> = new Emitter<void>();
public readonly onUpdate: Event<void> = this._onUpdate.event; public readonly onUpdate: Event<void> = this._onUpdate.event;
@@ -169,39 +170,41 @@ export class WizardPage extends DialogTab {
this._onUpdate.fire(); this._onUpdate.fire();
} }
public get description(): string { public get description(): string | undefined {
return this._description; return this._description;
} }
public set description(description: string) { public set description(description: string | undefined) {
this._description = description; this._description = description;
this._onUpdate.fire(); this._onUpdate.fire();
} }
} }
export type NavigationValidator = (pageChangeInfo: azdata.window.WizardPageChangeInfo) => boolean | Thenable<boolean>;
export class Wizard { export class Wizard {
public pages: WizardPage[]; public pages: WizardPage[] = [];
public nextButton: DialogButton; public customButtons: DialogButton[] = [];
public backButton: DialogButton; private _currentPage: number = -1;
public generateScriptButton: DialogButton;
public doneButton: DialogButton;
public cancelButton: DialogButton;
public customButtons: DialogButton[];
private _currentPage: number;
private _pageChangedEmitter = new Emitter<azdata.window.WizardPageChangeInfo>(); private _pageChangedEmitter = new Emitter<azdata.window.WizardPageChangeInfo>();
public readonly onPageChanged = this._pageChangedEmitter.event; public readonly onPageChanged = this._pageChangedEmitter.event;
private _pageAddedEmitter = new Emitter<WizardPage>(); private _pageAddedEmitter = new Emitter<WizardPage>();
public readonly onPageAdded = this._pageAddedEmitter.event; public readonly onPageAdded = this._pageAddedEmitter.event;
private _pageRemovedEmitter = new Emitter<WizardPage>(); private _pageRemovedEmitter = new Emitter<WizardPage>();
public readonly onPageRemoved = this._pageRemovedEmitter.event; public readonly onPageRemoved = this._pageRemovedEmitter.event;
private _navigationValidator: (pageChangeInfo: azdata.window.WizardPageChangeInfo) => boolean | Thenable<boolean>; private _navigationValidator: NavigationValidator | undefined;
private _onMessageChange = new Emitter<DialogMessage>(); private _onMessageChange = new Emitter<DialogMessage | undefined>();
public readonly onMessageChange = this._onMessageChange.event; public readonly onMessageChange = this._onMessageChange.event;
private _message: DialogMessage; private _message: DialogMessage | undefined;
public displayPageTitles: boolean; public displayPageTitles: boolean = false;
public width: DialogWidth; public width: DialogWidth | undefined;
constructor(public title: string) { } constructor(public title: string,
public doneButton: DialogButton,
public cancelButton: DialogButton,
public nextButton: DialogButton,
public backButton: DialogButton,
public generateScriptButton: DialogButton) { }
public get currentPage(): number { public get currentPage(): number {
return this._currentPage; return this._currentPage;
@@ -253,7 +256,7 @@ export class Wizard {
this._pageRemovedEmitter.fire(removedPage); this._pageRemovedEmitter.fire(removedPage);
} }
public registerNavigationValidator(validator: (pageChangeInfo: azdata.window.WizardPageChangeInfo) => boolean | Thenable<boolean>): void { public registerNavigationValidator(validator: NavigationValidator): void {
this._navigationValidator = validator; this._navigationValidator = validator;
} }
@@ -268,11 +271,11 @@ export class Wizard {
} }
} }
public get message(): DialogMessage { public get message(): DialogMessage | undefined {
return this._message; return this._message;
} }
public set message(value: DialogMessage) { public set message(value: DialogMessage | undefined) {
this._message = value; this._message = value;
this._onMessageChange.fire(this._message); this._onMessageChange.fire(this._message);
} }

View File

@@ -27,7 +27,7 @@ suite('Dialog Pane Tests', () => {
} }
setup(() => { setup(() => {
dialog = new Dialog('test_dialog'); dialog = new Dialog('test_dialog', 'narrow');
container = document.createElement('div'); container = document.createElement('div');
bootstrapSave = bootstrapAngular; bootstrapSave = bootstrapAngular;
}); });