Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fix to drag and drop #24252

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/sql/platform/connection/common/connectionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,17 @@ export class ConnectionConfig {
*/
public canChangeConnectionConfig(profile: ConnectionProfile, newGroupID: string): boolean {
let profiles = this.getIConnectionProfileStores(true);
let existingProfile = profiles.find(p =>
p.providerName === profile.providerName &&
this.checkIfAuthenticationOptionsMatch(p, profile) &&
p.options.databaseName === profile.options.databaseName &&
p.options.serverName === profile.options.serverName &&
p.options.userName === profile.options.userName &&
p.options.connectionName === profile.options.connectionName &&
p.groupId === newGroupID &&
this.checkIfNonDefaultOptionsMatch(p, profile));
let existingProfile = profiles.find(p => {
smartguest marked this conversation as resolved.
Show resolved Hide resolved
let authenticationCheck = this.checkIfAuthenticationOptionsMatch(p, profile);
let nonDefaultCheck = this.checkIfNonDefaultOptionsMatch(p, profile);
let basicOptionCheck = p.providerName === profile.providerName &&
p.options.database === profile.options.database &&
p.options.server === profile.options.server &&
p.options.user === profile.options.user &&
p.options.connectionName === profile.options.connectionName &&
p.groupId === newGroupID;
return authenticationCheck && nonDefaultCheck && basicOptionCheck;
});
return existingProfile === undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IDragAndDropData } from 'vs/base/browser/dnd';
import { ITreeDragAndDrop, ITreeDragOverReaction, TreeDragOverReactions } from 'vs/base/browser/ui/tree/tree';
import { ServerTreeDragAndDrop } from 'sql/workbench/services/objectExplorer/browser/dragAndDropController';
import { ServerTreeElement, AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
import { INotificationService } from 'vs/platform/notification/common/notification';

/**
* Implements drag and drop for the server tree
Expand All @@ -22,8 +23,9 @@ export class AsyncServerTreeDragAndDrop implements ITreeDragAndDrop<ServerTreeEl

constructor(
@IConnectionManagementService connectionManagementService: IConnectionManagementService,
@INotificationService notificationService: INotificationService
) {
this._dragAndDrop = new ServerTreeDragAndDrop(connectionManagementService);
this._dragAndDrop = new ServerTreeDragAndDrop(connectionManagementService, notificationService);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { UNSAVED_GROUP_ID, mssqlProviderName, pgsqlProviderName } from 'sql/plat
import { DataTransfers, IDragAndDropData } from 'vs/base/browser/dnd';
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
import { AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { localize } from 'vs/nls';

export function supportsNodeNameDrop(nodeId: string): boolean {
if (nodeId === 'Table' || nodeId === 'Column' || nodeId === 'View' || nodeId === 'Function') {
Expand Down Expand Up @@ -52,9 +54,13 @@ function escapeString(input: string | undefined): string | undefined {
*/
export class ServerTreeDragAndDrop implements IDragAndDrop {

private rejectDueToDupe: boolean;

constructor(
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@INotificationService private _notificationService: INotificationService
) {
this.rejectDueToDupe = false;
}

/**
Expand Down Expand Up @@ -195,6 +201,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
} else if (targetElement instanceof ConnectionProfile) {
canDragOver = source.groupId !== targetElement.groupId &&
this._connectionManagementService.canChangeConnectionConfig(source, targetElement.groupId);
this.rejectDueToDupe = !canDragOver;
} else if (targetElement instanceof TreeNode) {
canDragOver = source.groupId !== this.getTreeNodeParentGroup(targetElement).id;
}
Expand Down Expand Up @@ -263,6 +270,10 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
}

public dropAbort(tree: ITree, data: IDragAndDropData): void {
if (this.rejectDueToDupe) {
this.rejectDueToDupe = false;
this._notificationService.info(localize('objectExplorer.dragAndDropController.existingIdenticalProfile', 'Cannot drag profile into group: A profile with identical options already exists in the group.'));
}
TreeUpdateUtils.isInDragAndDrop = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/t
import { IStorageService } from 'vs/platform/storage/common/storage';
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
Expand Down Expand Up @@ -63,7 +64,7 @@ suite('AsyncServerTreeDragAndDrop', () => {
undefined, // configuration service
new TestCapabilitiesService(), // capabilities service
);
serverTreeDragAndDrop = new AsyncServerTreeDragAndDrop(mockConnectionManagementService.object);
serverTreeDragAndDrop = new AsyncServerTreeDragAndDrop(mockConnectionManagementService.object, new TestNotificationService());

capabilitiesService = new TestCapabilitiesService();
capabilitiesService.capabilities[mssqlProviderName] = { connection: msSQLCapabilities };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/t
import { IStorageService } from 'vs/platform/storage/common/storage';
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
import { ServerTreeDragAndDrop } from 'sql/workbench/services/objectExplorer/browser/dragAndDropController';
import { TestTree } from 'sql/workbench/test/browser/parts/tree/treeMock';
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
Expand Down Expand Up @@ -90,7 +91,7 @@ suite('SQL Drag And Drop Controller tests', () => {
undefined, // configuration service
new TestCapabilitiesService(), // capabilities service
);
serverTreeDragAndDrop = new ServerTreeDragAndDrop(mockConnectionManagementService.object);
serverTreeDragAndDrop = new ServerTreeDragAndDrop(mockConnectionManagementService.object, new TestNotificationService());

capabilitiesService = new TestCapabilitiesService();
capabilitiesService.capabilities[mssqlProviderName] = { connection: msSQLCapabilities };
Expand Down