Connection dialog cleanup (#6076)

* Update names to be clearer and remove some unnecessary code

* Remove unused/inaccurate CMS display name value
This commit is contained in:
Charles Gagnon
2019-06-18 21:33:21 +00:00
committed by GitHub
parent 561b7575ba
commit 9e7282d16a
3 changed files with 25 additions and 26 deletions

View File

@@ -29,6 +29,5 @@ export const azureMFA = 'AzureMFA';
/* CMS constants */ /* CMS constants */
export const cmsProviderName = 'MSSQL-CMS'; export const cmsProviderName = 'MSSQL-CMS';
export const cmsProviderDisplayName = localize('constants.cmsProviderDisplayName', 'Microsoft SQL Server - CMS');
export const UNSAVED_GROUP_ID = 'unsaved'; export const UNSAVED_GROUP_ID = 'unsaved';

View File

@@ -67,7 +67,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
private _options: IConnectionCompletionOptions; private _options: IConnectionCompletionOptions;
private _inputModel: IConnectionProfile; private _inputModel: IConnectionProfile;
private _providerNameToDisplayNameMap: { [providerDisplayName: string]: string } = {}; private _providerNameToDisplayNameMap: { [providerDisplayName: string]: string } = {};
private _providerTypes: string[] = []; private _providerDisplayNames: string[] = [];
private _currentProviderType: string = Constants.mssqlProviderName; private _currentProviderType: string = Constants.mssqlProviderName;
private _connecting: boolean = false; private _connecting: boolean = false;
private _connectionErrorTitle = localize('connectionError', 'Connection error'); private _connectionErrorTitle = localize('connectionError', 'Connection error');
@@ -100,7 +100,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
this._capabilitiesService.onCapabilitiesRegistered(() => { this._capabilitiesService.onCapabilitiesRegistered(() => {
this.setConnectionProviders(); this.setConnectionProviders();
if (this._connectionDialog) { if (this._connectionDialog) {
this._connectionDialog.updateConnectionProviders(this._providerTypes, this._providerNameToDisplayNameMap); this._connectionDialog.updateConnectionProviders(this._providerDisplayNames, this._providerNameToDisplayNameMap);
} }
}); });
} }
@@ -111,10 +111,10 @@ export class ConnectionDialogService implements IConnectionDialogService {
*/ */
private setConnectionProviders() { private setConnectionProviders() {
if (this._capabilitiesService) { if (this._capabilitiesService) {
this._providerTypes = []; this._providerDisplayNames = [];
this._providerNameToDisplayNameMap = {}; this._providerNameToDisplayNameMap = {};
entries(this._capabilitiesService.providers).forEach(p => { entries(this._capabilitiesService.providers).forEach(p => {
this._providerTypes.push(p[1].connection.displayName); this._providerDisplayNames.push(p[1].connection.displayName);
this._providerNameToDisplayNameMap[p[0]] = p[1].connection.displayName; this._providerNameToDisplayNameMap[p[0]] = p[1].connection.displayName;
}); });
} }
@@ -297,12 +297,12 @@ export class ConnectionDialogService implements IConnectionDialogService {
} }
private handleShowUiComponent(input: OnShowUIResponse) { private handleShowUiComponent(input: OnShowUIResponse) {
if (input.selectedProviderType) { if (input.selectedProviderDisplayName) {
// If the call is for specific providers // If the call is for specific providers
let isProviderInParams: boolean = false; let isProviderInParams: boolean = false;
if (this._params && this._params.providers) { if (this._params && this._params.providers) {
this._params.providers.forEach((provider) => { this._params.providers.forEach((provider) => {
if (input.selectedProviderType === this._providerNameToDisplayNameMap[provider]) { if (input.selectedProviderDisplayName === this._providerNameToDisplayNameMap[provider]) {
isProviderInParams = true; isProviderInParams = true;
this._currentProviderType = provider; this._currentProviderType = provider;
} }
@@ -310,7 +310,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
} }
if (!isProviderInParams) { if (!isProviderInParams) {
this._currentProviderType = Object.keys(this._providerNameToDisplayNameMap).find((key) => this._currentProviderType = Object.keys(this._providerNameToDisplayNameMap).find((key) =>
this._providerNameToDisplayNameMap[key] === input.selectedProviderType && this._providerNameToDisplayNameMap[key] === input.selectedProviderDisplayName &&
key !== Constants.cmsProviderName key !== Constants.cmsProviderName
); );
} }
@@ -429,7 +429,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
private doShowDialog(params: INewConnectionParams): Promise<void> { private doShowDialog(params: INewConnectionParams): Promise<void> {
if (!this._connectionDialog) { if (!this._connectionDialog) {
this._connectionDialog = this._instantiationService.createInstance(ConnectionDialogWidget, this._providerTypes, this._providerNameToDisplayNameMap[this._model.providerName], this._providerNameToDisplayNameMap); this._connectionDialog = this._instantiationService.createInstance(ConnectionDialogWidget, this._providerDisplayNames, this._providerNameToDisplayNameMap[this._model.providerName], this._providerNameToDisplayNameMap);
this._connectionDialog.onCancel(() => { this._connectionDialog.onCancel(() => {
this._connectionDialog.databaseDropdownExpanded = this.uiController.databaseDropdownExpanded; this._connectionDialog.databaseDropdownExpanded = this.uiController.databaseDropdownExpanded;
this.handleOnCancel(this._connectionDialog.newConnectionParams); this.handleOnCancel(this._connectionDialog.newConnectionParams);

View File

@@ -39,7 +39,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService'; import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
export interface OnShowUIResponse { export interface OnShowUIResponse {
selectedProviderType: string; selectedProviderDisplayName: string;
container: HTMLElement; container: HTMLElement;
} }
@@ -85,7 +85,7 @@ export class ConnectionDialogWidget extends Modal {
private _connecting = false; private _connecting = false;
constructor( constructor(
private providerTypeOptions: string[], private providerDisplayNameOptions: string[],
private selectedProviderType: string, private selectedProviderType: string,
private providerNameToDisplayNameMap: { [providerDisplayName: string]: string }, private providerNameToDisplayNameMap: { [providerDisplayName: string]: string },
@IInstantiationService private _instantiationService: IInstantiationService, @IInstantiationService private _instantiationService: IInstantiationService,
@@ -106,29 +106,29 @@ export class ConnectionDialogWidget extends Modal {
* Update the available connection providers, this is called when new providers are registered * Update the available connection providers, this is called when new providers are registered
* So that the connection type dropdown always has up to date values * So that the connection type dropdown always has up to date values
*/ */
public updateConnectionProviders(providerTypeOptions: string[], public updateConnectionProviders(
providerTypeDisplayNameOptions: string[],
providerNameToDisplayNameMap: { [providerDisplayName: string]: string }) { providerNameToDisplayNameMap: { [providerDisplayName: string]: string }) {
this.providerTypeOptions = providerTypeOptions; this.providerDisplayNameOptions = providerTypeDisplayNameOptions;
this.providerNameToDisplayNameMap = providerNameToDisplayNameMap; this.providerNameToDisplayNameMap = providerNameToDisplayNameMap;
this.refresh(); this.refresh();
} }
public refresh(): void { public refresh(): void {
let filteredProviderTypes = this.providerTypeOptions; let filteredProviderDisplayNames = this.providerDisplayNameOptions;
if (this._newConnectionParams && this._newConnectionParams.providers) { if (this._newConnectionParams && this._newConnectionParams.providers) {
const validProviderNames = Object.keys(this.providerNameToDisplayNameMap).filter(x => this.includeProvider(x, this._newConnectionParams)); const validProviderNames = Object.keys(this.providerNameToDisplayNameMap).filter(x => this.includeProvider(x, this._newConnectionParams));
if (validProviderNames && validProviderNames.length > 0) { if (validProviderNames && validProviderNames.length > 0) {
filteredProviderTypes = filteredProviderTypes.filter(x => validProviderNames.find( filteredProviderDisplayNames = filteredProviderDisplayNames.filter(x => validProviderNames.find(
v => this.providerNameToDisplayNameMap[v] === x) !== undefined v => this.providerNameToDisplayNameMap[v] === x) !== undefined
); );
} }
} else {
filteredProviderTypes = filteredProviderTypes.filter(x => x !== Constants.cmsProviderName);
} }
this._providerTypeSelectBox.setOptions(filteredProviderTypes.filter((providerType, index) =>
// Remove duplicate listings this._providerTypeSelectBox.setOptions(filteredProviderDisplayNames.filter((providerDisplayName, index) =>
filteredProviderTypes.indexOf(providerType) === index) // Remove duplicate listings (CMS uses the same display name)
filteredProviderDisplayNames.indexOf(providerDisplayName) === index)
); );
} }
@@ -140,7 +140,7 @@ export class ConnectionDialogWidget extends Modal {
this._body = DOM.append(container, DOM.$('.connection-dialog')); this._body = DOM.append(container, DOM.$('.connection-dialog'));
const connectTypeLabel = localize('connectType', "Connection type"); const connectTypeLabel = localize('connectType', "Connection type");
this._providerTypeSelectBox = new SelectBox(this.providerTypeOptions, this.selectedProviderType, this._contextViewService, undefined, { ariaLabel: connectTypeLabel }); this._providerTypeSelectBox = new SelectBox(this.providerDisplayNameOptions, this.selectedProviderType, this._contextViewService, undefined, { ariaLabel: connectTypeLabel });
// Recent connection tab // Recent connection tab
const recentConnectionTab = DOM.$('.connection-recent-tab'); const recentConnectionTab = DOM.$('.connection-recent-tab');
const recentConnectionContainer = DOM.append(recentConnectionTab, DOM.$('.connection-recent', { id: 'recentConnection' })); const recentConnectionContainer = DOM.append(recentConnectionTab, DOM.$('.connection-recent', { id: 'recentConnection' }));
@@ -259,10 +259,10 @@ export class ConnectionDialogWidget extends Modal {
})); }));
} }
private onProviderTypeSelected(selectedProviderType: string) { private onProviderTypeSelected(selectedProviderDisplayName: string) {
// Show connection form based on server type // Show connection form based on server type
DOM.clearNode(this._connectionUIContainer); DOM.clearNode(this._connectionUIContainer);
this._onShowUiComponent.fire({ selectedProviderType: selectedProviderType, container: this._connectionUIContainer }); this._onShowUiComponent.fire({ selectedProviderDisplayName: selectedProviderDisplayName, container: this._connectionUIContainer });
this.initDialog(); this.initDialog();
} }
@@ -445,10 +445,10 @@ export class ConnectionDialogWidget extends Modal {
this.refresh(); this.refresh();
} }
public updateProvider(displayName: string) { public updateProvider(providerDisplayName: string) {
this._providerTypeSelectBox.selectWithOptionName(displayName); this._providerTypeSelectBox.selectWithOptionName(providerDisplayName);
this.onProviderTypeSelected(displayName); this.onProviderTypeSelected(providerDisplayName);
} }
public dispose(): void { public dispose(): void {