make connectiondialog react to provider event (#4544)

* make connectiondialog react to provider event

* fix unit test error

* code review comments
This commit is contained in:
Alan Ren
2019-03-15 14:47:23 -07:00
committed by GitHub
parent 86bac90001
commit 5caf0b02f0
2 changed files with 43 additions and 8 deletions

View File

@@ -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<void>((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) {

View File

@@ -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;