Fixes object explorer's manage keybinding shortcut (#21459)

* Fixes object explorer's manage keybinding shortcut

* Update src/sql/workbench/contrib/dashboard/browser/dashboardActions.ts

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>

* Update src/sql/workbench/contrib/dashboard/browser/dashboardActions.ts

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>

* Update src/sql/workbench/contrib/dashboard/browser/dashboardActions.ts

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>

* Fixes OEManageConnectionAction ctor missing argument

* Updates no connection profile comment

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
Lewis Sanchez
2022-12-22 10:49:18 -08:00
committed by GitHub
parent eb880834fb
commit 4a1e5001f0
2 changed files with 22 additions and 3 deletions

View File

@@ -5,6 +5,7 @@
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { TreeViewItemHandleArg } from 'sql/workbench/common/views';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IConnectionManagementService, IConnectionCompletionOptions } from 'sql/platform/connection/common/connectionManagement';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { generateUri } from 'sql/platform/connection/common/utils';
@@ -19,6 +20,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
import { IViewsService } from 'vs/workbench/common/views';
import { ConnectionViewletPanel } from 'sql/workbench/contrib/dataExplorer/browser/connectionViewletPanel';
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
export const DE_MANAGE_COMMAND_ID = 'dataExplorer.manage';
@@ -69,6 +71,7 @@ export class OEManageConnectionAction extends Action {
id: string,
label: string,
@IConnectionManagementService protected readonly _connectionManagementService: IConnectionManagementService,
@IEditorService private readonly _editorService: IEditorService,
@ICapabilitiesService protected readonly _capabilitiesService: ICapabilitiesService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IObjectExplorerService private readonly _objectExplorerService: IObjectExplorerService,
@@ -89,7 +92,8 @@ export class OEManageConnectionAction extends Action {
private async doManage(actionContext: ObjectExplorerActionsContext): Promise<boolean> {
let treeNode: TreeNode = undefined;
let connectionProfile: ConnectionProfile = undefined;
let connectionProfile: ConnectionProfile | undefined;
if (actionContext instanceof ObjectExplorerActionsContext) {
// Must use a real connection profile for this action due to lookup
connectionProfile = ConnectionProfile.fromIConnectionProfile(this._capabilitiesService, actionContext.connectionProfile);
@@ -100,10 +104,13 @@ export class OEManageConnectionAction extends Action {
}
}
}
else if (!actionContext) {
const globalProfile = TaskUtilities.getCurrentGlobalConnection(this._objectExplorerService, this._connectionManagementService, this._editorService);
connectionProfile = globalProfile ? ConnectionProfile.fromIConnectionProfile(this._capabilitiesService, globalProfile) : undefined;
}
if (!connectionProfile) {
// This should never happen. There should be always a valid connection if the manage action is called for
// an OE node or a database node
// No valid connection (e.g. This was triggered without an active context to get the connection from) so just return early
return true;
}

View File

@@ -39,6 +39,8 @@ import { Tree } from 'sql/base/parts/tree/browser/treeImpl';
import { AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
import { ConsoleLogger, LogService } from 'vs/platform/log/common/log';
import { TestAccessibilityService } from 'vs/platform/accessibility/test/common/testAccessibilityService';
import { TestEditorService } from 'vs/workbench/test/browser/workbenchTestServices';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
suite('SQL Connection Tree Action tests', () => {
let errorMessageService: TypeMoq.Mock<TestErrorMessageService>;
@@ -77,6 +79,12 @@ suite('SQL Connection Tree Action tests', () => {
return connectionManagementService;
}
function createEditorService(): TypeMoq.Mock<IEditorService> {
let editorService = TypeMoq.Mock.ofType<IEditorService>(TestEditorService, TypeMoq.MockBehavior.Strict);
return editorService;
}
function createObjectExplorerService(connectionManagementService: TestConnectionManagementService, getTreeNodeReturnVal: TreeNode): TypeMoq.Mock<ObjectExplorerService> {
let objectExplorerService = TypeMoq.Mock.ofType(ObjectExplorerService, TypeMoq.MockBehavior.Strict, connectionManagementService);
objectExplorerService.callBase = true;
@@ -107,6 +115,7 @@ suite('SQL Connection Tree Action tests', () => {
id: 'testId'
});
let connectionManagementService = createConnectionManagementService(isConnectedReturnValue, connection);
let editorService: TypeMoq.Mock<IEditorService> = createEditorService();
let objectExplorerService = createObjectExplorerService(connectionManagementService.object, undefined);
let treeSelectionMock = TypeMoq.Mock.ofType(TreeSelectionHandler);
let instantiationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Loose);
@@ -163,6 +172,7 @@ suite('SQL Connection Tree Action tests', () => {
OEManageConnectionAction.ID,
OEManageConnectionAction.LABEL,
connectionManagementService.object,
editorService.object,
capabilitiesService,
instantiationService.object,
objectExplorerService.object,
@@ -196,6 +206,7 @@ suite('SQL Connection Tree Action tests', () => {
let treeNode = new TreeNode(NodeType.Database, '', 'db node', false, '', '', '', undefined, undefined, undefined, undefined);
treeNode.connection = connection;
let connectionManagementService = createConnectionManagementService(isConnectedReturnValue, connection);
let editorService = createEditorService();
let objectExplorerService = createObjectExplorerService(connectionManagementService.object, treeNode);
let treeSelectionMock = TypeMoq.Mock.ofType(TreeSelectionHandler);
let instantiationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Loose);
@@ -207,6 +218,7 @@ suite('SQL Connection Tree Action tests', () => {
OEManageConnectionAction.ID,
OEManageConnectionAction.LABEL,
connectionManagementService.object,
editorService.object,
capabilitiesService,
instantiationService.object,
objectExplorerService.object,