mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 01:25:37 -05:00
Strict null pass on some base ui files (#4832)
* more strict null checks in base browser code * revert changes to radiobutton * fix some more minor things, enable strict null check in pipelines * formatting * fix compile errors * make null undefined * more null to undefined
This commit is contained in:
@@ -141,51 +141,54 @@ export class PanelComponent extends Disposable {
|
||||
* Select a tab based on index (unrecommended)
|
||||
* @param index index of tab in the html
|
||||
*/
|
||||
selectTab(index: number);
|
||||
selectTab(index: number): void;
|
||||
/**
|
||||
* Select a tab based on the identifier that was passed into the tab
|
||||
* @param identifier specified identifer of the tab
|
||||
*/
|
||||
selectTab(identifier: string);
|
||||
selectTab(identifier: string): void;
|
||||
/**
|
||||
* Select a tab directly if you have access to the object
|
||||
* @param tab tab to navigate to
|
||||
*/
|
||||
selectTab(tab: TabComponent);
|
||||
selectTab(input: TabComponent | number | string) {
|
||||
selectTab(tab: TabComponent): void;
|
||||
selectTab(input: TabComponent | number | string): void {
|
||||
if (this._tabs && this._tabs.length > 0) {
|
||||
let tab: TabComponent;
|
||||
let foundTab: TabComponent | undefined;
|
||||
if (input instanceof TabComponent) {
|
||||
tab = input;
|
||||
foundTab = input;
|
||||
} else if (types.isNumber(input)) {
|
||||
tab = this._tabs.toArray()[input];
|
||||
foundTab = this._tabs.toArray()[input];
|
||||
} else if (types.isString(input)) {
|
||||
tab = this._tabs.find(i => i.identifier === input);
|
||||
foundTab = this._tabs.find(i => i.identifier === input);
|
||||
}
|
||||
|
||||
// since we need to compare identifiers in this next step we are going to go through and make sure all tabs have one
|
||||
this._tabs.forEach(i => {
|
||||
if (!i.identifier) {
|
||||
i.identifier = 'tabIndex_' + idPool++;
|
||||
}
|
||||
});
|
||||
if (foundTab) {
|
||||
const tab = foundTab;
|
||||
// since we need to compare identifiers in this next step we are going to go through and make sure all tabs have one
|
||||
this._tabs.forEach(i => {
|
||||
if (!i.identifier) {
|
||||
i.identifier = 'tabIndex_' + idPool++;
|
||||
}
|
||||
});
|
||||
|
||||
if (this._activeTab && tab === this._activeTab) {
|
||||
this.onTabChange.emit(tab);
|
||||
return;
|
||||
if (this._activeTab && tab === this._activeTab) {
|
||||
this.onTabChange.emit(tab);
|
||||
return;
|
||||
}
|
||||
|
||||
this._zone.run(() => {
|
||||
if (this._activeTab) {
|
||||
this._activeTab.active = false;
|
||||
}
|
||||
|
||||
this._activeTab = tab;
|
||||
this.setMostRecentlyUsed(tab);
|
||||
this._activeTab.active = true;
|
||||
|
||||
this.onTabChange.emit(tab);
|
||||
});
|
||||
}
|
||||
|
||||
this._zone.run(() => {
|
||||
if (this._activeTab) {
|
||||
this._activeTab.active = false;
|
||||
}
|
||||
|
||||
this._activeTab = tab;
|
||||
this.setMostRecentlyUsed(tab);
|
||||
this._activeTab.active = true;
|
||||
|
||||
this.onTabChange.emit(tab);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export type PanelTabIdentifier = string;
|
||||
|
||||
export class TabbedPanel extends Disposable implements IThemable {
|
||||
private _tabMap = new Map<PanelTabIdentifier, IInternalPanelTab>();
|
||||
private _shownTab: PanelTabIdentifier;
|
||||
private _shownTabId?: PanelTabIdentifier;
|
||||
public readonly headersize = 35;
|
||||
private header: HTMLElement;
|
||||
private tabList: HTMLElement;
|
||||
@@ -103,7 +103,7 @@ export class TabbedPanel extends Disposable implements IThemable {
|
||||
internalTab.disposables = [];
|
||||
this._tabMap.set(tab.identifier, internalTab);
|
||||
this._createTab(internalTab);
|
||||
if (!this._shownTab) {
|
||||
if (!this._shownTabId) {
|
||||
this.showTab(tab.identifier);
|
||||
}
|
||||
if (this._tabMap.size > 1 && !this._headerVisible) {
|
||||
@@ -147,24 +147,23 @@ export class TabbedPanel extends Disposable implements IThemable {
|
||||
}
|
||||
|
||||
public showTab(id: PanelTabIdentifier): void {
|
||||
if (this._shownTab && this._shownTab === id) {
|
||||
if (this._shownTabId === id || !this._tabMap.has(id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._shownTab) {
|
||||
DOM.removeClass(this._tabMap.get(this._shownTab).label, 'active');
|
||||
DOM.removeClass(this._tabMap.get(this._shownTab).header, 'active');
|
||||
this._tabMap.get(this._shownTab).header.setAttribute('aria-selected', 'false');
|
||||
if (this._shownTabId) {
|
||||
const shownTab = this._tabMap.get(this._shownTabId);
|
||||
if (shownTab) {
|
||||
DOM.removeClass(shownTab.label, 'active');
|
||||
DOM.removeClass(shownTab.header, 'active');
|
||||
shownTab.header.setAttribute('aria-selected', 'false');
|
||||
shownTab.body.remove();
|
||||
}
|
||||
}
|
||||
|
||||
let prevTab = this._tabMap.get(this._shownTab);
|
||||
if (prevTab) {
|
||||
prevTab.body.remove();
|
||||
}
|
||||
|
||||
this._shownTab = id;
|
||||
this._shownTabId = id;
|
||||
this.tabHistory.push(id);
|
||||
let tab = this._tabMap.get(this._shownTab);
|
||||
const tab = this._tabMap.get(this._shownTabId)!; // @anthonydresser we know this can't be undefined since we check further up if the map contains the id
|
||||
if (!tab.body) {
|
||||
tab.body = DOM.$('.tab-container');
|
||||
tab.body.style.width = '100%';
|
||||
@@ -183,7 +182,10 @@ export class TabbedPanel extends Disposable implements IThemable {
|
||||
}
|
||||
|
||||
public removeTab(tab: PanelTabIdentifier) {
|
||||
let actualTab = this._tabMap.get(tab);
|
||||
const actualTab = this._tabMap.get(tab);
|
||||
if (!actualTab) {
|
||||
return;
|
||||
}
|
||||
if (actualTab.view && actualTab.view.remove) {
|
||||
actualTab.view.remove();
|
||||
}
|
||||
@@ -195,12 +197,14 @@ export class TabbedPanel extends Disposable implements IThemable {
|
||||
}
|
||||
dispose(actualTab.disposables);
|
||||
this._tabMap.delete(tab);
|
||||
if (this._shownTab === tab) {
|
||||
this._shownTab = undefined;
|
||||
while (this._shownTab === undefined && this.tabHistory.length > 0) {
|
||||
if (this._shownTabId === tab) {
|
||||
this._shownTabId = undefined;
|
||||
while (this._shownTabId === undefined && this.tabHistory.length > 0) {
|
||||
let lastTab = this.tabHistory.shift();
|
||||
if (this._tabMap.get(lastTab)) {
|
||||
this.showTab(lastTab);
|
||||
if (lastTab) {
|
||||
if (this._tabMap.get(lastTab)) {
|
||||
this.showTab(lastTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,11 +234,13 @@ export class TabbedPanel extends Disposable implements IThemable {
|
||||
}
|
||||
|
||||
private _layoutCurrentTab(dimension: DOM.Dimension): void {
|
||||
if (this._shownTab) {
|
||||
let tab = this._tabMap.get(this._shownTab);
|
||||
tab.body.style.width = dimension.width + 'px';
|
||||
tab.body.style.height = dimension.height + 'px';
|
||||
tab.view.layout(dimension);
|
||||
if (this._shownTabId) {
|
||||
const tab = this._tabMap.get(this._shownTabId);
|
||||
if (tab) {
|
||||
tab.body.style.width = dimension.width + 'px';
|
||||
tab.body.style.height = dimension.height + 'px';
|
||||
tab.view.layout(dimension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export abstract class TabChild extends Disposable {
|
||||
})
|
||||
export class TabComponent implements OnDestroy {
|
||||
private _child: TabChild;
|
||||
@ContentChild(TemplateRef) templateRef;
|
||||
@ContentChild(TemplateRef) templateRef: TemplateRef<any>;
|
||||
@Input() public title: string;
|
||||
@Input() public canClose: boolean;
|
||||
@Input() public actions: Array<Action>;
|
||||
@@ -32,8 +32,7 @@ export class TabComponent implements OnDestroy {
|
||||
private rendered = false;
|
||||
private destroyed: boolean = false;
|
||||
|
||||
|
||||
@ContentChild(TabChild) private set child(tab: TabChild) {
|
||||
@ContentChild(TabChild) public set child(tab: TabChild) {
|
||||
this._child = tab;
|
||||
if (this.active && this._child) {
|
||||
this._child.layout();
|
||||
|
||||
Reference in New Issue
Block a user