mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 17:22:48 -05:00
Strict null scripting (#12126)
* strict null scripting * fix compile * fix tests * fix icon
This commit is contained in:
@@ -52,7 +52,7 @@ export class AsyncServerTreeDataSource implements IAsyncDataSource<ConnectionPro
|
||||
if (element.children) {
|
||||
return element.children;
|
||||
} else {
|
||||
return await this._objectExplorerService.resolveTreeNodeChildren(element.getSession(), element);
|
||||
return await this._objectExplorerService.resolveTreeNodeChildren(element.getSession()!, element);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -37,15 +37,15 @@ export class AsyncServerTreeDragAndDrop implements ITreeDragAndDrop<ServerTreeEl
|
||||
* Returns a uri if the given element should be allowed to drag.
|
||||
* Returns null, otherwise.
|
||||
*/
|
||||
public getDragURI(element: ServerTreeElement): string {
|
||||
return this._dragAndDrop.getDragURI(this._tree, element);
|
||||
public getDragURI(element: ServerTreeElement): string | null {
|
||||
return this._dragAndDrop.getDragURI(this._tree!, element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a label(name) to display when dragging the element.
|
||||
*/
|
||||
public getDragLabel(elements: ServerTreeElement[]): string {
|
||||
return this._dragAndDrop.getDragLabel(this._tree, elements);
|
||||
return this._dragAndDrop.getDragLabel(this._tree!, elements);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,17 +54,17 @@ export class AsyncServerTreeDragAndDrop implements ITreeDragAndDrop<ServerTreeEl
|
||||
public onDragStart(dragAndDropData: IDragAndDropData, originalEvent: DragEvent): void {
|
||||
// Force the event cast while in preview - we don't use any of the mouse properties on the
|
||||
// implementation so this is fine for now
|
||||
return this._dragAndDrop.onDragStart(this._tree, dragAndDropData, <any>originalEvent);
|
||||
return this._dragAndDrop.onDragStart(this._tree!, dragAndDropData, <any>originalEvent);
|
||||
}
|
||||
|
||||
public onDragOver(data: IDragAndDropData, targetElement: ServerTreeElement, targetIndex: number, originalEvent: DragEvent): boolean | ITreeDragOverReaction {
|
||||
public onDragOver(data: IDragAndDropData, targetElement: ServerTreeElement | undefined, targetIndex: number, originalEvent: DragEvent): boolean | ITreeDragOverReaction {
|
||||
// Dropping onto an empty space (undefined targetElement) we treat as wanting to move into the root connection group
|
||||
if (!targetElement) {
|
||||
targetElement = this._tree?.getInput();
|
||||
}
|
||||
// Force the event cast while in preview - we don't use any of the mouse properties on the
|
||||
// implementation so this is fine for now
|
||||
const canDragOver = this._dragAndDrop.onDragOver(this._tree, data, targetElement, <any>originalEvent);
|
||||
const canDragOver = this._dragAndDrop.onDragOver(this._tree!, data, targetElement, <any>originalEvent);
|
||||
|
||||
if (canDragOver.accept) {
|
||||
return TreeDragOverReactions.acceptBubbleDown(canDragOver.autoExpand);
|
||||
@@ -76,14 +76,14 @@ export class AsyncServerTreeDragAndDrop implements ITreeDragAndDrop<ServerTreeEl
|
||||
/**
|
||||
* Handle a drop in the server tree.
|
||||
*/
|
||||
public drop(data: IDragAndDropData, targetElement: ServerTreeElement, targetIndex: number, originalEvent: DragEvent): void {
|
||||
public drop(data: IDragAndDropData, targetElement: ServerTreeElement | undefined, targetIndex: number, originalEvent: DragEvent): void {
|
||||
// Dropping onto an empty space (undefined targetElement) we treat as wanting to move into the root connection group
|
||||
if (!targetElement) {
|
||||
targetElement = this._tree?.getInput();
|
||||
}
|
||||
// Force the event cast while in preview - we don't use any of the mouse properties on the
|
||||
// implementation so this is fine for now
|
||||
this._dragAndDrop.drop(this._tree, data, targetElement, <any>originalEvent);
|
||||
this._dragAndDrop.drop(this._tree!, data, targetElement, <any>originalEvent);
|
||||
}
|
||||
|
||||
public onDragEnd(originalEvent: DragEvent): void {
|
||||
@@ -102,7 +102,7 @@ export class AsyncRecentConnectionsDragAndDrop implements ITreeDragAndDrop<Serve
|
||||
return (<ConnectionProfile>element).id;
|
||||
}
|
||||
else if (element instanceof ConnectionProfileGroup) {
|
||||
return (<ConnectionProfileGroup>element).id;
|
||||
return (<ConnectionProfileGroup>element).id ?? null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ export class AsyncRecentConnectionsDragAndDrop implements ITreeDragAndDrop<Serve
|
||||
else if (elements[0] instanceof ConnectionProfileGroup) {
|
||||
return elements[0].name;
|
||||
}
|
||||
return undefined;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,6 @@ import { ServerTreeElement } from 'sql/workbench/services/objectExplorer/browser
|
||||
|
||||
export class AsyncServerTreeIdentityProvider implements IIdentityProvider<ServerTreeElement> {
|
||||
getId(element: ServerTreeElement): { toString(): string; } {
|
||||
return element.id;
|
||||
return element.id!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'vs/css!./media/objectTypes/objecttypes';
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
import { localize } from 'vs/nls';
|
||||
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ConnectionProfile, IconPath } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
|
||||
import { iconRenderer } from 'sql/workbench/services/objectExplorer/browser/iconRenderer';
|
||||
@@ -22,6 +22,7 @@ import { IListAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
|
||||
import { ServerTreeRenderer } from 'sql/workbench/services/objectExplorer/browser/serverTreeRenderer';
|
||||
import { ServerTreeElement } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
|
||||
import { DefaultServerGroupColor } from 'sql/workbench/services/serverGroup/common/serverGroupViewModel';
|
||||
import { withNullAsUndefined } from 'vs/base/common/types';
|
||||
|
||||
class ConnectionProfileGroupTemplate extends Disposable {
|
||||
private _root: HTMLElement;
|
||||
@@ -31,7 +32,7 @@ class ConnectionProfileGroupTemplate extends Disposable {
|
||||
container: HTMLElement
|
||||
) {
|
||||
super();
|
||||
container.parentElement.classList.add('server-group');
|
||||
container.parentElement!.classList.add('server-group');
|
||||
container.classList.add('server-group');
|
||||
this._root = dom.append(container, dom.$('.server-group'));
|
||||
this._nameContainer = dom.append(this._root, dom.$('span.name'));
|
||||
@@ -89,7 +90,7 @@ class ConnectionProfileTemplate extends Disposable {
|
||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService
|
||||
) {
|
||||
super();
|
||||
container.parentElement.classList.add('connection-profile');
|
||||
container.parentElement!.classList.add('connection-profile');
|
||||
this._root = dom.append(container, dom.$('.connection-tile'));
|
||||
this._icon = dom.append(this._root, dom.$('div.icon server-page'));
|
||||
this._connectionStatusBadge = dom.append(this._icon, dom.$('div.connection-status-badge'));
|
||||
@@ -98,16 +99,15 @@ class ConnectionProfileTemplate extends Disposable {
|
||||
|
||||
set(element: ConnectionProfile) {
|
||||
if (!this._isCompact) {
|
||||
let iconPath: IconPath = getIconPath(element, this._connectionManagementService);
|
||||
let iconPath: IconPath | undefined = getIconPath(element, this._connectionManagementService);
|
||||
if (this._connectionManagementService.isConnected(undefined, element)) {
|
||||
this._connectionStatusBadge.classList.remove('disconnected');
|
||||
this._connectionStatusBadge.classList.add('connected');
|
||||
renderServerIcon(this._icon, iconPath);
|
||||
} else {
|
||||
this._connectionStatusBadge.classList.remove('connected');
|
||||
this._connectionStatusBadge.classList.add('disconnected');
|
||||
renderServerIcon(this._icon, iconPath);
|
||||
}
|
||||
renderServerIcon(this._icon, iconPath);
|
||||
}
|
||||
|
||||
let label = element.title;
|
||||
@@ -156,7 +156,7 @@ class TreeNodeTemplate extends Disposable {
|
||||
set(element: TreeNode) {
|
||||
// Use an explicitly defined iconType first. If not defined, fall back to using nodeType and
|
||||
// other compount indicators instead.
|
||||
let iconName: string = undefined;
|
||||
let iconName: string | undefined = undefined;
|
||||
if (element.iconType) {
|
||||
iconName = (typeof element.iconType === 'string') ? element.iconType : element.iconType.id;
|
||||
} else {
|
||||
@@ -171,7 +171,7 @@ class TreeNodeTemplate extends Disposable {
|
||||
|
||||
let tokens: string[] = [];
|
||||
for (let index = 1; index < this._icon.classList.length; index++) {
|
||||
tokens.push(this._icon.classList.item(index));
|
||||
tokens.push(this._icon.classList.item(index)!);
|
||||
}
|
||||
this._icon.classList.remove(...tokens);
|
||||
this._icon.classList.add('icon');
|
||||
@@ -229,7 +229,7 @@ export class ServerTreeAccessibilityProvider implements IListAccessibilityProvid
|
||||
|
||||
getAriaLabel(element: ServerTreeElement): string | null {
|
||||
if (element instanceof ConnectionProfileGroup) {
|
||||
return element.fullName;
|
||||
return element.fullName ?? null;
|
||||
} else if (element instanceof ConnectionProfile) {
|
||||
return element.title;
|
||||
}
|
||||
@@ -240,22 +240,22 @@ export class ServerTreeAccessibilityProvider implements IListAccessibilityProvid
|
||||
/**
|
||||
* Returns the first parent which contains the className
|
||||
*/
|
||||
function findParentElement(container: HTMLElement, className: string): HTMLElement {
|
||||
let currentElement = container;
|
||||
function findParentElement(container: HTMLElement, className: string): HTMLElement | undefined {
|
||||
let currentElement: HTMLElement | null = container;
|
||||
while (currentElement) {
|
||||
if (currentElement.className.indexOf(className) > -1) {
|
||||
break;
|
||||
}
|
||||
currentElement = currentElement.parentElement;
|
||||
}
|
||||
return currentElement;
|
||||
return withNullAsUndefined(currentElement);
|
||||
}
|
||||
|
||||
function getIconPath(connection: ConnectionProfile, connectionManagementService: IConnectionManagementService): IconPath {
|
||||
function getIconPath(connection: ConnectionProfile, connectionManagementService: IConnectionManagementService): IconPath | undefined {
|
||||
if (!connection) { return undefined; }
|
||||
|
||||
if (connection['iconPath']) {
|
||||
return connection['iconPath'];
|
||||
if (connection.iconPath) {
|
||||
return connection.iconPath;
|
||||
}
|
||||
|
||||
let iconId = connectionManagementService.getConnectionIconId(connection.id);
|
||||
@@ -264,8 +264,8 @@ function getIconPath(connection: ConnectionProfile, connectionManagementService:
|
||||
let providerProperties = connectionManagementService.getProviderProperties(connection.providerName);
|
||||
if (!providerProperties) { return undefined; }
|
||||
|
||||
let iconPath: IconPath = undefined;
|
||||
let pathConfig: URI | IconPath | { id: string, path: IconPath }[] = providerProperties['iconPath'];
|
||||
let iconPath: IconPath | undefined = undefined;
|
||||
let pathConfig: URI | IconPath | { id: string, path: IconPath }[] | undefined = providerProperties['iconPath'];
|
||||
if (Array.isArray(pathConfig)) {
|
||||
for (const e of pathConfig) {
|
||||
if (!e.id || e.id === iconId) {
|
||||
@@ -274,25 +274,18 @@ function getIconPath(connection: ConnectionProfile, connectionManagementService:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (pathConfig['light']) {
|
||||
iconPath = pathConfig as IconPath;
|
||||
connection['iconPath'] = iconPath;
|
||||
} else if (URI.isUri(pathConfig)) {
|
||||
iconPath = { light: pathConfig, dark: pathConfig };
|
||||
connection.iconPath = iconPath;
|
||||
} else {
|
||||
let singlePath = pathConfig as URI;
|
||||
iconPath = { light: singlePath, dark: singlePath };
|
||||
connection['iconPath'] = iconPath;
|
||||
connection.iconPath = pathConfig;
|
||||
}
|
||||
return iconPath;
|
||||
}
|
||||
|
||||
function renderServerIcon(element: HTMLElement, iconPath: IconPath): void {
|
||||
function renderServerIcon(element: HTMLElement, iconPath?: IconPath): void {
|
||||
if (!element) { return; }
|
||||
if (iconPath) {
|
||||
iconRenderer.putIcon(element, iconPath);
|
||||
}
|
||||
}
|
||||
|
||||
interface IconPath {
|
||||
light: URI;
|
||||
dark: URI;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ export function supportsFolderNodeNameDrop(nodeId: string, label: string): boole
|
||||
return false;
|
||||
}
|
||||
|
||||
function escapeString(input: string): string;
|
||||
function escapeString(input: undefined): undefined;
|
||||
function escapeString(input: string | undefined): string | undefined {
|
||||
return input?.replace(/]/g, ']]');
|
||||
}
|
||||
@@ -46,22 +48,22 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
|
||||
* Returns a uri if the given element should be allowed to drag.
|
||||
* Returns null, otherwise.
|
||||
*/
|
||||
public getDragURI(tree: AsyncServerTree | ITree, element: any): string {
|
||||
public getDragURI(tree: AsyncServerTree | ITree, element: any): string | null {
|
||||
if (element) {
|
||||
if (element instanceof ConnectionProfile) {
|
||||
return (<ConnectionProfile>element).id;
|
||||
return element.id;
|
||||
} else if (element instanceof ConnectionProfileGroup) {
|
||||
return (<ConnectionProfileGroup>element).id;
|
||||
return element.id ?? null;
|
||||
} else if (supportsNodeNameDrop(element.nodeTypeId)) {
|
||||
return (<TreeNode>element).id;
|
||||
} else if (supportsFolderNodeNameDrop(element.nodeTypeId, element.label) && element.children) {
|
||||
return (<TreeNode>element).id;
|
||||
} else {
|
||||
return undefined;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,11 +80,11 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
|
||||
return elements[0].label;
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +127,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
|
||||
return element.connection.providerName;
|
||||
}
|
||||
|
||||
return this.getProviderNameFromElement(element.parent);
|
||||
return this.getProviderNameFromElement(element.parent!);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +135,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
|
||||
let canDragOver: boolean = true;
|
||||
|
||||
if (source instanceof ConnectionProfile) {
|
||||
if (!this._connectionManagementService.canChangeConnectionConfig(source, targetConnectionProfileGroup.id)) {
|
||||
if (!this._connectionManagementService.canChangeConnectionConfig(source, targetConnectionProfileGroup.id!)) {
|
||||
canDragOver = false;
|
||||
}
|
||||
} else if (source instanceof ConnectionProfileGroup) {
|
||||
@@ -158,7 +160,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
|
||||
// Verify if the connection can be moved to the target group
|
||||
const source = data.getData()[0];
|
||||
if (source instanceof ConnectionProfile) {
|
||||
if (!this._connectionManagementService.canChangeConnectionConfig(source, targetConnectionProfileGroup.id)) {
|
||||
if (!this._connectionManagementService.canChangeConnectionConfig(source, targetConnectionProfileGroup.id!)) {
|
||||
canDragOver = false;
|
||||
}
|
||||
} else if (source instanceof ConnectionProfileGroup) {
|
||||
@@ -201,7 +203,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
|
||||
|
||||
if (source instanceof ConnectionProfile) {
|
||||
// Change group id of profile
|
||||
this._connectionManagementService.changeGroupIdForConnection(source, targetConnectionProfileGroup.id).then(() => {
|
||||
this._connectionManagementService.changeGroupIdForConnection(source, targetConnectionProfileGroup.id!).then(() => {
|
||||
if (tree) {
|
||||
TreeUpdateUtils.registeredServerUpdate(tree, self._connectionManagementService, targetConnectionProfileGroup);
|
||||
}
|
||||
@@ -224,13 +226,13 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
|
||||
TreeUpdateUtils.isInDragAndDrop = false;
|
||||
}
|
||||
|
||||
private getTargetGroup(targetElement: any): ConnectionProfileGroup {
|
||||
private getTargetGroup(targetElement: ConnectionProfileGroup | ConnectionProfile): ConnectionProfileGroup {
|
||||
let targetConnectionProfileGroup: ConnectionProfileGroup;
|
||||
if (targetElement instanceof ConnectionProfile) {
|
||||
targetConnectionProfileGroup = (<ConnectionProfile>targetElement).getParent();
|
||||
targetConnectionProfileGroup = targetElement.getParent()!;
|
||||
}
|
||||
else {
|
||||
targetConnectionProfileGroup = <ConnectionProfileGroup>targetElement;
|
||||
targetConnectionProfileGroup = targetElement;
|
||||
}
|
||||
|
||||
return targetConnectionProfileGroup;
|
||||
@@ -256,12 +258,12 @@ export class RecentConnectionsDragAndDrop implements IDragAndDrop {
|
||||
* Returns a uri if the given element should be allowed to drag.
|
||||
* Returns null, otherwise.
|
||||
*/
|
||||
public getDragURI(tree: ITree, element: any): string {
|
||||
public getDragURI(tree: ITree, element: any): string | null {
|
||||
if (element instanceof ConnectionProfile) {
|
||||
return (<ConnectionProfile>element).id;
|
||||
}
|
||||
else if (element instanceof ConnectionProfileGroup) {
|
||||
return (<ConnectionProfileGroup>element).id;
|
||||
return (<ConnectionProfileGroup>element).id ?? null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -276,7 +278,7 @@ export class RecentConnectionsDragAndDrop implements IDragAndDrop {
|
||||
else if (elements[0] instanceof ConnectionProfileGroup) {
|
||||
return (<ConnectionProfileGroup>elements[0]).name;
|
||||
}
|
||||
return undefined;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,11 +10,11 @@ import { URI } from 'vs/base/common/uri';
|
||||
class IconRenderer {
|
||||
private iconRegistered: Set<string> = new Set<string>();
|
||||
|
||||
public registerIcon(path: URI | IconPath): string {
|
||||
public registerIcon(path: URI | IconPath): string | undefined {
|
||||
if (!path) { return undefined; }
|
||||
let iconPath: IconPath = this.toIconPath(path);
|
||||
let iconUid: string = this.getIconUid(iconPath);
|
||||
if (!this.iconRegistered.has(iconUid)) {
|
||||
let iconUid: string | undefined = this.getIconUid(iconPath);
|
||||
if (iconUid && !this.iconRegistered.has(iconUid)) {
|
||||
createCSSRule(`.icon#${iconUid}`, `background: ${asCSSUrl(iconPath.light || iconPath.dark)} center center no-repeat`);
|
||||
createCSSRule(`.vs-dark .icon#${iconUid}, .hc-black .icon#${iconUid}`, `background: ${asCSSUrl(iconPath.dark)} center center no-repeat`);
|
||||
this.iconRegistered.add(iconUid);
|
||||
@@ -22,30 +22,30 @@ class IconRenderer {
|
||||
return iconUid;
|
||||
}
|
||||
|
||||
public getIconUid(path: URI | IconPath): string {
|
||||
public getIconUid(path: URI | IconPath): string | undefined {
|
||||
if (!path) { return undefined; }
|
||||
let iconPath: IconPath = this.toIconPath(path);
|
||||
return `icon${hash(iconPath.light.toString() + iconPath.dark.toString())}`;
|
||||
}
|
||||
|
||||
private toIconPath(path: URI | IconPath): IconPath {
|
||||
if (path['light']) {
|
||||
return path as IconPath;
|
||||
} else {
|
||||
let singlePath = path as URI;
|
||||
if (URI.isUri(path)) {
|
||||
let singlePath = path;
|
||||
return { light: singlePath, dark: singlePath };
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
public putIcon(element: HTMLElement, path: URI | IconPath): void {
|
||||
if (!element || !path) { return undefined; }
|
||||
let iconUid: string = this.registerIcon(path);
|
||||
element.id = iconUid;
|
||||
let iconUid: string | undefined = this.registerIcon(path);
|
||||
element.id = iconUid ?? '';
|
||||
}
|
||||
|
||||
public removeIcon(element: HTMLElement): void {
|
||||
if (!element) { return undefined; }
|
||||
element.id = undefined;
|
||||
element.id = '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,9 +117,9 @@ class BadgeRenderer {
|
||||
|
||||
public removeBadge(element: HTMLElement, badgeClass: string): void {
|
||||
let children: HTMLCollection = element.children;
|
||||
let current = children[0];
|
||||
let current: Element | null = children[0];
|
||||
while (current) {
|
||||
let next = current.nextElementSibling;
|
||||
let next: Element | null = current.nextElementSibling;
|
||||
if (current.classList.contains(badgeClass)) {
|
||||
current.remove();
|
||||
break;
|
||||
|
||||
@@ -19,10 +19,8 @@ export class RecentConnectionDataSource implements IDataSource {
|
||||
public getId(tree: ITree, element: any): string {
|
||||
if (element instanceof ConnectionProfile) {
|
||||
return (<ConnectionProfile>element).id;
|
||||
} else if (element instanceof ConnectionProfileGroup) {
|
||||
return (<ConnectionProfileGroup>element).id;
|
||||
} else {
|
||||
return undefined;
|
||||
return (<ConnectionProfileGroup>element).id!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,4 +61,4 @@ export class RecentConnectionDataSource implements IDataSource {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export class ServerTreeController extends treedefaults.DefaultController {
|
||||
context.nodeInfo = element.toNodeInfo();
|
||||
// Note: getting DB name before, but intentionally not using treeUpdateUtils.getConnectionProfile as it replaces
|
||||
// the connection ID with a new one. This breaks a number of internal tasks
|
||||
context.connectionProfile = element.getConnectionProfile().toIConnectionProfile();
|
||||
context.connectionProfile = element.getConnectionProfile()!.toIConnectionProfile();
|
||||
context.connectionProfile.databaseName = element.getDatabaseName();
|
||||
actionContext = context;
|
||||
} else if (element instanceof ConnectionProfile) {
|
||||
|
||||
@@ -30,13 +30,7 @@ export class ServerTreeDataSource implements IDataSource {
|
||||
* No more than one element may use a given identifier.
|
||||
*/
|
||||
public getId(tree: ITree, element: any): string {
|
||||
if (element instanceof ConnectionProfile
|
||||
|| element instanceof ConnectionProfileGroup
|
||||
|| element instanceof TreeNode) {
|
||||
return element.id;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
return element.id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +61,7 @@ export class ServerTreeDataSource implements IDataSource {
|
||||
return node.children;
|
||||
} else {
|
||||
try {
|
||||
return this._objectExplorerService.resolveTreeNodeChildren(node.getSession(), node);
|
||||
return this._objectExplorerService.resolveTreeNodeChildren(node.getSession()!, node);
|
||||
} catch (expandError) {
|
||||
await node.setExpandedState(TreeItemCollapsibleState.Collapsed);
|
||||
node.errorStateMessage = expandError;
|
||||
|
||||
@@ -16,6 +16,7 @@ import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
|
||||
import { badgeRenderer, iconRenderer } from 'sql/workbench/services/objectExplorer/browser/iconRenderer';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { DefaultServerGroupColor } from 'sql/workbench/services/serverGroup/common/serverGroupViewModel';
|
||||
import { withNullAsUndefined } from 'vs/base/common/types';
|
||||
|
||||
export interface IConnectionTemplateData {
|
||||
root: HTMLElement;
|
||||
@@ -132,7 +133,7 @@ export class ServerTreeRenderer implements IRenderer {
|
||||
private renderObjectExplorer(treeNode: TreeNode, templateData: IObjectExplorerTemplateData): void {
|
||||
// Use an explicitly defined iconType first. If not defined, fall back to using nodeType and
|
||||
// other compount indicators instead.
|
||||
let iconName: string = undefined;
|
||||
let iconName: string | undefined = undefined;
|
||||
if (treeNode.iconType) {
|
||||
iconName = (typeof treeNode.iconType === 'string') ? treeNode.iconType : treeNode.iconType.id;
|
||||
} else {
|
||||
@@ -147,7 +148,7 @@ export class ServerTreeRenderer implements IRenderer {
|
||||
|
||||
let tokens: string[] = [];
|
||||
for (let index = 1; index < templateData.icon.classList.length; index++) {
|
||||
tokens.push(templateData.icon.classList.item(index));
|
||||
tokens.push(templateData.icon.classList.item(index)!);
|
||||
}
|
||||
templateData.icon.classList.remove(...tokens);
|
||||
templateData.icon.classList.add('icon');
|
||||
@@ -162,11 +163,11 @@ export class ServerTreeRenderer implements IRenderer {
|
||||
templateData.root.title = treeNode.label;
|
||||
}
|
||||
|
||||
private getIconPath(connection: ConnectionProfile): IconPath {
|
||||
private getIconPath(connection: ConnectionProfile): IconPath | undefined {
|
||||
if (!connection) { return undefined; }
|
||||
|
||||
if (connection['iconPath']) {
|
||||
return connection['iconPath'];
|
||||
if (connection.iconPath) {
|
||||
return connection.iconPath;
|
||||
}
|
||||
|
||||
let iconId = this._connectionManagementService.getConnectionIconId(connection.id);
|
||||
@@ -175,8 +176,8 @@ export class ServerTreeRenderer implements IRenderer {
|
||||
let providerProperties = this._connectionManagementService.getProviderProperties(connection.providerName);
|
||||
if (!providerProperties) { return undefined; }
|
||||
|
||||
let iconPath: IconPath = undefined;
|
||||
let pathConfig: URI | IconPath | { id: string, path: IconPath }[] = providerProperties['iconPath'];
|
||||
let iconPath: IconPath | undefined = undefined;
|
||||
let pathConfig: URI | IconPath | { id: string, path: IconPath }[] | undefined = providerProperties.iconPath;
|
||||
if (Array.isArray(pathConfig)) {
|
||||
for (const e of pathConfig) {
|
||||
if (!e.id || e.id === iconId) {
|
||||
@@ -185,18 +186,18 @@ export class ServerTreeRenderer implements IRenderer {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (pathConfig['light']) {
|
||||
iconPath = pathConfig as IconPath;
|
||||
connection['iconPath'] = iconPath;
|
||||
} else {
|
||||
} else if (URI.isUri(pathConfig)) {
|
||||
let singlePath = pathConfig as URI;
|
||||
iconPath = { light: singlePath, dark: singlePath };
|
||||
connection['iconPath'] = iconPath;
|
||||
connection.iconPath = iconPath;
|
||||
} else {
|
||||
iconPath = pathConfig as IconPath;
|
||||
connection.iconPath = iconPath;
|
||||
}
|
||||
return iconPath;
|
||||
}
|
||||
|
||||
private renderServerIcon(element: HTMLElement, iconPath: IconPath, isConnected: boolean): void {
|
||||
private renderServerIcon(element: HTMLElement, iconPath: IconPath | undefined, isConnected: boolean): void {
|
||||
if (!element) { return; }
|
||||
if (iconPath) {
|
||||
iconRenderer.putIcon(element, iconPath);
|
||||
@@ -209,7 +210,7 @@ export class ServerTreeRenderer implements IRenderer {
|
||||
|
||||
private renderConnection(connection: ConnectionProfile, templateData: IConnectionTemplateData): void {
|
||||
if (!this._isCompact) {
|
||||
let iconPath: IconPath = this.getIconPath(connection);
|
||||
let iconPath = this.getIconPath(connection);
|
||||
if (this._connectionManagementService.isConnected(undefined, connection)) {
|
||||
templateData.icon.classList.remove('disconnected');
|
||||
templateData.icon.classList.add('connected');
|
||||
@@ -252,15 +253,15 @@ export class ServerTreeRenderer implements IRenderer {
|
||||
/**
|
||||
* Returns the first parent which contains the className
|
||||
*/
|
||||
private findParentElement(container: HTMLElement, className: string): HTMLElement {
|
||||
let currentElement = container;
|
||||
private findParentElement(container: HTMLElement, className: string): HTMLElement | undefined {
|
||||
let currentElement: HTMLElement | null = container;
|
||||
while (currentElement) {
|
||||
if (currentElement.className.indexOf(className) > -1) {
|
||||
break;
|
||||
}
|
||||
currentElement = currentElement.parentElement;
|
||||
}
|
||||
return currentElement;
|
||||
return withNullAsUndefined(currentElement);
|
||||
}
|
||||
|
||||
public disposeTemplate(tree: ITree, templateId: string, templateData: any): void {
|
||||
|
||||
@@ -142,5 +142,5 @@ export class TreeCreationUtils {
|
||||
}
|
||||
|
||||
function useAsyncServerTree(configurationService: IConfigurationService): boolean {
|
||||
return configurationService.getValue('workbench.enablePreviewFeatures') && configurationService.getValue('serverTree.useAsyncServerTree');
|
||||
return configurationService.getValue<boolean>('workbench.enablePreviewFeatures') && configurationService.getValue<boolean>('serverTree.useAsyncServerTree');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user