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

@@ -522,6 +522,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
let allNodes: azdata.NodeInfo[] = [];
let errorNode: azdata.NodeInfo = {
nodePath: nodePath,
parentNodePath: '',
objectType: 'error',
label: 'Error',
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, {
getChildren: (treeNode?: TreeNode) => this.getChildren(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);
}
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);
const childrenNodes = await this.oe.refreshTreeNode({
success: true,
@@ -168,6 +168,7 @@ export class OEShimService extends Disposable implements IOEShimService {
}
const nodeInfo: azdata.NodeInfo = {
nodePath: nodePath,
parentNodePath: node.parentNodePath,
nodeType: node.nodeTypeId,
objectType: node.objectType,
nodeSubType: node.nodeSubType,

View File

@@ -69,7 +69,7 @@ export class ServerTreeActionProvider {
* Return actions for connection elements
*/
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.
this._connectionManagementService.addSavedPassword(profile, true);
node.connection = profile;

View File

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

View File

@@ -46,6 +46,7 @@ suite('SQL Object Explorer Service tests', () => {
const NodeInfoTable1 = {
nodePath: 'testServerName/tables/dbo.Table1',
parentNodePath: 'testServerName/tables',
nodeType: NodeType.Table,
objectType: '',
label: 'dbo.Table1',
@@ -57,6 +58,7 @@ suite('SQL Object Explorer Service tests', () => {
};
const NodeInfoTable2 = {
nodePath: 'testServerName/tables/dbo.Table2',
parentNodePath: 'testServerName/tables',
nodeType: NodeType.Table,
objectType: '',
label: 'dbo.Table2',
@@ -69,6 +71,7 @@ suite('SQL Object Explorer Service tests', () => {
const NodeInfoTable3 = {
nodePath: 'testServerName/tables/dbo.Table3',
parentNodePath: 'testServerName/tables',
nodeType: NodeType.Table,
objectType: '',
label: 'dbo.Table3',
@@ -84,6 +87,7 @@ suite('SQL Object Explorer Service tests', () => {
sessionId: sessionId,
rootNode: {
nodePath: 'testServerName/tables',
parentNodePath: 'testServerName',
nodeType: NodeType.Folder,
objectType: '',
label: 'Tables',
@@ -348,7 +352,7 @@ suite('SQL Object Explorer Service tests', () => {
});
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);
objectExplorerService.onSessionCreated(1, objectExplorerSession);
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 () => {
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);
objectExplorerService.onSessionCreated(1, objectExplorerSession);
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 () => {
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;
await objectExplorerService.createNewSession(mssqlProviderName, connection);
objectExplorerService.onSessionCreated(1, objectExplorerSession);
@@ -389,7 +393,7 @@ suite('SQL Object Explorer Service tests', () => {
});
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;
await objectExplorerService.createNewSession(mssqlProviderName, connection);
objectExplorerService.onSessionCreated(1, objectExplorerSession);
@@ -436,13 +440,13 @@ suite('SQL Object Explorer Service tests', () => {
parentName: 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.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];
const table1Node = new TreeNode(NodeType.Table, '', 'dbo.Table1', false, 'testServerName\\Db1\\tables\\dbo.Table1', '', '', tablesNode, undefined, undefined, undefined);
const table2Node = new TreeNode(NodeType.Table, '', 'dbo.Table2', false, 'testServerName\\Db1\\tables\\dbo.Table2', '', '', 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', 'testServerName/Db1/tables', '', '', tablesNode, undefined, undefined, undefined);
tablesNode.children = [table1Node, table2Node];
assert.strictEqual(table1Node.getSession(), objectExplorerSession);
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', () => {
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;
serverTreeView.setup(x => x.getSelection()).returns(() => [databaseNode]);
objectExplorerService.registerServerTreeView(serverTreeView.object);
@@ -483,8 +487,8 @@ suite('SQL Object Explorer Service tests', () => {
parentTypeName: undefined
};
const databaseName = 'Db1';
const databaseNode = new TreeNode(NodeType.Database, '', databaseName, false, 'testServerName\\Db1', '', '', undefined, databaseMetadata, undefined, undefined);
const tablesNode = new TreeNode(NodeType.Folder, '', 'Tables', false, 'testServerName\\Db1\\tables', '', '', databaseNode, undefined, 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', 'testServerName/Db1', '', '', databaseNode, undefined, undefined, undefined);
databaseNode.connection = connection;
databaseNode.children = [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));
// 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);
const expandPromise = objectExplorerService.expandNode(mssqlProviderName, objectExplorerSession, rootNode);
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
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;
await objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, tablesNode);
sqlOEProvider.verify(x => x.refreshNode(TypeMoq.It.is(x => x.nodePath === tablesNodePath)), TypeMoq.Times.never());