From 5caf0b02f0b2d926a9fe3d1d4bd02aa953f26895 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Fri, 15 Mar 2019 14:47:23 -0700 Subject: [PATCH] make connectiondialog react to provider event (#4544) * make connectiondialog react to provider event * fix unit test error * code review comments --- .../browser/connectionDialogService.ts | 40 +++++++++++++++---- .../browser/connectionDialogWidget.ts | 11 +++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/sql/workbench/services/connection/browser/connectionDialogService.ts b/src/sql/workbench/services/connection/browser/connectionDialogService.ts index 21a21998cd..bc5ff6d179 100644 --- a/src/sql/workbench/services/connection/browser/connectionDialogService.ts +++ b/src/sql/workbench/services/connection/browser/connectionDialogService.ts @@ -89,7 +89,38 @@ export class ConnectionDialogService implements IConnectionDialogService { @IWorkspaceConfigurationService private _workspaceConfigurationService: IWorkspaceConfigurationService, @IClipboardService private _clipboardService: IClipboardService, @ICommandService private _commandService: ICommandService - ) { } + ) { + this.initializeConnectionProviders(); + } + + /** + * Set the initial value for the connection provider and listen to the provider change event + */ + private initializeConnectionProviders() { + this.setConnectionProviders(); + if (this._capabilitiesService) { + this._capabilitiesService.onCapabilitiesRegistered(() => { + this.setConnectionProviders(); + if (this._connectionDialog) { + this._connectionDialog.updateConnectionProviders(this._providerTypes, this._providerNameToDisplayNameMap); + } + }); + } + } + + /** + * Update the available provider types using the values from capabilities service + */ + private setConnectionProviders() { + if (this._capabilitiesService) { + this._providerTypes = []; + this._providerNameToDisplayNameMap = {}; + entries(this._capabilitiesService.providers).forEach(p => { + this._providerTypes.push(p[1].connection.displayName); + this._providerNameToDisplayNameMap[p[0]] = p[1].connection.displayName; + }); + } + } /** * Gets the default provider with the following actions @@ -350,13 +381,6 @@ export class ConnectionDialogService implements IConnectionDialogService { this._inputModel = model; return new Promise((resolve, reject) => { - // only create the provider maps first time the dialog gets called - if (this._providerTypes.length === 0) { - entries(this._capabilitiesService.providers).forEach(p => { - this._providerTypes.push(p[1].connection.displayName); - this._providerNameToDisplayNameMap[p[0]] = p[1].connection.displayName; - }); - } this.updateModelServerCapabilities(model); // If connecting from a query editor set "save connection" to false if (params && params.input && params.connectionType === ConnectionType.editor) { diff --git a/src/sql/workbench/services/connection/browser/connectionDialogWidget.ts b/src/sql/workbench/services/connection/browser/connectionDialogWidget.ts index 20ea89d06c..49ecda8818 100644 --- a/src/sql/workbench/services/connection/browser/connectionDialogWidget.ts +++ b/src/sql/workbench/services/connection/browser/connectionDialogWidget.ts @@ -102,6 +102,17 @@ export class ConnectionDialogWidget extends Modal { super(localize('connection', 'Connection'), TelemetryKeys.Connection, _partService, telemetryService, clipboardService, _workbenchThemeService, contextKeyService, { hasSpinner: true, hasErrors: true }); } + /** + * 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 + */ + public updateConnectionProviders(providerTypeOptions: string[], + providerNameToDisplayNameMap: { [providerDisplayName: string]: string }) { + this.providerTypeOptions = providerTypeOptions; + this.providerNameToDisplayNameMap = providerNameToDisplayNameMap; + this.refresh(); + } + public refresh(): void { let filteredProviderTypes = this.providerTypeOptions;