Revert "Revert "OE clicking and awaiting the expansion calls"" (#6923)

* Revert "Revert "OE clicking and awaiting the expansion calls" (#6921)"

This reverts commit b9e3a468ae.

* Handle edge cases better

* Polling for OE load time
This commit is contained in:
Amir Omidi
2019-09-03 10:31:29 -07:00
committed by GitHub
parent a5c824a318
commit 33a7fe38e1
7 changed files with 82 additions and 36 deletions

View File

@@ -14,7 +14,7 @@ import { TestServerProfile } from './testConfig';
* @param timeout optional timeout parameter * @param timeout optional timeout parameter
* Returns connection id for a new connection * Returns connection id for a new connection
*/ */
export async function connectToServer(server: TestServerProfile, timeout: number = 3000): Promise<string> { export async function connectToServer(server: TestServerProfile, timeout: number = 10000): Promise<string> {
let connectionProfile: azdata.IConnectionProfile = { let connectionProfile: azdata.IConnectionProfile = {
serverName: server.serverName, serverName: server.serverName,
databaseName: server.database, databaseName: server.database,
@@ -36,10 +36,37 @@ export async function connectToServer(server: TestServerProfile, timeout: number
//workaround //workaround
//wait for OE to load //wait for OE to load
await new Promise(c => setTimeout(c, timeout)); await pollTimeout(async () => {
const nodes = await azdata.objectexplorer.getActiveConnectionNodes();
let found = nodes.some(node => {
return node.connectionId === result.connectionId;
});
if (found === undefined) {
found = false;
}
return found;
}, 1000, timeout);
return result.connectionId; return result.connectionId;
} }
export async function pollTimeout(predicate: () => Thenable<boolean>, intervalDelay: number, timeoutTime: number): Promise<boolean> {
let interval: NodeJS.Timer;
return new Promise(pollOver => {
const complete = (success = false) => {
clearInterval(interval);
pollOver(success);
};
interval = setInterval(async () => {
const predResult = await predicate();
if (predResult) {
complete(true);
}
}, intervalDelay);
setTimeout(complete, timeoutTime);
});
}
export async function ensureConnectionViewOpened() { export async function ensureConnectionViewOpened() {
await vscode.commands.executeCommand('dataExplorer.servers.focus'); await vscode.commands.executeCommand('dataExplorer.servers.focus');
} }

View File

@@ -75,8 +75,8 @@ export class ServerTreeDataSource implements IDataSource {
// It has been tested for connecting to the server in profile itself and things work fine there. // It has been tested for connecting to the server in profile itself and things work fine there.
this._objectExplorerService.resolveTreeNodeChildren(node.getSession(), node).then(() => { this._objectExplorerService.resolveTreeNodeChildren(node.getSession(), node).then(() => {
resolve(node.children); resolve(node.children);
}, expandError => { }, async expandError => {
node.setExpandedState(TreeItemCollapsibleState.Collapsed); await node.setExpandedState(TreeItemCollapsibleState.Collapsed);
node.errorStateMessage = expandError; node.errorStateMessage = expandError;
this.showError(expandError); this.showError(expandError);
// collapse node and refresh in case of error so remove tree cache // collapse node and refresh in case of error so remove tree cache

View File

@@ -171,13 +171,13 @@ export class ServerTreeView extends Disposable {
})); }));
} }
return new Promise<void>((resolve, reject) => { return new Promise<void>(async (resolve, reject) => {
this.refreshTree(); this.refreshTree();
const root = <ConnectionProfileGroup>this._tree.getInput(); const root = <ConnectionProfileGroup>this._tree.getInput();
const expandGroups: boolean = this._configurationService.getValue(SERVER_GROUP_CONFIG)[SERVER_GROUP_AUTOEXPAND_CONFIG]; const expandGroups: boolean = this._configurationService.getValue(SERVER_GROUP_CONFIG)[SERVER_GROUP_AUTOEXPAND_CONFIG];
if (expandGroups) { if (expandGroups) {
this._tree.expandAll(ConnectionProfileGroup.getSubgroups(root)); await this._tree.expandAll(ConnectionProfileGroup.getSubgroups(root));
} }
if (root && !root.hasValidConnections) { if (root && !root.hasValidConnections) {
@@ -270,9 +270,9 @@ export class ServerTreeView extends Disposable {
if (connection) { if (connection) {
const conn = this.getConnectionInTreeInput(connection.id); const conn = this.getConnectionInTreeInput(connection.id);
if (conn) { if (conn) {
return this._objectExplorerService.deleteObjectExplorerNode(conn).then(() => { return this._objectExplorerService.deleteObjectExplorerNode(conn).then(async () => {
this._tree.collapse(conn); await this._tree.collapse(conn);
this._tree.refresh(conn); return this._tree.refresh(conn);
}); });
} }
} }
@@ -342,10 +342,10 @@ export class ServerTreeView extends Disposable {
} else { } else {
treeInput = filteredResults[0]; treeInput = filteredResults[0];
} }
this._tree.setInput(treeInput).then(() => { this._tree.setInput(treeInput).then(async () => {
if (isHidden(this.messages)) { if (isHidden(this.messages)) {
this._tree.getFocus(); this._tree.getFocus();
this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput)); await this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput));
} else { } else {
this._tree.clearFocus(); this._tree.clearFocus();
} }
@@ -374,10 +374,10 @@ export class ServerTreeView extends Disposable {
// Add all connections to tree root and set tree input // Add all connections to tree root and set tree input
const treeInput = new ConnectionProfileGroup('searchroot', undefined, 'searchroot', undefined, undefined); const treeInput = new ConnectionProfileGroup('searchroot', undefined, 'searchroot', undefined, undefined);
treeInput.addConnections(filteredResults); treeInput.addConnections(filteredResults);
this._tree.setInput(treeInput).then(() => { this._tree.setInput(treeInput).then(async () => {
if (isHidden(this.messages)) { if (isHidden(this.messages)) {
this._tree.getFocus(); this._tree.getFocus();
this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput)); await this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput));
} else { } else {
this._tree.clearFocus(); this._tree.clearFocus();
} }

View File

@@ -15,8 +15,9 @@ import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/tree
export class TreeSelectionHandler { export class TreeSelectionHandler {
// progressRunner: IProgressRunner; // progressRunner: IProgressRunner;
private _lastClicked: any; private _lastClicked: any[];
private _clickTimer: any = undefined; private _clickTimer: any = undefined;
private _otherTimer: any = undefined;
// constructor(@IProgressService private _progressService: IProgressService) { // constructor(@IProgressService private _progressService: IProgressService) {
@@ -38,14 +39,21 @@ export class TreeSelectionHandler {
return event && event.payload && event.payload.origin === 'mouse'; return event && event.payload && event.payload.origin === 'mouse';
} }
private isKeyboardEvent(event: any): boolean {
return event && event.payload && event.payload.origin === 'keyboard';
}
/** /**
* Handle selection of tree element * Handle select ion of tree element
*/ */
public onTreeSelect(event: any, tree: ITree, connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, connectionCompleteCallback: () => void) { public onTreeSelect(event: any, tree: ITree, connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, connectionCompleteCallback: () => void) {
let sendSelectionEvent = ((event: any, selection: any, isDoubleClick: boolean) => { let sendSelectionEvent = ((event: any, selection: any, isDoubleClick: boolean, userInteraction: boolean) => {
let isKeyboard = event && event.payload && event.payload.origin === 'keyboard'; // userInteraction: defensive - don't touch this something else is handling it.
if (userInteraction === true && this._lastClicked && this._lastClicked[0] === selection[0]) {
this._lastClicked = undefined;
}
if (!TreeUpdateUtils.isInDragAndDrop) { if (!TreeUpdateUtils.isInDragAndDrop) {
this.handleTreeItemSelected(connectionManagementService, objectExplorerService, isDoubleClick, isKeyboard, selection, tree, connectionCompleteCallback); this.handleTreeItemSelected(connectionManagementService, objectExplorerService, isDoubleClick, this.isKeyboardEvent(event), selection, tree, connectionCompleteCallback);
} }
}); });
@@ -56,18 +64,29 @@ export class TreeSelectionHandler {
} }
let specificSelection = selection[0]; let specificSelection = selection[0];
if (this.isMouseEvent(event)) { if (this.isMouseEvent(event) || this.isKeyboardEvent(event)) {
if (this._lastClicked === specificSelection) { if (this._lastClicked !== undefined) {
clearTimeout(this._clickTimer); clearTimeout(this._clickTimer);
sendSelectionEvent(event, selection, true); let lastSpecificClick = this._lastClicked[0];
return;
}
this._lastClicked = specificSelection;
}
this._clickTimer = setTimeout(() => { if (lastSpecificClick === specificSelection) {
sendSelectionEvent(event, selection, false); sendSelectionEvent(event, selection, true, true);
}, 300); return;
} else {
sendSelectionEvent(event, this._lastClicked, false, true);
}
}
this._lastClicked = selection;
this._clickTimer = setTimeout(() => {
sendSelectionEvent(event, selection, false, true);
}, 400);
} else {
clearTimeout(this._otherTimer);
this._otherTimer = setTimeout(() => {
sendSelectionEvent(event, selection, false, false);
}, 400);
}
} }
/** /**

View File

@@ -74,13 +74,13 @@ export class TreeUpdateUtils {
treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService, providers); treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService, providers);
} }
const previousTreeInput: any = tree.getInput(); const previousTreeInput: any = tree.getInput();
return tree.setInput(treeInput).then(() => { return tree.setInput(treeInput).then(async () => {
if (previousTreeInput instanceof Disposable) { if (previousTreeInput instanceof Disposable) {
previousTreeInput.dispose(); previousTreeInput.dispose();
} }
// Make sure to expand all folders that where expanded in the previous session // Make sure to expand all folders that where expanded in the previous session
if (targetsToExpand) { if (targetsToExpand) {
tree.expandAll(targetsToExpand); await tree.expandAll(targetsToExpand);
} }
if (selectedElement) { if (selectedElement) {
tree.select(selectedElement); tree.select(selectedElement);
@@ -118,10 +118,10 @@ export class TreeUpdateUtils {
let treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService); let treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService);
if (treeInput) { if (treeInput) {
if (treeInput !== tree.getInput()) { if (treeInput !== tree.getInput()) {
return tree.setInput(treeInput).then(() => { return tree.setInput(treeInput).then(async () => {
// Make sure to expand all folders that where expanded in the previous session // Make sure to expand all folders that where expanded in the previous session
if (targetsToExpand) { if (targetsToExpand) {
tree.expandAll(targetsToExpand); await tree.expandAll(targetsToExpand);
} }
if (selectedElement) { if (selectedElement) {
tree.select(selectedElement); tree.select(selectedElement);
@@ -316,4 +316,4 @@ export class TreeUpdateUtils {
} }
return connectionProfile; return connectionProfile;
} }
} }

View File

@@ -120,10 +120,10 @@ export class TaskHistoryView {
//Get the tree Input //Get the tree Input
let treeInput = this._taskService.getAllTasks(); let treeInput = this._taskService.getAllTasks();
if (treeInput) { if (treeInput) {
this._tree.setInput(treeInput).then(() => { this._tree.setInput(treeInput).then(async () => {
// Make sure to expand all folders that where expanded in the previous session // Make sure to expand all folders that where expanded in the previous session
if (targetsToExpand) { if (targetsToExpand) {
this._tree.expandAll(targetsToExpand); await this._tree.expandAll(targetsToExpand);
} }
if (selectedElement) { if (selectedElement) {
this._tree.select(selectedElement); this._tree.select(selectedElement);

View File

@@ -604,7 +604,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
nodeInfo.nodeSubType, nodeInfo.nodeStatus, parent, nodeInfo.metadata, nodeInfo.iconType, { nodeInfo.nodeSubType, nodeInfo.nodeStatus, parent, nodeInfo.metadata, nodeInfo.iconType, {
getChildren: treeNode => this.getChildren(treeNode), getChildren: treeNode => this.getChildren(treeNode),
isExpanded: treeNode => this.isExpanded(treeNode), isExpanded: treeNode => this.isExpanded(treeNode),
setNodeExpandedState: (treeNode, expandedState) => this.setNodeExpandedState(treeNode, expandedState), setNodeExpandedState: async (treeNode, expandedState) => await this.setNodeExpandedState(treeNode, expandedState),
setNodeSelected: (treeNode, selected, clearOtherSelections: boolean = undefined) => this.setNodeSelected(treeNode, selected, clearOtherSelections) setNodeSelected: (treeNode, selected, clearOtherSelections: boolean = undefined) => this.setNodeSelected(treeNode, selected, clearOtherSelections)
}); });
node.childProvider = nodeInfo.childProvider; node.childProvider = nodeInfo.childProvider;