handle unsupported connections in OE/Recent connections view (#20588)

* handle unknown provider in OE

* more update

* add comment

* test
This commit is contained in:
Alan Ren
2022-09-12 11:48:08 -07:00
committed by GitHub
parent b5408495b9
commit 6015c8e2f4
8 changed files with 67 additions and 46 deletions

View File

@@ -6,7 +6,6 @@
import 'vs/css!./media/objectTypes/objecttypes';
import * as dom from 'vs/base/browser/dom';
import { localize } from 'vs/nls';
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import { ConnectionProfile, IconPath } from 'sql/platform/connection/common/connectionProfile';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
@@ -121,10 +120,6 @@ class ConnectionProfileTemplate extends Disposable {
const iconPath: IconPath | undefined = getIconPath(element, this._connectionManagementService);
renderServerIcon(this._icon, iconPath);
let label = element.title;
if (!element.isConnectionOptionsValid) {
label = localize('loading', "Loading...");
}
this._label.textContent = label;
this._root.title = element.serverInfo;
}

View File

@@ -6,7 +6,6 @@
import 'vs/css!./media/objectTypes/objecttypes';
import * as dom from 'vs/base/browser/dom';
import { localize } from 'vs/nls';
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { ITree, IRenderer } from 'vs/base/parts/tree/browser/tree';
@@ -227,10 +226,6 @@ export class ServerTreeRenderer implements IRenderer {
this.renderServerIcon(templateData.icon, iconPath, isConnected);
let label = connection.title;
if (!connection.isConnectionOptionsValid) {
label = localize('loading', "Loading...");
}
templateData.label.textContent = label;
templateData.root.title = connection.serverInfo;
templateData.connectionProfile = connection;

View File

@@ -12,6 +12,8 @@ import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/br
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
import { TreeUpdateUtils } from 'sql/workbench/services/objectExplorer/browser/treeUpdateUtils';
import { AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { onUnexpectedError } from 'vs/base/common/errors';
export class TreeSelectionHandler {
// progressRunner: IProgressRunner;
@@ -47,14 +49,14 @@ export class TreeSelectionHandler {
/**
* Handle selection of tree element
*/
public onTreeSelect(event: any, tree: AsyncServerTree | ITree, connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, connectionCompleteCallback: () => void) {
public onTreeSelect(event: any, tree: AsyncServerTree | ITree, connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, capabilitiesService: ICapabilitiesService, connectionCompleteCallback: () => void) {
let sendSelectionEvent = ((event: any, selection: any, isDoubleClick: boolean, userInteraction: boolean) => {
// 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) {
this.handleTreeItemSelected(connectionManagementService, objectExplorerService, isDoubleClick, this.isKeyboardEvent(event), selection, tree, connectionCompleteCallback);
this.handleTreeItemSelected(connectionManagementService, objectExplorerService, capabilitiesService, isDoubleClick, this.isKeyboardEvent(event), selection, tree, connectionCompleteCallback);
}
});
@@ -94,15 +96,20 @@ export class TreeSelectionHandler {
*
* @param connectionManagementService
* @param objectExplorerService
* @param capabilitiesService
* @param isDoubleClick
* @param isKeyboard
* @param selection
* @param tree
* @param connectionCompleteCallback A function that gets called after a connection is established due to the selection, if needed
*/
private handleTreeItemSelected(connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, isDoubleClick: boolean, isKeyboard: boolean, selection: any[], tree: AsyncServerTree | ITree, connectionCompleteCallback: () => void): void {
private handleTreeItemSelected(connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, capabilitiesService: ICapabilitiesService, isDoubleClick: boolean, isKeyboard: boolean, selection: any[], tree: AsyncServerTree | ITree, connectionCompleteCallback: () => void): void {
if (tree instanceof AsyncServerTree) {
if (selection && selection.length > 0 && (selection[0] instanceof ConnectionProfile)) {
if (!capabilitiesService.getCapabilities(selection[0].providerName)) {
connectionManagementService.handleUnsupportedProvider(selection[0].providerName).catch(onUnexpectedError);
return;
}
this.onTreeActionStateChange(true);
}
} else {
@@ -116,6 +123,10 @@ export class TreeSelectionHandler {
};
if (selection && selection.length > 0 && (selection[0] instanceof ConnectionProfile)) {
connectionProfile = <ConnectionProfile>selection[0];
if (!capabilitiesService.getCapabilities(connectionProfile.providerName)) {
connectionManagementService.handleUnsupportedProvider(connectionProfile.providerName).catch(onUnexpectedError);
return;
}
if (connectionProfile) {
this.onTreeActionStateChange(true);