Add changes for flavor selection (#8419)

* Add changes for flavor selection

* Use getDefaultProviderId method

* Update default engine user setting description

* Add back check for codeEditor

* Add test for multiple providers

* Removing extra merge line

* Add an attribute to ConnectionProviderProperties for language flavor

Adding a boolean property to ConnectionProviderProperties for providers that are language flavors. When it is set to true, the provider will be part of drop down for changing SQL language flavor.

* Update variable name

* Put logic for removing CMS at one place and remove flag for flavor provider

* Using keys instead of entries

Using Object.keys instead of entries as doing [0] can be error prone if no provider matches.

* Adding logic to check from params

* Updating variable names

* Rename dedup map

* Fix action
This commit is contained in:
swjain23
2019-12-05 15:28:35 -08:00
committed by GitHub
parent 0d9353d99e
commit 0bf4790a64
10 changed files with 133 additions and 40 deletions

View File

@@ -308,10 +308,8 @@ export class ConnectionDialogService implements IConnectionDialogService {
});
}
if (!isProviderInParams) {
this._currentProviderType = find(Object.keys(this._providerNameToDisplayNameMap), (key) =>
this._providerNameToDisplayNameMap[key] === input.selectedProviderDisplayName &&
key !== Constants.cmsProviderName
);
let uniqueProvidersMap = this._connectionManagementService.getUniqueConnectionProvidersByNameMap(this._providerNameToDisplayNameMap);
this._currentProviderType = find(Object.keys(uniqueProvidersMap), (key) => uniqueProvidersMap[key] === input.selectedProviderDisplayName);
}
}
this._model.providerName = this._currentProviderType;

View File

@@ -37,6 +37,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
import { entries } from 'sql/base/common/collections';
export interface OnShowUIResponse {
selectedProviderDisplayName: string;
@@ -116,21 +117,21 @@ export class ConnectionDialogWidget extends Modal {
}
public refresh(): void {
let filteredProviderDisplayNames = this.providerDisplayNameOptions;
let filteredProviderMap = this.providerNameToDisplayNameMap;
if (this._newConnectionParams && this._newConnectionParams.providers) {
const validProviderNames = Object.keys(this.providerNameToDisplayNameMap).filter(x => this.includeProvider(x, this._newConnectionParams));
if (validProviderNames && validProviderNames.length > 0) {
filteredProviderDisplayNames = filteredProviderDisplayNames.filter(x => validProviderNames.some(
v => this.providerNameToDisplayNameMap[v] === x) !== undefined
);
const validProviderMap = entries(this.providerNameToDisplayNameMap).filter(x => this.includeProvider(x[0], this._newConnectionParams));
if (validProviderMap && validProviderMap.length > 0) {
let map: { [providerDisplayName: string]: string } = {};
validProviderMap.forEach(v => {
map[v[0]] = v[1];
});
filteredProviderMap = map;
}
}
this._providerTypeSelectBox.setOptions(filteredProviderDisplayNames.filter((providerDisplayName, index) =>
// Remove duplicate listings (CMS uses the same display name)
filteredProviderDisplayNames.indexOf(providerDisplayName) === index)
);
// Remove duplicate listings (CMS uses the same display name)
let uniqueProvidersMap = this._connectionManagementService.getUniqueConnectionProvidersByNameMap(filteredProviderMap);
this._providerTypeSelectBox.setOptions(Object.keys(uniqueProvidersMap).map(k => uniqueProvidersMap[k]));
}
private includeProvider(providerName: string, params?: INewConnectionParams): Boolean {

View File

@@ -58,6 +58,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
_serviceBrand: undefined;
private _providers = new Map<string, { onReady: Promise<azdata.ConnectionProvider>, properties: ConnectionProviderProperties }>();
private _providerNameToDisplayNameMap: { [providerDisplayName: string]: string } = {};
private _iconProviders = new Map<string, azdata.IconProvider>();
private _uriToProvider: { [uri: string]: string; } = Object.create(null);
private _onAddConnectionProfile = new Emitter<interfaces.IConnectionProfile>();
@@ -107,6 +108,8 @@ export class ConnectionManagementService extends Disposable implements IConnecti
this._mementoObj = this._mementoContext.getMemento(StorageScope.GLOBAL);
}
this.initializeConnectionProvidersMap();
const registry = platform.Registry.as<IConnectionProviderRegistry>(ConnectionProviderExtensions.ConnectionProviderContributions);
let providerRegistration = (p: { id: string, properties: ConnectionProviderProperties }) => {
@@ -126,6 +129,30 @@ export class ConnectionManagementService extends Disposable implements IConnecti
this._register(this._onDeleteConnectionProfile);
}
/**
* Set the initial value for the connection provider map and listen to the provider change event
*/
private initializeConnectionProvidersMap() {
this.updateConnectionProvidersMap();
if (this._capabilitiesService) {
this._capabilitiesService.onCapabilitiesRegistered(() => {
this.updateConnectionProvidersMap();
});
}
}
/**
* Update the map using the values from capabilities service
*/
private updateConnectionProvidersMap() {
if (this._capabilitiesService) {
this._providerNameToDisplayNameMap = {};
entries(this._capabilitiesService.providers).forEach(p => {
this._providerNameToDisplayNameMap[p[0]] = p[1].connection.displayName;
});
}
}
public providerRegistered(providerId: string): boolean {
return !!this._providers.get(providerId);
}
@@ -159,6 +186,10 @@ export class ConnectionManagementService extends Disposable implements IConnecti
return this._onLanguageFlavorChanged.event;
}
public get providerNameToDisplayNameMap(): { readonly [providerDisplayName: string]: string } {
return this._providerNameToDisplayNameMap;
}
// Connection Provider Registration
public registerProvider(providerId: string, provider: azdata.ConnectionProvider): void {
if (!this._providers.has(providerId)) {
@@ -217,6 +248,20 @@ export class ConnectionManagementService extends Disposable implements IConnecti
return providerId;
}
/**
* Get the connection providers map and filter out CMS.
*/
public getUniqueConnectionProvidersByNameMap(providerNameToDisplayNameMap: { [providerDisplayName: string]: string }): { [providerDisplayName: string]: string } {
let uniqueProvidersMap = {};
entries(providerNameToDisplayNameMap).forEach(p => {
if (p[0] !== Constants.cmsProviderName) {
uniqueProvidersMap[p[0]] = p[1];
}
});
return uniqueProvidersMap;
}
/**
* Loads the password and try to connect. If fails, shows the dialog so user can change the connection
* @param Connection Profile
@@ -672,6 +717,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
*/
public doChangeLanguageFlavor(uri: string, language: string, provider: string): void {
if (this._providers.has(provider)) {
this._uriToProvider[uri] = provider;
this._onLanguageFlavorChanged.fire({
uri: uri,
language: language,
@@ -689,9 +735,8 @@ export class ConnectionManagementService extends Disposable implements IConnecti
public ensureDefaultLanguageFlavor(uri: string): void {
if (!this.getProviderIdFromUri(uri)) {
// Lookup the default settings and use this
let defaultProvider = WorkbenchUtils.getSqlConfigValue<string>(this._configurationService, Constants.defaultEngine);
if (defaultProvider && this._providers.has(defaultProvider)) {
// Only set a default if it's in the list of registered providers
let defaultProvider = this.getDefaultProviderId();
if (defaultProvider) {
this.doChangeLanguageFlavor(uri, 'sql', defaultProvider);
}
}
@@ -771,9 +816,6 @@ export class ConnectionManagementService extends Disposable implements IConnecti
options: connection.options
});
// setup URI to provider ID map for connection
this._uriToProvider[uri] = connection.providerName;
return this._providers.get(connection.providerName).onReady.then((provider) => {
provider.connect(uri, connectionInfo);
this._onConnectRequestSent.fire();

View File

@@ -729,6 +729,21 @@ suite('SQL ConnectionManagementService tests', () => {
}
});
test('getUniqueConnectionProvidersByNameMap should return non CMS providers', () => {
let nameToDisplayNameMap: { [providerDisplayName: string]: string } = { 'MSSQL': 'SQL Server', 'MSSQL-CMS': 'SQL Server' };
let providerNames = Object.keys(connectionManagementService.getUniqueConnectionProvidersByNameMap(nameToDisplayNameMap));
assert.equal(providerNames.length, 1);
assert.equal(providerNames[0], 'MSSQL');
});
test('providerNameToDisplayNameMap should return all providers', () => {
let expectedNames = ['MSSQL', 'PGSQL'];
let providerNames = Object.keys(connectionManagementService.providerNameToDisplayNameMap);
assert.equal(providerNames.length, 2);
assert.equal(providerNames[0], expectedNames[0]);
assert.equal(providerNames[1], expectedNames[1]);
});
test('ensureDefaultLanguageFlavor should not send event if uri is connected', done => {
let uri: string = 'Editor Uri';
let options: IConnectionCompletionOptions = {