Skip to content

Commit

Permalink
Merge ace7536 into 1f87a87
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Bist committed Nov 6, 2019
2 parents 1f87a87 + ace7536 commit 1384016
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 32 deletions.
4 changes: 0 additions & 4 deletions src/controllers/mainController.ts
Expand Up @@ -327,10 +327,6 @@ export default class MainController implements vscode.Disposable {
const newNode = await createSessionPromise;
if (newNode) {
this._objectExplorerProvider.refresh(undefined);
let expandSessionPromise = new Deferred<TreeNodeInfo[]>();
await this._objectExplorerProvider.expandNode(newNode, newNode.sessionId, expandSessionPromise);
await expandSessionPromise;
this._objectExplorerProvider.refresh(undefined);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/models/connectionCredentials.ts
Expand Up @@ -56,6 +56,7 @@ export class ConnectionCredentials implements IConnectionCredentials {
details.options['server'] += (',' + credentials.port);
}
details.options['database'] = credentials.database;
details.options['databaseDisplayName'] = credentials.database;
details.options['user'] = credentials.user;
details.options['password'] = credentials.password;
details.options['authenticationType'] = credentials.authenticationType;
Expand Down
28 changes: 17 additions & 11 deletions src/objectExplorer/objectExplorerService.ts
Expand Up @@ -65,21 +65,22 @@ export class ObjectExplorerService {
let nodeConnection = this._sessionIdToConnectionCredentialsMap.get(result.sessionId);
for (let connection of savedConnections) {
if (Utils.isSameConnection(connection.connectionCreds, nodeConnection)) {
nodeLabel = connection.label;
// if it's not the defaul label
if (connection.label !== connection.connectionCreds.server) {
nodeLabel = connection.label;
}
break;
}
}
// set connection and other things
if (self._currentNode && (self._currentNode.sessionId === result.sessionId)) {
nodeLabel = nodeLabel === result.rootNode.nodePath ?
self.createNodeLabel(self._currentNode.connectionCredentials) : nodeLabel;
nodeLabel = !nodeLabel ? self.createNodeLabel(self._currentNode.connectionCredentials) : nodeLabel;
self._currentNode = TreeNodeInfo.fromNodeInfo(result.rootNode, result.sessionId,
undefined, self._currentNode.connectionCredentials, nodeLabel);
undefined, self._currentNode.connectionCredentials, nodeLabel, Constants.serverLabel);
} else {
nodeLabel = nodeLabel === result.rootNode.nodePath ?
self.createNodeLabel(nodeConnection) : nodeLabel;
nodeLabel = !nodeLabel ? self.createNodeLabel(nodeConnection) : nodeLabel;
self._currentNode = TreeNodeInfo.fromNodeInfo(result.rootNode, result.sessionId,
undefined, nodeConnection, nodeLabel);
undefined, nodeConnection, nodeLabel, Constants.serverLabel);
}
// make a connection if not connected already
const nodeUri = ObjectExplorerUtils.getNodeUri(self._currentNode);
Expand Down Expand Up @@ -144,25 +145,29 @@ export class ObjectExplorerService {
return handler;
}

public async expandNode(node: TreeNodeInfo, sessionId: string, promise: Deferred<TreeNodeInfo[]>): Promise<boolean> {
public async expandNode(node: TreeNodeInfo, sessionId: string, promise: Deferred<TreeNodeInfo[]>): Promise<boolean | undefined> {
const expandParams: ExpandParams = {
sessionId: sessionId,
nodePath: node.nodePath
};
this._expandParamsToPromiseMap.set(expandParams, promise);
const response = await this._connectionManager.client.sendRequest(ExpandRequest.type, expandParams);
if (!response) {
if (response) {
this._currentNode = node;
return response;
} else {
this._expandParamsToPromiseMap.delete(expandParams);
promise.resolve(undefined);
return undefined;
}
this._currentNode = node;
return response;
}

public updateNode(node: TreeNodeInfo): void {
for (let rootTreeNode of this._rootTreeNodeArray) {
if (Utils.isSameConnection(node.connectionCredentials, rootTreeNode.connectionCredentials) &&
rootTreeNode.label === node.label) {
const index = this._rootTreeNodeArray.indexOf(rootTreeNode);
delete this._rootTreeNodeArray[index];
this._rootTreeNodeArray[index] = node;
return;
}
Expand All @@ -184,6 +189,7 @@ export class ObjectExplorerService {
}
this._treeNodeToChildrenMap.delete(child);
}
this._treeNodeToChildrenMap.delete(node);
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/objectExplorer/objectExplorerUtils.ts
Expand Up @@ -31,7 +31,12 @@ export class ObjectExplorerUtils {
}

public static getNodeUriFromProfile(profile: IConnectionProfile): string {
const uri = `${profile.server}_${profile.database}_${profile.user}_${profile.profileName}`;
let uri: string;
if (profile.authenticationType === Constants.sqlAuthentication) {
uri = `${profile.server}_${profile.database}_${profile.user}_${profile.profileName}`;
} else {
uri = `${profile.server}_${profile.database}_${profile.profileName}`;
}
return uri;
}

Expand All @@ -40,8 +45,10 @@ export class ObjectExplorerUtils {
return node.connectionCredentials.database;
}
while (node) {
if (node.nodeType === Constants.databaseString) {
return node.label;
if (node.metadata) {
if (node.metadata.metadataTypeName === Constants.databaseString) {
return node.metadata.name;
}
}
node = node.parentNode;
}
Expand Down
11 changes: 6 additions & 5 deletions src/objectExplorer/treeNodeInfo.ts
Expand Up @@ -52,14 +52,15 @@ export class TreeNodeInfo extends vscode.TreeItem {
sessionId: string,
parentNode: TreeNodeInfo,
connectionCredentials: IConnectionCredentials,
label?: string): TreeNodeInfo {

const treeNodeInfo = new TreeNodeInfo(label ? label : nodeInfo.label, nodeInfo.nodeType,
label?: string,
nodeType?: string): TreeNodeInfo {
let type = nodeType ? nodeType : nodeInfo.nodeType;
const treeNodeInfo = new TreeNodeInfo(label ? label : nodeInfo.label, type,
nodeInfo.isLeaf ? vscode.TreeItemCollapsibleState.None :
(nodeInfo.nodeType === Constants.serverLabel ? vscode.TreeItemCollapsibleState.Expanded :
(type === Constants.serverLabel ? vscode.TreeItemCollapsibleState.Expanded :
vscode.TreeItemCollapsibleState.Collapsed),
nodeInfo.nodePath, nodeInfo.nodeStatus,
nodeInfo.nodeType, sessionId, connectionCredentials, parentNode, nodeInfo.metadata);
type, sessionId, connectionCredentials, parentNode, nodeInfo.metadata);
return treeNodeInfo;
}

Expand Down
2 changes: 2 additions & 0 deletions src/scripting/scriptingService.ts
Expand Up @@ -89,4 +89,6 @@ export class ScriptingService {
return result.script;
}



}
32 changes: 23 additions & 9 deletions test/objectExplorerUtils.test.ts
Expand Up @@ -5,8 +5,10 @@
import * as path from 'path';
import { ObjectExplorerUtils } from '../src/objectExplorer/objectExplorerUtils';
import { expect, assert } from 'chai';
import Constants = require('../src/constants/constants');
import { TreeNodeInfo } from '../src/objectExplorer/treeNodeInfo';
import { ConnectionProfile } from '../src/models/connectionProfile';
import { ObjectMetadata } from '../src/models/contracts/metadata/metadataRequest';

suite('Object Explorer Utils Tests', () => {

Expand All @@ -28,16 +30,17 @@ suite('Object Explorer Utils Tests', () => {
testProfile.profileName = 'test_profile';
testProfile.database = 'test_database';
testProfile.user = 'test_user';
testProfile.authenticationType = Constants.sqlAuthentication;
const disconnectedTestNode = new TreeNodeInfo('disconnectedTest', undefined, undefined, undefined,
undefined, 'disconnectedServer', undefined, disconnectedProfile, undefined);
undefined, 'disconnectedServer', undefined, disconnectedProfile, undefined, undefined);
const serverTestNode = new TreeNodeInfo('serverTest', undefined, undefined, 'test_path',
undefined, 'Server', undefined, testProfile, undefined);
undefined, 'Server', undefined, testProfile, undefined, undefined);
const databaseTestNode = new TreeNodeInfo('databaseTest', undefined, undefined, 'test_path',
undefined, 'Database', undefined, testProfile, serverTestNode);
undefined, 'Database', undefined, testProfile, serverTestNode, undefined);
const tableTestNode = new TreeNodeInfo('tableTest', undefined, undefined, 'test_path',
undefined, 'Table', undefined, testProfile, databaseTestNode);
undefined, 'Table', undefined, testProfile, databaseTestNode, undefined);
const testNodes = [disconnectedTestNode, serverTestNode, tableTestNode];
const expectedUris = ['disconnected_server_undefined_undefined_undefined',
const expectedUris = ['disconnected_server_undefined_undefined',
'test_server_test_database_test_user_test_profile',
'test_server_test_database_test_user_test_profile'];

Expand All @@ -53,11 +56,13 @@ suite('Object Explorer Utils Tests', () => {
testProfile.profileName = 'test_profile';
testProfile.database = 'test_database';
testProfile.user = 'test_user';
testProfile.authenticationType = Constants.sqlAuthentication;
const testProfile2 = new ConnectionProfile();
testProfile2.server = 'test_server2';
testProfile2.profileName = undefined;
testProfile2.authenticationType = 'Integrated';
const testProfiles = [testProfile, testProfile2];
const expectedProfiles = ['test_server_test_database_test_user_test_profile', 'test_server2_undefined_undefined_undefined'];
const expectedProfiles = ['test_server_test_database_test_user_test_profile', 'test_server2_undefined_undefined'];

for (let i = 0; i < testProfiles.length; i++) {
const uri = ObjectExplorerUtils.getNodeUriFromProfile(testProfiles[i]);
Expand All @@ -73,12 +78,21 @@ suite('Object Explorer Utils Tests', () => {
testProfile.user = 'test_user';
const serverTestNode = new TreeNodeInfo('serverTest', undefined, undefined, 'test_path',
undefined, 'Server', undefined, testProfile, undefined);
let databaseMetatadata: ObjectMetadata = {
metadataType: undefined,
metadataTypeName: Constants.databaseString,
urn: undefined,
name: 'databaseTest',
schema: undefined
};
const databaseTestNode = new TreeNodeInfo('databaseTest', undefined, undefined, 'test_path',
undefined, 'Database', undefined, undefined, serverTestNode);
undefined, 'Database', undefined, undefined, serverTestNode, databaseMetatadata);
const databaseTestNode2 = new TreeNodeInfo('databaseTest', undefined, undefined, 'test_path',
undefined, 'Database', undefined, undefined, serverTestNode, undefined);
const tableTestNode = new TreeNodeInfo('tableTest', undefined, undefined, 'test_path',
undefined, 'Table', undefined, undefined, databaseTestNode);
const testNodes = [serverTestNode, databaseTestNode, tableTestNode];
const expectedDatabaseNames = ['test_database', 'databaseTest', 'databaseTest'];
const testNodes = [serverTestNode, databaseTestNode, databaseTestNode2, tableTestNode];
const expectedDatabaseNames = ['test_database', 'databaseTest', '<default>', 'databaseTest'];
for (let i = 0; i < testNodes.length; i++) {
let databaseName = ObjectExplorerUtils.getDatabaseName(testNodes[i]);
assert.equal(databaseName, expectedDatabaseNames[i]);
Expand Down

0 comments on commit 1384016

Please sign in to comment.