mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 01:25:36 -05:00
Synapse query editor dropdown fix (#16684)
* formatting * update comment * format doc * fix connection test * remove unused imports * test server info mock * try with mocks * add server info check for tests * added logic for corner case
This commit is contained in:
@@ -46,6 +46,7 @@ import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
import { getErrorMessage, onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { gen3Version, sqlDataWarehouse } from 'sql/platform/connection/common/constants';
|
||||
|
||||
/**
|
||||
* Action class that query-based Actions will extend. This base class automatically handles activating and
|
||||
@@ -720,6 +721,33 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id profile id
|
||||
* @returns boolean saying if the server connection is a Gen 3 DW server
|
||||
*/
|
||||
private isDWGen3Database(id: string): boolean {
|
||||
const serverInfo = this.connectionManagementService.getServerInfo(id);
|
||||
if (serverInfo) {
|
||||
return serverInfo.serverEdition === sqlDataWarehouse &&
|
||||
serverInfo.serverMajorVersion === gen3Version;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dbName database name
|
||||
* @returns updated database name after stripping the pool name, if any
|
||||
*/
|
||||
private removePoolInstanceName(dbName: string): string {
|
||||
if (dbName.includes('@')) {
|
||||
const lastIndex = dbName.lastIndexOf('@');
|
||||
dbName = dbName.slice(0, lastIndex);
|
||||
}
|
||||
return dbName;
|
||||
}
|
||||
|
||||
private getCurrentDatabaseName(): string | undefined {
|
||||
if (!this._editor.input) {
|
||||
this.logService.error('editor input was null');
|
||||
@@ -730,6 +758,9 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt
|
||||
if (uri) {
|
||||
let profile = this.connectionManagementService.getConnectionProfile(uri);
|
||||
if (profile) {
|
||||
if (this.isDWGen3Database(profile.id)) {
|
||||
return this.removePoolInstanceName(profile.databaseName);
|
||||
}
|
||||
return profile.databaseName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/u
|
||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
import { ServerInfo } from 'azdata';
|
||||
|
||||
suite('SQL QueryAction Tests', () => {
|
||||
|
||||
@@ -463,6 +464,7 @@ suite('SQL QueryAction Tests', () => {
|
||||
|
||||
// ... Mock "isConnected" in ConnectionManagementService
|
||||
connectionManagementService.setup(x => x.isConnected(TypeMoq.It.isAnyString())).returns(() => isConnected);
|
||||
connectionManagementService.setup(x => x.getServerInfo(TypeMoq.It.isAny())).returns(() => <ServerInfo>{ serverMajorVersion: 12, serverEdition: 'Test' });
|
||||
connectionManagementService.setup(x => x.onConnectionChanged).returns(() => Event.None);
|
||||
connectionManagementService.setup(x => x.getConnectionProfile(TypeMoq.It.isAny())).returns(() => <IConnectionProfile>{
|
||||
databaseName: databaseName
|
||||
@@ -495,9 +497,10 @@ suite('SQL QueryAction Tests', () => {
|
||||
// ... Create event emitter we can use to trigger db changed event
|
||||
let dbChangedEmitter = new Emitter<IConnectionParams>();
|
||||
|
||||
// ... Create mock connection management service
|
||||
// ... Create mock connection management service and server info
|
||||
let databaseName = 'foobar';
|
||||
connectionManagementService.setup(x => x.onConnectionChanged).returns(() => dbChangedEmitter.event);
|
||||
connectionManagementService.setup(x => x.getServerInfo(TypeMoq.It.isAny())).returns(() => <ServerInfo>{ serverMajorVersion: 12, serverEdition: 'Test' });
|
||||
connectionManagementService.setup(x => x.getConnectionProfile(TypeMoq.It.isAny())).returns(() => <IConnectionProfile>{ databaseName: databaseName });
|
||||
connectionManagementService.setup(x => x.changeDatabase(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => Promise.resolve(true));
|
||||
|
||||
@@ -521,6 +524,7 @@ suite('SQL QueryAction Tests', () => {
|
||||
// ... Create mock connection management service that will not claim it's connected
|
||||
let databaseName = 'foobar';
|
||||
connectionManagementService.setup(x => x.onConnectionChanged).returns(() => dbChangedEmitter.event);
|
||||
connectionManagementService.setup(x => x.getServerInfo(TypeMoq.It.isAny())).returns(() => <ServerInfo>{ serverMajorVersion: 12, serverEdition: 'Test' });
|
||||
connectionManagementService.setup(x => x.getConnectionProfile(TypeMoq.It.isAny())).returns(() => <IConnectionProfile>{ databaseName: databaseName });
|
||||
connectionManagementService.setup(x => x.changeDatabase(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => Promise.resolve(true));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user