only show new query when query is supported (#17346)

* only show new query when query is supported

* test case fix and pr comments

* rename context key
This commit is contained in:
Alan Ren
2021-10-13 13:01:31 -07:00
committed by GitHub
parent 547ceba501
commit 156f8f1d5f
13 changed files with 66 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ import 'vs/css!./media/connectionDialog';
import { Button } from 'sql/base/browser/ui/button/button';
import { SelectBox } from 'sql/base/browser/ui/selectBox/selectBox';
import { HideReason, Modal } from 'sql/workbench/browser/modal/modal';
import { IConnectionManagementService, INewConnectionParams } from 'sql/platform/connection/common/connectionManagement';
import { ConnectionType, IConnectionManagementService, INewConnectionParams } from 'sql/platform/connection/common/connectionManagement';
import * as DialogHelper from 'sql/workbench/browser/modal/dialogHelper';
import { TreeCreationUtils } from 'sql/workbench/services/objectExplorer/browser/treeCreationUtils';
import { TabbedPanel, PanelTabIdentifier } from 'sql/base/browser/ui/panel/panel';
@@ -43,6 +43,7 @@ import { AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/a
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ConnectionBrowseTab } from 'sql/workbench/services/connection/browser/connectionBrowseTab';
import { ElementSizeObserver } from 'vs/editor/browser/config/elementSizeObserver';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
export interface OnShowUIResponse {
selectedProviderDisplayName: string;
@@ -122,7 +123,8 @@ export class ConnectionDialogWidget extends Modal {
@IClipboardService clipboardService: IClipboardService,
@ILogService logService: ILogService,
@ITextResourcePropertiesService textResourcePropertiesService: ITextResourcePropertiesService,
@IConfigurationService private _configurationService: IConfigurationService
@IConfigurationService private _configurationService: IConfigurationService,
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService
) {
super(
localize('connection', "Connection"),
@@ -155,8 +157,20 @@ export class ConnectionDialogWidget extends Modal {
public refresh(): void {
let filteredProviderMap = this.providerNameToDisplayNameMap;
if (this._newConnectionParams && this._newConnectionParams.providers) {
const validProviderMap = entries(this.providerNameToDisplayNameMap).filter(x => this.includeProvider(x[0], this._newConnectionParams));
if (this._newConnectionParams && (this._newConnectionParams.providers || this._newConnectionParams.connectionType === ConnectionType.editor)) {
const validProviderMap = entries(this.providerNameToDisplayNameMap).filter(x => {
const providerName = x[0];
const capabilities = this._capabilitiesService.getCapabilities(providerName).connection;
// If the connection is for an editor (e.g. query editor or notebook), the provider must be a query provider
if (this._newConnectionParams.connectionType === ConnectionType.editor && !capabilities.isQueryProvider) {
return false;
}
// If the provider list is provided, the provider must be in the list.
if (this._newConnectionParams.providers && !this._newConnectionParams.providers.some(p => p === providerName)) {
return false;
}
return true;
});
if (validProviderMap && validProviderMap.length > 0) {
let map: { [providerDisplayName: string]: string } = {};
validProviderMap.forEach(v => {
@@ -171,10 +185,6 @@ export class ConnectionDialogWidget extends Modal {
this._providerTypeSelectBox.setOptions(Object.keys(uniqueProvidersMap).map(k => uniqueProvidersMap[k]));
}
private includeProvider(providerName: string, params?: INewConnectionParams): Boolean {
return params === undefined || params.providers === undefined || params.providers.some(x => x === providerName);
}
protected renderBody(container: HTMLElement): void {
this._body = DOM.append(container, DOM.$('.connection-dialog'));