From f27b4a29cf56f2e8c707502a040648644937835a Mon Sep 17 00:00:00 2001 From: Aditya Bist Date: Tue, 15 Oct 2019 15:42:26 -0700 Subject: [PATCH] Fix UX for create session issue (#1434) * fix create session issue * add comment to get PR running * clear password if incorrect password is given when connecting * change createSession signature * review comments --- src/controllers/mainController.ts | 19 ++++++----- src/objectExplorer/objectExplorerProvider.ts | 6 +++- src/objectExplorer/objectExplorerService.ts | 33 +++++++++++++++----- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/controllers/mainController.ts b/src/controllers/mainController.ts index 0e04c1ee..0e163968 100644 --- a/src/controllers/mainController.ts +++ b/src/controllers/mainController.ts @@ -232,6 +232,7 @@ export default class MainController implements vscode.Disposable { this._context.subscriptions.push( vscode.commands.registerCommand( Constants.cmdConnectObjectExplorerNode, async (node: ConnectTreeNode) => { + self._objectExplorerProvider.currentNode = node.parentNode; await self.createObjectExplorerSession(node.parentNode.connectionCredentials); })); this._context.subscriptions.push( @@ -321,13 +322,17 @@ export default class MainController implements vscode.Disposable { */ private async createObjectExplorerSession(connectionCredentials?: IConnectionCredentials): Promise { let createSessionPromise = new Deferred(); - await this._objectExplorerProvider.createSession(createSessionPromise, connectionCredentials); - const newNode = await createSessionPromise; - this._objectExplorerProvider.refresh(undefined); - let expandSessionPromise = new Deferred(); - await this._objectExplorerProvider.expandNode(newNode, newNode.sessionId, expandSessionPromise); - await expandSessionPromise; - this._objectExplorerProvider.refresh(undefined); + const sessionId = await this._objectExplorerProvider.createSession(createSessionPromise, connectionCredentials); + if (sessionId) { + const newNode = await createSessionPromise; + if (newNode) { + this._objectExplorerProvider.refresh(undefined); + let expandSessionPromise = new Deferred(); + await this._objectExplorerProvider.expandNode(newNode, newNode.sessionId, expandSessionPromise); + await expandSessionPromise; + this._objectExplorerProvider.refresh(undefined); + } + } } diff --git a/src/objectExplorer/objectExplorerProvider.ts b/src/objectExplorer/objectExplorerProvider.ts index 8ec451c2..243e11c3 100644 --- a/src/objectExplorer/objectExplorerProvider.ts +++ b/src/objectExplorer/objectExplorerProvider.ts @@ -37,7 +37,7 @@ export class ObjectExplorerProvider implements vscode.TreeDataProvider { } } - async createSession(promise: Deferred, connectionCredentials?: IConnectionCredentials): Promise { + async createSession(promise: Deferred, connectionCredentials?: IConnectionCredentials): Promise { return this._objectExplorerService.createSession(promise, connectionCredentials); } @@ -98,4 +98,8 @@ export class ObjectExplorerProvider implements vscode.TreeDataProvider { public set objectExplorerService(value: ObjectExplorerService) { this._objectExplorerService = value; } + + public set currentNode(node: TreeNodeInfo) { + this._objectExplorerService.currentNode = node; + } } diff --git a/src/objectExplorer/objectExplorerService.ts b/src/objectExplorer/objectExplorerService.ts index 90113802..1054f6ad 100644 --- a/src/objectExplorer/objectExplorerService.ts +++ b/src/objectExplorer/objectExplorerService.ts @@ -267,10 +267,17 @@ export class ObjectExplorerService { } else { // start node session let promise = new Deferred(); - await this.createSession(promise, element.connectionCredentials); - let node = await promise; - // If node create session failed - if (!node) { + const sessionId = await this.createSession(promise, element.connectionCredentials); + if (sessionId) { + let node = await promise; + // if password failed + if (!node) { + const connectNode = new ConnectTreeNode(element); + this._treeNodeToChildrenMap.set(element, [connectNode]); + return [connectNode]; + } + } else { + // If node create session failed const signInNode = new AccountSignInTreeNode(element); this._treeNodeToChildrenMap.set(element, [signInNode]); return [signInNode]; @@ -310,7 +317,7 @@ export class ObjectExplorerService { * OE out of * @param connectionCredentials Connection Credentials for a node */ - public async createSession(promise: Deferred, connectionCredentials?: IConnectionCredentials): Promise { + public async createSession(promise: Deferred, connectionCredentials?: IConnectionCredentials): Promise { if (!connectionCredentials) { const connectionUI = this._connectionManager.connectionUI; connectionCredentials = await connectionUI.showConnections(false); @@ -325,7 +332,8 @@ export class ObjectExplorerService { // prompt for password password = await this._connectionManager.connectionUI.promptForPassword(); if (!password) { - return promise.resolve(undefined); + promise.resolve(undefined); + return undefined; } } else { // look up saved password @@ -339,8 +347,12 @@ export class ObjectExplorerService { if (response) { this._sessionIdToConnectionCredentialsMap.set(response.sessionId, connectionCredentials); this._sessionIdToPromiseMap.set(response.sessionId, promise); - return; + return response.sessionId; } + } else { + // no connection was made + promise.resolve(undefined); + return undefined; } } @@ -468,4 +480,11 @@ export class ObjectExplorerService { const connections = this._rootTreeNodeArray.map(node => node.connectionCredentials); return connections; } + + /** + * Setters + */ + public set currentNode(node: TreeNodeInfo) { + this._currentNode = node; + } }