fix find parent node issue (#22356)

* fix find parent node issue

* sts update

* fix errors

* pr comments and a fix
This commit is contained in:
Alan Ren
2023-03-20 08:20:11 -07:00
committed by GitHub
parent 9d16a48dee
commit aa47729f90
28 changed files with 104 additions and 50 deletions

View File

@@ -16,6 +16,7 @@ export class ExtHostObjectExplorerNodeStub implements azdata.objectexplorer.Obje
// Base properties // Base properties
public connectionId: string; public connectionId: string;
public nodePath: string; public nodePath: string;
public parentNodePath: string;
public nodeType: string; public nodeType: string;
public nodeSubType: string; public nodeSubType: string;
public nodeStatus: string; public nodeStatus: string;

View File

@@ -41,6 +41,7 @@ export class AzureResourceMessageTreeNode extends TreeNode {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: AzureResourceItemType.message, nodeType: AzureResourceItemType.message,
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -65,6 +65,7 @@ export class AzureResourceResourceTreeNode extends TreeNode {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: treeItem.contextValue || '', nodeType: treeItem.contextValue || '',
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -34,6 +34,7 @@ export class AzureResourceAccountNotSignedInTreeNode extends TreeNode {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: AzureResourceItemType.message, nodeType: AzureResourceItemType.message,
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -120,6 +120,7 @@ export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNode
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: AzureResourceItemType.account, nodeType: AzureResourceItemType.account,
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -94,6 +94,7 @@ export class FlatAccountTreeNode extends AzureResourceContainerTreeNodeBase {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: AzureResourceItemType.account, nodeType: AzureResourceItemType.account,
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -200,6 +200,7 @@ class AzureResourceResourceTreeNode extends TreeNode {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: treeItem.contextValue || '', nodeType: treeItem.contextValue || '',
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -76,6 +76,7 @@ export class AzureResourceSubscriptionTreeNode extends AzureResourceContainerTre
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: AzureResourceItemType.subscription, nodeType: AzureResourceItemType.subscription,
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -209,6 +209,7 @@ class SqlClusterRootNode extends TreeNode {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath()!, nodePath: this.generateNodePath()!,
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: 'sqlCluster:root', nodeType: 'sqlCluster:root',
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -41,6 +41,7 @@ export class CmsResourceMessageTreeNode extends TreeNode {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: CmsResourceItemType.cmsMessageNodeContainer, nodeType: CmsResourceItemType.cmsMessageNodeContainer,
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -34,6 +34,7 @@ export class CmsResourceEmptyTreeNode extends TreeNode {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: CmsResourceItemType.cmsEmptyNodeContainer, nodeType: CmsResourceItemType.cmsEmptyNodeContainer,
iconType: CmsResourceItemType.cmsEmptyNodeContainer, iconType: CmsResourceItemType.cmsEmptyNodeContainer,

View File

@@ -108,6 +108,7 @@ export class CmsResourceTreeNode extends CmsResourceTreeNodeBase {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: CmsResourceItemType.cmsNodeContainer, nodeType: CmsResourceItemType.cmsNodeContainer,
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -71,6 +71,7 @@ export class RegisteredServerTreeNode extends CmsResourceTreeNodeBase {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: CmsResourceItemType.registeredServer, nodeType: CmsResourceItemType.registeredServer,
nodeSubType: undefined nodeSubType: undefined

View File

@@ -95,6 +95,7 @@ export class ServerGroupTreeNode extends CmsResourceTreeNodeBase {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: CmsResourceItemType.serverGroup, nodeType: CmsResourceItemType.serverGroup,
nodeSubType: undefined nodeSubType: undefined

View File

@@ -79,6 +79,7 @@ export class FileNode extends HdfsFileSourceNode implements IFileNode {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath(), nodePath: this.generateNodePath(),
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: Constants.HdfsItems.File, nodeType: Constants.HdfsItems.File,
nodeSubType: this.getSubType(), nodeSubType: this.getSubType(),

View File

@@ -210,6 +210,7 @@ class SqlClusterRootNode extends TreeNode {
errorMessage: undefined, errorMessage: undefined,
metadata: undefined, metadata: undefined,
nodePath: this.generateNodePath()!, nodePath: this.generateNodePath()!,
parentNodePath: this.parent?.generateNodePath() ?? '',
nodeStatus: undefined, nodeStatus: undefined,
nodeType: 'sqlCluster:root', nodeType: 'sqlCluster:root',
nodeSubType: undefined, nodeSubType: undefined,

View File

@@ -1,6 +1,6 @@
{ {
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "4.6.0.12", "version": "4.6.0.13",
"downloadFileNames": { "downloadFileNames": {
"Windows_86": "win-x86-net7.0.zip", "Windows_86": "win-x86-net7.0.zip",
"Windows_64": "win-x64-net7.0.zip", "Windows_64": "win-x64-net7.0.zip",

2
src/sql/azdata.d.ts vendored
View File

@@ -308,7 +308,7 @@ declare module 'azdata' {
/** /**
* Get the parent node. Returns undefined if there is none. * Get the parent node. Returns undefined if there is none.
*/ */
getParent(): Thenable<ObjectExplorerNode>; getParent(): Thenable<ObjectExplorerNode | undefined>;
/** /**
* Refresh the node, expanding it if it has children * Refresh the node, expanding it if it has children

View File

@@ -1880,6 +1880,10 @@ declare module 'azdata' {
* under the database, the nodeType is Folder, the objectType is be Tables. * under the database, the nodeType is Folder, the objectType is be Tables.
*/ */
objectType?: string; objectType?: string;
/*
* The path of the parent node.
*/
parentNodePath: string;
} }
export namespace window { export namespace window {

View File

@@ -66,6 +66,7 @@ export class ExtHostObjectExplorer implements ExtHostObjectExplorerShape {
export class ExtHostObjectExplorerNode implements azdata.objectexplorer.ObjectExplorerNode { export class ExtHostObjectExplorerNode implements azdata.objectexplorer.ObjectExplorerNode {
public connectionId: string; public connectionId: string;
public nodePath: string; public nodePath: string;
public parentNodePath: string;
public nodeType: string; public nodeType: string;
public nodeSubType: string; public nodeSubType: string;
public nodeStatus: string; public nodeStatus: string;
@@ -95,21 +96,30 @@ export class ExtHostObjectExplorerNode implements azdata.objectexplorer.ObjectEx
return this._proxy.$getChildren(this.connectionId, this.nodePath).then(children => children.map(nodeInfo => new ExtHostObjectExplorerNode(nodeInfo, this.connectionId, this._proxy))); return this._proxy.$getChildren(this.connectionId, this.nodePath).then(children => children.map(nodeInfo => new ExtHostObjectExplorerNode(nodeInfo, this.connectionId, this._proxy)));
} }
getParent(): Thenable<azdata.objectexplorer.ObjectExplorerNode> { getParent(): Thenable<azdata.objectexplorer.ObjectExplorerNode | undefined> {
// Object nodes have a name like <schema>.<name> in the nodePath - we can't use label because let parentPath;
// that may have additional display information appended to it. Items without metadata are nodes // parentNodePath property is introduced after we discovered the flaw of the following code.
// such as folders that don't correspond to actual objects and so just use the label // To maintain backward compatibility with other providers, we need to keep the following code.
let nodePathName = this.metadata ? if (this.parentNodePath === undefined) {
`${this.metadata.schema ? this.metadata.schema + '.' : ''}${this.metadata.name}` : // Object nodes have a name like <schema>.<name> in the nodePath - we can't use label because
this.label; // that may have additional display information appended to it. Items without metadata are nodes
// such as folders that don't correspond to actual objects and so just use the label
let nodePathName = this.metadata ?
`${this.metadata.schema ? this.metadata.schema + '.' : ''}${this.metadata.name}` :
this.label;
// -1 to remove the / as well // -1 to remove the / as well
let parentPathEndIndex: number = this.nodePath.lastIndexOf(nodePathName) - 1; let parentPathEndIndex: number = this.nodePath.lastIndexOf(nodePathName) - 1;
if (parentPathEndIndex < 0) { parentPath = this.nodePath.slice(0, parentPathEndIndex)
} else {
parentPath = this.parentNodePath;
}
if (!parentPath) {
// At root node // At root node
return Promise.resolve(undefined); return Promise.resolve(undefined);
} }
return this._proxy.$getNode(this.connectionId, this.nodePath.slice(0, parentPathEndIndex)).then( return this._proxy.$getNode(this.connectionId, this.parentNodePath).then(
nodeInfo => nodeInfo ? new ExtHostObjectExplorerNode(nodeInfo, this.connectionId, this._proxy) : undefined); nodeInfo => nodeInfo ? new ExtHostObjectExplorerNode(nodeInfo, this.connectionId, this._proxy) : undefined);
} }
@@ -119,6 +129,7 @@ export class ExtHostObjectExplorerNode implements azdata.objectexplorer.ObjectEx
private getDetailsFromInfo(nodeInfo: azdata.NodeInfo): void { private getDetailsFromInfo(nodeInfo: azdata.NodeInfo): void {
this.nodePath = nodeInfo.nodePath; this.nodePath = nodeInfo.nodePath;
this.parentNodePath = nodeInfo.parentNodePath;
this.nodeType = nodeInfo.nodeType; this.nodeType = nodeInfo.nodeType;
this.nodeSubType = nodeInfo.nodeSubType; this.nodeSubType = nodeInfo.nodeSubType;
this.nodeStatus = nodeInfo.nodeStatus; this.nodeStatus = nodeInfo.nodeStatus;

View File

@@ -109,8 +109,8 @@ suite('SQL Connection Tree Action tests', () => {
let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Strict, connectionManagementService); let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Strict, connectionManagementService);
objectExplorerService.callBase = true; objectExplorerService.callBase = true;
objectExplorerService.setup(x => x.getTreeNode(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(getTreeNodeReturnVal)); objectExplorerService.setup(x => x.getTreeNode(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(getTreeNodeReturnVal));
objectExplorerService.setup(x => x.getObjectExplorerNode(TypeMoq.It.isAny())).returns(() => new TreeNode('', '', '', false, '', '', '', undefined, undefined, undefined, undefined)); objectExplorerService.setup(x => x.getObjectExplorerNode(TypeMoq.It.isAny())).returns(() => new TreeNode('', '', '', false, '', '', '', '', undefined, undefined, undefined, undefined));
objectExplorerService.setup(x => x.getObjectExplorerNode(undefined)).returns(() => new TreeNode('', '', '', false, '', '', '', undefined, undefined, undefined, undefined)); objectExplorerService.setup(x => x.getObjectExplorerNode(undefined)).returns(() => new TreeNode('', '', '', false, '', '', '', '', undefined, undefined, undefined, undefined));
objectExplorerService.setup(x => x.onUpdateObjectExplorerNodes).returns(() => new Emitter<ObjectExplorerNodeEventArgs>().event); objectExplorerService.setup(x => x.onUpdateObjectExplorerNodes).returns(() => new Emitter<ObjectExplorerNodeEventArgs>().event);
objectExplorerService.setup(x => x.onUpdateObjectExplorerNodes).returns(() => new Emitter<ObjectExplorerNodeEventArgs>().event); objectExplorerService.setup(x => x.onUpdateObjectExplorerNodes).returns(() => new Emitter<ObjectExplorerNodeEventArgs>().event);
@@ -223,7 +223,7 @@ suite('SQL Connection Tree Action tests', () => {
saveProfile: true, saveProfile: true,
id: 'testId' id: 'testId'
}); });
let treeNode = new TreeNode(NodeType.Database, '', 'db node', false, '', '', '', undefined, undefined, undefined, undefined); let treeNode = new TreeNode(NodeType.Database, '', 'db node', false, '', '', '', '', undefined, undefined, undefined, undefined);
treeNode.connection = connection; treeNode.connection = connection;
let connectionManagementService = createConnectionManagementService(isConnectedReturnValue, connection); let connectionManagementService = createConnectionManagementService(isConnectedReturnValue, connection);
let editorService = createEditorService(); let editorService = createEditorService();
@@ -471,7 +471,8 @@ suite('SQL Connection Tree Action tests', () => {
success: true, success: true,
sessionId: '1234', sessionId: '1234',
rootNode: { rootNode: {
nodePath: 'testServerName\tables', nodePath: 'testServerName/tables',
parentNodePath: 'testServerName',
nodeType: NodeType.Folder, nodeType: NodeType.Folder,
objectType: '', objectType: '',
label: 'Tables', label: 'Tables',
@@ -484,11 +485,11 @@ suite('SQL Connection Tree Action tests', () => {
errorMessage: '' errorMessage: ''
}; };
let tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName\Db1\tables', '', '', null, null, undefined, undefined); let tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/Db1/tables', 'testServerName/Db1', '', '', null, null, undefined, undefined);
tablesNode.connection = connection; tablesNode.connection = connection;
tablesNode.session = objectExplorerSession; tablesNode.session = objectExplorerSession;
let table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\tables\dbo.Table1', '', '', tablesNode, null, undefined, undefined); let table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName/tables/dbo.Table1', 'testServerName/tables', '', '', tablesNode, null, undefined, undefined);
let table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\tables\dbo.Table1', '', '', tablesNode, null, undefined, undefined); let table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName/tables/dbo.Table1', 'testServerName/tables', '', '', tablesNode, null, undefined, undefined);
tablesNode.children = [table1Node, table2Node]; tablesNode.children = [table1Node, table2Node];
let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManagementService.object); let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManagementService.object);
objectExplorerService.callBase = true; objectExplorerService.callBase = true;
@@ -558,7 +559,8 @@ suite('SQL Connection Tree Action tests', () => {
success: true, success: true,
sessionId: '1234', sessionId: '1234',
rootNode: { rootNode: {
nodePath: 'testServerName\tables', nodePath: 'testServerName/tables',
parentNodePath: 'testServerName',
nodeType: NodeType.Folder, nodeType: NodeType.Folder,
objectType: '', objectType: '',
label: 'Tables', label: 'Tables',
@@ -571,11 +573,11 @@ suite('SQL Connection Tree Action tests', () => {
errorMessage: '' errorMessage: ''
}; };
let tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName\Db1\tables', '', '', null, null, undefined, undefined); let tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/Db1/tables', 'testServerName/Db1', '', '', null, null, undefined, undefined);
tablesNode.connection = connection; tablesNode.connection = connection;
tablesNode.session = objectExplorerSession; tablesNode.session = objectExplorerSession;
let table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\tables\dbo.Table1', '', '', tablesNode, null, undefined, undefined); let table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName/tables/dbo.Table1', 'testServerName/tables', '', '', tablesNode, null, undefined, undefined);
let table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\tables\dbo.Table1', '', '', tablesNode, null, undefined, undefined); let table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName/tables/dbo.Table1', 'testServerName/tables', '', '', tablesNode, null, undefined, undefined);
tablesNode.children = [table1Node, table2Node]; tablesNode.children = [table1Node, table2Node];
let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManagementService.object); let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManagementService.object);
objectExplorerService.callBase = true; objectExplorerService.callBase = true;
@@ -646,7 +648,8 @@ suite('SQL Connection Tree Action tests', () => {
success: true, success: true,
sessionId: '1234', sessionId: '1234',
rootNode: { rootNode: {
nodePath: 'testServerName\tables', nodePath: 'testServerName/tables',
parentNodePath: 'testServerName',
nodeType: NodeType.Folder, nodeType: NodeType.Folder,
objectType: '', objectType: '',
label: 'Tables', label: 'Tables',
@@ -659,11 +662,11 @@ suite('SQL Connection Tree Action tests', () => {
errorMessage: '' errorMessage: ''
}; };
let tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName\Db1\tables', '', '', null, null, undefined, undefined); let tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/Db1/tables', 'testServerName/Db1', '', '', null, null, undefined, undefined);
tablesNode.connection = connection; tablesNode.connection = connection;
tablesNode.session = objectExplorerSession; tablesNode.session = objectExplorerSession;
let table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\tables\dbo.Table1', '', '', tablesNode, null, undefined, undefined); let table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName/tables/dbo.Table1', 'testServerName/tables', '', '', tablesNode, null, undefined, undefined);
let table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\tables\dbo.Table1', '', '', tablesNode, null, undefined, undefined); let table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName/tables/dbo.Table1', 'testServerName/tables', '', '', tablesNode, null, undefined, undefined);
tablesNode.children = [table1Node, table2Node]; tablesNode.children = [table1Node, table2Node];
let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManagementService.object); let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManagementService.object);
objectExplorerService.callBase = true; objectExplorerService.callBase = true;
@@ -743,7 +746,8 @@ suite('SQL Connection Tree Action tests', () => {
success: true, success: true,
sessionId: '1234', sessionId: '1234',
rootNode: { rootNode: {
nodePath: 'testServerName\tables', nodePath: 'testServerName/tables',
parentNodePath: 'testServerName',
nodeType: NodeType.Folder, nodeType: NodeType.Folder,
objectType: '', objectType: '',
label: 'Tables', label: 'Tables',
@@ -756,11 +760,11 @@ suite('SQL Connection Tree Action tests', () => {
errorMessage: '' errorMessage: ''
}; };
let tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName\Db1\tables', '', '', null, null, undefined, undefined); let tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/Db1/tables', 'testServerName/Db1', '', '', null, null, undefined, undefined);
tablesNode.connection = connection; tablesNode.connection = connection;
tablesNode.session = objectExplorerSession; tablesNode.session = objectExplorerSession;
let table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\tables\dbo.Table1', '', '', tablesNode, null, undefined, undefined); let table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName/tables/dbo.Table1', 'testServerName/tables', '', '', tablesNode, null, undefined, undefined);
let table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\tables\dbo.Table1', '', '', tablesNode, null, undefined, undefined); let table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName/tables/dbo.Table1', 'testServerName/tables', '', '', tablesNode, null, undefined, undefined);
tablesNode.children = [table1Node, table2Node]; tablesNode.children = [table1Node, table2Node];
let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManagementService.object); let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Loose, connectionManagementService.object);
objectExplorerService.callBase = true; objectExplorerService.callBase = true;

View File

@@ -42,6 +42,7 @@ const connection: azdata.IConnectionProfile = {
const nodeInfo: azdata.NodeInfo = { const nodeInfo: azdata.NodeInfo = {
nodePath: 'MyServer', nodePath: 'MyServer',
parentNodePath: '',
objectType: '', objectType: '',
nodeStatus: '', nodeStatus: '',
nodeSubType: '', nodeSubType: '',
@@ -52,7 +53,7 @@ const nodeInfo: azdata.NodeInfo = {
errorMessage: '' errorMessage: ''
}; };
const treeNode = new TreeNode(NodeType.Database, '', 'db node', false, '', '', '', undefined, undefined, undefined, undefined); const treeNode = new TreeNode(NodeType.Database, '', 'db node', false, '', '', '', '', undefined, undefined, undefined, undefined);
const oeActionArgs: ObjectExplorerActionsContext = { connectionProfile: connection, isConnectionNode: false, nodeInfo: nodeInfo }; const oeActionArgs: ObjectExplorerActionsContext = { connectionProfile: connection, isConnectionNode: false, nodeInfo: nodeInfo };
let instantiationService: IInstantiationService; let instantiationService: IInstantiationService;

View File

@@ -522,6 +522,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
let allNodes: azdata.NodeInfo[] = []; let allNodes: azdata.NodeInfo[] = [];
let errorNode: azdata.NodeInfo = { let errorNode: azdata.NodeInfo = {
nodePath: nodePath, nodePath: nodePath,
parentNodePath: '',
objectType: 'error', objectType: 'error',
label: 'Error', label: 'Error',
errorMessage: '', errorMessage: '',
@@ -690,7 +691,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
} }
} }
let node = new TreeNode(nodeInfo.nodeType, nodeInfo.objectType, nodeInfo.label, isLeaf, nodeInfo.nodePath, let node = new TreeNode(nodeInfo.nodeType, nodeInfo.objectType, nodeInfo.label, isLeaf, nodeInfo.nodePath, nodeInfo.parentNodePath,
nodeInfo.nodeSubType!, nodeInfo.nodeStatus, parent, nodeInfo.metadata, nodeInfo.iconType, nodeInfo.icon, { nodeInfo.nodeSubType!, nodeInfo.nodeStatus, parent, nodeInfo.metadata, nodeInfo.iconType, nodeInfo.icon, {
getChildren: (treeNode?: TreeNode) => this.getChildren(treeNode), getChildren: (treeNode?: TreeNode) => this.getChildren(treeNode),
isExpanded: treeNode => this.isExpanded(treeNode), isExpanded: treeNode => this.isExpanded(treeNode),

View File

@@ -125,7 +125,7 @@ export class OEShimService extends Disposable implements IOEShimService {
node.sessionId = await this.createSession(viewId, node.childProvider!, node); node.sessionId = await this.createSession(viewId, node.childProvider!, node);
} }
const requestHandle = this.nodeHandleMap.get(generateNodeMapKey(viewId, node)) || node.handle; const requestHandle = this.nodeHandleMap.get(generateNodeMapKey(viewId, node)) || node.handle;
const treeNode = new TreeNode(undefined!, undefined!, undefined!, undefined!, requestHandle, undefined!); // hack since this entire system is a hack anyways const treeNode = new TreeNode(undefined!, undefined!, undefined!, undefined!, requestHandle, undefined!, undefined!); // hack since this entire system is a hack anyways
treeNode.connection = new ConnectionProfile(this.capabilities, node.payload); treeNode.connection = new ConnectionProfile(this.capabilities, node.payload);
const childrenNodes = await this.oe.refreshTreeNode({ const childrenNodes = await this.oe.refreshTreeNode({
success: true, success: true,
@@ -168,6 +168,7 @@ export class OEShimService extends Disposable implements IOEShimService {
} }
const nodeInfo: azdata.NodeInfo = { const nodeInfo: azdata.NodeInfo = {
nodePath: nodePath, nodePath: nodePath,
parentNodePath: node.parentNodePath,
nodeType: node.nodeTypeId, nodeType: node.nodeTypeId,
objectType: node.objectType, objectType: node.objectType,
nodeSubType: node.nodeSubType, nodeSubType: node.nodeSubType,

View File

@@ -69,7 +69,7 @@ export class ServerTreeActionProvider {
* Return actions for connection elements * Return actions for connection elements
*/ */
private getConnectionActions(tree: AsyncServerTree | ITree, profile: ConnectionProfile): IAction[] { private getConnectionActions(tree: AsyncServerTree | ITree, profile: ConnectionProfile): IAction[] {
let node = new TreeNode(NodeType.Server, NodeType.Server, '', false, '', '', '', undefined, undefined, undefined, undefined); let node = new TreeNode(NodeType.Server, NodeType.Server, '', false, '', '', '', '', undefined, undefined, undefined, undefined);
// Only update password and not access tokens to avoid login prompts when opening context menu. // Only update password and not access tokens to avoid login prompts when opening context menu.
this._connectionManagementService.addSavedPassword(profile, true); this._connectionManagementService.addSavedPassword(profile, true);
node.connection = profile; node.connection = profile;

View File

@@ -73,6 +73,11 @@ export class TreeNode {
*/ */
public nodePath: string; public nodePath: string;
/**
* Parent node path
*/
public parentNodePath: string;
/** /**
* Node sub type * Node sub type
*/ */
@@ -99,7 +104,7 @@ export class TreeNode {
public icon?: IconPath | SqlThemeIcon; public icon?: IconPath | SqlThemeIcon;
constructor(nodeTypeId: string, objectType: string, label: string, isAlwaysLeaf: boolean, nodePath: string, constructor(nodeTypeId: string, objectType: string, label: string, isAlwaysLeaf: boolean, nodePath: string, parentNodePath: string,
nodeSubType: string, nodeStatus?: string, parent?: TreeNode, metadata?: azdata.ObjectMetadata, nodeSubType: string, nodeStatus?: string, parent?: TreeNode, metadata?: azdata.ObjectMetadata,
iconType?: string | SqlThemeIcon, iconType?: string | SqlThemeIcon,
icon?: IconPath | SqlThemeIcon, icon?: IconPath | SqlThemeIcon,
@@ -109,6 +114,7 @@ export class TreeNode {
this.label = label; this.label = label;
this.isAlwaysLeaf = isAlwaysLeaf; this.isAlwaysLeaf = isAlwaysLeaf;
this.nodePath = nodePath; this.nodePath = nodePath;
this.parentNodePath = parentNodePath;
this.parent = parent; this.parent = parent;
this.metadata = metadata; this.metadata = metadata;
this.iconType = iconType; this.iconType = iconType;
@@ -158,6 +164,7 @@ export class TreeNode {
public toNodeInfo(): azdata.NodeInfo { public toNodeInfo(): azdata.NodeInfo {
return <azdata.NodeInfo>{ return <azdata.NodeInfo>{
nodePath: this.nodePath, nodePath: this.nodePath,
parentNodePath: this.parentNodePath,
nodeType: this.nodeTypeId, nodeType: this.nodeTypeId,
nodeSubType: this.nodeSubType, nodeSubType: this.nodeSubType,
nodeStatus: this.nodeStatus, nodeStatus: this.nodeStatus,

View File

@@ -46,6 +46,7 @@ suite('SQL Object Explorer Service tests', () => {
const NodeInfoTable1 = { const NodeInfoTable1 = {
nodePath: 'testServerName/tables/dbo.Table1', nodePath: 'testServerName/tables/dbo.Table1',
parentNodePath: 'testServerName/tables',
nodeType: NodeType.Table, nodeType: NodeType.Table,
objectType: '', objectType: '',
label: 'dbo.Table1', label: 'dbo.Table1',
@@ -57,6 +58,7 @@ suite('SQL Object Explorer Service tests', () => {
}; };
const NodeInfoTable2 = { const NodeInfoTable2 = {
nodePath: 'testServerName/tables/dbo.Table2', nodePath: 'testServerName/tables/dbo.Table2',
parentNodePath: 'testServerName/tables',
nodeType: NodeType.Table, nodeType: NodeType.Table,
objectType: '', objectType: '',
label: 'dbo.Table2', label: 'dbo.Table2',
@@ -69,6 +71,7 @@ suite('SQL Object Explorer Service tests', () => {
const NodeInfoTable3 = { const NodeInfoTable3 = {
nodePath: 'testServerName/tables/dbo.Table3', nodePath: 'testServerName/tables/dbo.Table3',
parentNodePath: 'testServerName/tables',
nodeType: NodeType.Table, nodeType: NodeType.Table,
objectType: '', objectType: '',
label: 'dbo.Table3', label: 'dbo.Table3',
@@ -84,6 +87,7 @@ suite('SQL Object Explorer Service tests', () => {
sessionId: sessionId, sessionId: sessionId,
rootNode: { rootNode: {
nodePath: 'testServerName/tables', nodePath: 'testServerName/tables',
parentNodePath: 'testServerName',
nodeType: NodeType.Folder, nodeType: NodeType.Folder,
objectType: '', objectType: '',
label: 'Tables', label: 'Tables',
@@ -348,7 +352,7 @@ suite('SQL Object Explorer Service tests', () => {
}); });
test('expand node should expand node correctly', async () => { test('expand node should expand node correctly', async () => {
const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/tables', '', '', null, null, undefined, undefined); const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/tables', 'testServerName', '', '', null, null, undefined, undefined);
await objectExplorerService.createNewSession(mssqlProviderName, connection); await objectExplorerService.createNewSession(mssqlProviderName, connection);
objectExplorerService.onSessionCreated(1, objectExplorerSession); objectExplorerService.onSessionCreated(1, objectExplorerSession);
const expandInfo = await objectExplorerService.expandNode(mssqlProviderName, objectExplorerSession, tablesNode); const expandInfo = await objectExplorerService.expandNode(mssqlProviderName, objectExplorerSession, tablesNode);
@@ -361,7 +365,7 @@ suite('SQL Object Explorer Service tests', () => {
}); });
test('refresh node should refresh node correctly', async () => { test('refresh node should refresh node correctly', async () => {
const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/tables', '', '', null, null, undefined, undefined); const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/tables', 'testServerName', '', '', null, null, undefined, undefined);
await objectExplorerService.createNewSession(mssqlProviderName, connection); await objectExplorerService.createNewSession(mssqlProviderName, connection);
objectExplorerService.onSessionCreated(1, objectExplorerSession); objectExplorerService.onSessionCreated(1, objectExplorerSession);
const expandInfo = await objectExplorerService.refreshNode(mssqlProviderName, objectExplorerSession, tablesNode); const expandInfo = await objectExplorerService.refreshNode(mssqlProviderName, objectExplorerSession, tablesNode);
@@ -374,7 +378,7 @@ suite('SQL Object Explorer Service tests', () => {
}); });
test('expand tree node should get correct children', async () => { test('expand tree node should get correct children', async () => {
const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/tables', '', '', null, null, undefined, undefined); const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/tables', 'testServerName', '', '', null, null, undefined, undefined);
tablesNode.connection = connection; tablesNode.connection = connection;
await objectExplorerService.createNewSession(mssqlProviderName, connection); await objectExplorerService.createNewSession(mssqlProviderName, connection);
objectExplorerService.onSessionCreated(1, objectExplorerSession); objectExplorerService.onSessionCreated(1, objectExplorerSession);
@@ -389,7 +393,7 @@ suite('SQL Object Explorer Service tests', () => {
}); });
test('refresh tree node should children correctly', async () => { test('refresh tree node should children correctly', async () => {
const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/tables', '', '', null, null, undefined, undefined); const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/tables', 'testServerName', '', '', null, null, undefined, undefined);
tablesNode.connection = connection; tablesNode.connection = connection;
await objectExplorerService.createNewSession(mssqlProviderName, connection); await objectExplorerService.createNewSession(mssqlProviderName, connection);
objectExplorerService.onSessionCreated(1, objectExplorerSession); objectExplorerService.onSessionCreated(1, objectExplorerSession);
@@ -436,13 +440,13 @@ suite('SQL Object Explorer Service tests', () => {
parentName: undefined, parentName: undefined,
parentTypeName: undefined parentTypeName: undefined
}; };
const databaseNode = new TreeNode(NodeType.Database, '', 'Db1', false, 'testServerName\\Db1', '', '', undefined, databaseMetaData, undefined, undefined); const databaseNode = new TreeNode(NodeType.Database, '', 'Db1', false, 'testServerName/Db1', 'testServerName', '', '', undefined, databaseMetaData, undefined, undefined);
databaseNode.connection = connection; databaseNode.connection = connection;
databaseNode.session = objectExplorerSession; databaseNode.session = objectExplorerSession;
const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName\\Db1\\tables', '', '', databaseNode, undefined, undefined, undefined); const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/Db1/tables', 'testServerName/Db1', '', '', databaseNode, undefined, undefined, undefined);
databaseNode.children = [tablesNode]; databaseNode.children = [tablesNode];
const table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\\Db1\\tables\\dbo.Table1', '', '', tablesNode, undefined, undefined, undefined); const table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName/Db1/tables/dbo.Table1', 'testServerName/Db1/tables', '', '', tablesNode, undefined, undefined, undefined);
const table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table2', false, 'testServerName\\Db1\\tables\\dbo.Table2', '', '', tablesNode, undefined, undefined, undefined); const table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table2', false, 'testServerName/Db1/tables/dbo.Table2', 'testServerName/Db1/tables', '', '', tablesNode, undefined, undefined, undefined);
tablesNode.children = [table1Node, table2Node]; tablesNode.children = [table1Node, table2Node];
assert.strictEqual(table1Node.getSession(), objectExplorerSession); assert.strictEqual(table1Node.getSession(), objectExplorerSession);
assert.strictEqual(table1Node.getConnectionProfile(), connection); assert.strictEqual(table1Node.getConnectionProfile(), connection);
@@ -461,7 +465,7 @@ suite('SQL Object Explorer Service tests', () => {
test('getSelectedProfileAndDatabase returns the profile but no database if children of a server are selected', () => { test('getSelectedProfileAndDatabase returns the profile but no database if children of a server are selected', () => {
const serverTreeView = TypeMoq.Mock.ofInstance({ getSelection: () => undefined, onSelectionOrFocusChange: Event.None } as IServerTreeView); const serverTreeView = TypeMoq.Mock.ofInstance({ getSelection: () => undefined, onSelectionOrFocusChange: Event.None } as IServerTreeView);
const databaseNode = new TreeNode(NodeType.Folder, '', 'Folder1', false, 'testServerName\\Folder1', '', '', undefined, undefined, undefined, undefined); const databaseNode = new TreeNode(NodeType.Folder, '', 'Folder1', false, 'testServerName/Folder1', 'testServerName', '', '', undefined, undefined, undefined, undefined);
databaseNode.connection = connection; databaseNode.connection = connection;
serverTreeView.setup(x => x.getSelection()).returns(() => [databaseNode]); serverTreeView.setup(x => x.getSelection()).returns(() => [databaseNode]);
objectExplorerService.registerServerTreeView(serverTreeView.object); objectExplorerService.registerServerTreeView(serverTreeView.object);
@@ -483,8 +487,8 @@ suite('SQL Object Explorer Service tests', () => {
parentTypeName: undefined parentTypeName: undefined
}; };
const databaseName = 'Db1'; const databaseName = 'Db1';
const databaseNode = new TreeNode(NodeType.Database, '', databaseName, false, 'testServerName\\Db1', '', '', undefined, databaseMetadata, undefined, undefined); const databaseNode = new TreeNode(NodeType.Database, '', databaseName, false, 'testServerName/Db1', 'testServerName', '', '', undefined, databaseMetadata, undefined, undefined);
const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName\\Db1\\tables', '', '', databaseNode, undefined, undefined, undefined); const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName/Db1/tables', 'testServerName/Db1', '', '', databaseNode, undefined, undefined, undefined);
databaseNode.connection = connection; databaseNode.connection = connection;
databaseNode.children = [tablesNode]; databaseNode.children = [tablesNode];
serverTreeView.setup(x => x.getSelection()).returns(() => [tablesNode]); serverTreeView.setup(x => x.getSelection()).returns(() => [tablesNode]);
@@ -676,7 +680,7 @@ suite('SQL Object Explorer Service tests', () => {
sqlOEProvider.setup(x => x.expandNode(TypeMoq.It.is(x => x.nodePath === nodePath))).callback(() => { }).returns(() => Promise.resolve(true)); sqlOEProvider.setup(x => x.expandNode(TypeMoq.It.is(x => x.nodePath === nodePath))).callback(() => { }).returns(() => Promise.resolve(true));
// If I queue a second expand request (the first compconstes normally because of the original mock) and then close the session // If I queue a second expand request (the first compconstes normally because of the original mock) and then close the session
const rootNode = new TreeNode(NodeType.Root, '', '', false, objectExplorerSession.rootNode.nodePath, '', '', null, null, undefined, undefined); const rootNode = new TreeNode(NodeType.Root, '', '', false, objectExplorerSession.rootNode.nodePath, '', '', '', null, null, undefined, undefined);
await objectExplorerService.expandNode(mssqlProviderName, objectExplorerSession, rootNode); await objectExplorerService.expandNode(mssqlProviderName, objectExplorerSession, rootNode);
const expandPromise = objectExplorerService.expandNode(mssqlProviderName, objectExplorerSession, rootNode); const expandPromise = objectExplorerService.expandNode(mssqlProviderName, objectExplorerSession, rootNode);
const closeSessionResult = await objectExplorerService.closeSession(mssqlProviderName, objectExplorerSession); const closeSessionResult = await objectExplorerService.closeSession(mssqlProviderName, objectExplorerSession);
@@ -693,7 +697,7 @@ suite('SQL Object Explorer Service tests', () => {
// If I call resolveTreeNodeChildren once, set an error on the node, and then call it again // If I call resolveTreeNodeChildren once, set an error on the node, and then call it again
const tablesNodePath = 'testServerName/tables'; const tablesNodePath = 'testServerName/tables';
const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, tablesNodePath, '', '', null, null, undefined, undefined); const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, tablesNodePath, 'testServerName', '', '', null, null, undefined, undefined);
tablesNode.connection = connection; tablesNode.connection = connection;
await objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, tablesNode); await objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, tablesNode);
sqlOEProvider.verify(x => x.refreshNode(TypeMoq.It.is(x => x.nodePath === tablesNodePath)), TypeMoq.Times.never()); sqlOEProvider.verify(x => x.refreshNode(TypeMoq.It.is(x => x.nodePath === tablesNodePath)), TypeMoq.Times.never());

View File

@@ -14,6 +14,7 @@ const nodes: { [nodeName: string]: azdata.NodeInfo } =
{ {
'Server1': { 'Server1': {
nodePath: 'MyServer', nodePath: 'MyServer',
parentNodePath: '',
nodeStatus: '', nodeStatus: '',
nodeSubType: '', nodeSubType: '',
nodeType: 'Server', nodeType: 'Server',
@@ -24,6 +25,7 @@ const nodes: { [nodeName: string]: azdata.NodeInfo } =
}, },
'DatabasesFolder': { 'DatabasesFolder': {
nodePath: 'MyServer/Databases', nodePath: 'MyServer/Databases',
parentNodePath: 'MyServer',
nodeStatus: '', nodeStatus: '',
nodeSubType: '', nodeSubType: '',
nodeType: 'Folder', nodeType: 'Folder',
@@ -34,6 +36,7 @@ const nodes: { [nodeName: string]: azdata.NodeInfo } =
}, },
'Database1': { 'Database1': {
nodePath: 'MyServer/Databases/MyDatabase', nodePath: 'MyServer/Databases/MyDatabase',
parentNodePath: 'MyServer/Databases',
nodeStatus: '', nodeStatus: '',
nodeSubType: '', nodeSubType: '',
nodeType: 'Database', nodeType: 'Database',
@@ -44,6 +47,7 @@ const nodes: { [nodeName: string]: azdata.NodeInfo } =
}, },
'Database2': { 'Database2': {
nodePath: 'MyServer/Databases/My/TrickyDatabase', nodePath: 'MyServer/Databases/My/TrickyDatabase',
parentNodePath: 'MyServer/Databases',
nodeStatus: '', nodeStatus: '',
nodeSubType: '', nodeSubType: '',
nodeType: 'Database', nodeType: 'Database',
@@ -54,6 +58,7 @@ const nodes: { [nodeName: string]: azdata.NodeInfo } =
}, },
'TablesFolder': { 'TablesFolder': {
nodePath: 'MyServer/Databases/My/TrickyDatabase/Tables', nodePath: 'MyServer/Databases/My/TrickyDatabase/Tables',
parentNodePath: 'MyServer/Databases/My/TrickyDatabase',
nodeStatus: '', nodeStatus: '',
nodeSubType: '', nodeSubType: '',
nodeType: 'Folder', nodeType: 'Folder',