mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51: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:
@@ -32,3 +32,7 @@ export const dstsAuth = 'dstsAuth';
|
|||||||
export const cmsProviderName = 'MSSQL-CMS';
|
export const cmsProviderName = 'MSSQL-CMS';
|
||||||
|
|
||||||
export const UNSAVED_GROUP_ID = 'unsaved';
|
export const UNSAVED_GROUP_ID = 'unsaved';
|
||||||
|
|
||||||
|
/* Server Type Constants */
|
||||||
|
export const sqlDataWarehouse = 'Azure SQL Data Warehouse';
|
||||||
|
export const gen3Version = 12;
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
getServerInfo(profileId: string): azdata.ServerInfo {
|
getServerInfo(profileId: string): azdata.ServerInfo {
|
||||||
return undefined!;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
getConnectionString(connectionId: string): Thenable<string> {
|
getConnectionString(connectionId: string): Thenable<string> {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import { ILogService } from 'vs/platform/log/common/log';
|
|||||||
import { IRange } from 'vs/editor/common/core/range';
|
import { IRange } from 'vs/editor/common/core/range';
|
||||||
import { getErrorMessage, onUnexpectedError } from 'vs/base/common/errors';
|
import { getErrorMessage, onUnexpectedError } from 'vs/base/common/errors';
|
||||||
import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
|
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
|
* 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 {
|
private getCurrentDatabaseName(): string | undefined {
|
||||||
if (!this._editor.input) {
|
if (!this._editor.input) {
|
||||||
this.logService.error('editor input was null');
|
this.logService.error('editor input was null');
|
||||||
@@ -730,6 +758,9 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt
|
|||||||
if (uri) {
|
if (uri) {
|
||||||
let profile = this.connectionManagementService.getConnectionProfile(uri);
|
let profile = this.connectionManagementService.getConnectionProfile(uri);
|
||||||
if (profile) {
|
if (profile) {
|
||||||
|
if (this.isDWGen3Database(profile.id)) {
|
||||||
|
return this.removePoolInstanceName(profile.databaseName);
|
||||||
|
}
|
||||||
return 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 { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||||
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
|
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||||
import { IRange } from 'vs/editor/common/core/range';
|
import { IRange } from 'vs/editor/common/core/range';
|
||||||
|
import { ServerInfo } from 'azdata';
|
||||||
|
|
||||||
suite('SQL QueryAction Tests', () => {
|
suite('SQL QueryAction Tests', () => {
|
||||||
|
|
||||||
@@ -463,6 +464,7 @@ suite('SQL QueryAction Tests', () => {
|
|||||||
|
|
||||||
// ... Mock "isConnected" in ConnectionManagementService
|
// ... Mock "isConnected" in ConnectionManagementService
|
||||||
connectionManagementService.setup(x => x.isConnected(TypeMoq.It.isAnyString())).returns(() => isConnected);
|
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.onConnectionChanged).returns(() => Event.None);
|
||||||
connectionManagementService.setup(x => x.getConnectionProfile(TypeMoq.It.isAny())).returns(() => <IConnectionProfile>{
|
connectionManagementService.setup(x => x.getConnectionProfile(TypeMoq.It.isAny())).returns(() => <IConnectionProfile>{
|
||||||
databaseName: databaseName
|
databaseName: databaseName
|
||||||
@@ -495,9 +497,10 @@ suite('SQL QueryAction Tests', () => {
|
|||||||
// ... Create event emitter we can use to trigger db changed event
|
// ... Create event emitter we can use to trigger db changed event
|
||||||
let dbChangedEmitter = new Emitter<IConnectionParams>();
|
let dbChangedEmitter = new Emitter<IConnectionParams>();
|
||||||
|
|
||||||
// ... Create mock connection management service
|
// ... Create mock connection management service and server info
|
||||||
let databaseName = 'foobar';
|
let databaseName = 'foobar';
|
||||||
connectionManagementService.setup(x => x.onConnectionChanged).returns(() => dbChangedEmitter.event);
|
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.getConnectionProfile(TypeMoq.It.isAny())).returns(() => <IConnectionProfile>{ databaseName: databaseName });
|
||||||
connectionManagementService.setup(x => x.changeDatabase(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => Promise.resolve(true));
|
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
|
// ... Create mock connection management service that will not claim it's connected
|
||||||
let databaseName = 'foobar';
|
let databaseName = 'foobar';
|
||||||
connectionManagementService.setup(x => x.onConnectionChanged).returns(() => dbChangedEmitter.event);
|
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.getConnectionProfile(TypeMoq.It.isAny())).returns(() => <IConnectionProfile>{ databaseName: databaseName });
|
||||||
connectionManagementService.setup(x => x.changeDatabase(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => Promise.resolve(true));
|
connectionManagementService.setup(x => x.changeDatabase(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => Promise.resolve(true));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user