optional database name option (#17538)

* optional database name option

* object explorer connection title

* revert unexpected change

* bug fixes
This commit is contained in:
Alan Ren
2021-10-29 16:37:35 -07:00
committed by GitHub
parent ce8f1156b1
commit b48f392ab2
5 changed files with 45 additions and 77 deletions

View File

@@ -109,20 +109,6 @@
"categoryValues": null, "categoryValues": null,
"isRequired": true, "isRequired": true,
"isArray": false "isArray": false
},
{
"specialValueType": "databaseName",
"isIdentity": true,
"name": "database",
"displayName": "%azuremonitor.connectionOptions.databaseName.displayName%",
"description": "%azuremonitor.connectionOptions.databaseName.description%",
"groupName": "%azuremonitor.connectionProperties.groupName.source%",
"valueType": "string",
"defaultValue": null,
"objectType": null,
"categoryValues": null,
"isRequired": false,
"isArray": false
} }
] ]
}, },

View File

@@ -160,9 +160,13 @@ export class ProviderConnectionInfo extends Disposable implements azdata.Connect
} }
private getServerInfo() { private getServerInfo() {
let databaseName = this.databaseName ? this.databaseName : '<default>'; let title = this.serverName;
let userName = this.userName ? this.userName : 'Windows Authentication'; // Only show database name if the provider supports it.
return this.serverName + ', ' + databaseName + ' (' + userName + ')'; if (this.serverCapabilities?.connectionOptions?.find(option => option.specialValueType === ConnectionOptionSpecialType.databaseName)) {
title += `, ${this.databaseName || '<default>'}`;
}
title += ` (${this.userName || this.authenticationType})`;
return title;
} }
/** /**

View File

@@ -229,11 +229,11 @@ export abstract class QueryEditorInput extends EditorInput implements IConnectab
title = this._description + ' '; title = this._description + ' ';
} }
if (profile) { if (profile) {
if (profile.userName) { title += `${profile.serverName}`;
title += `${profile.serverName}.${profile.databaseName} (${profile.userName})`; if (profile.databaseName) {
} else { title += `.${profile.databaseName}`;
title += `${profile.serverName}.${profile.databaseName} (${profile.authenticationType})`;
} }
title += ` (${profile.userName || profile.authenticationType})`;
} else { } else {
title += localize('disconnected', "disconnected"); title += localize('disconnected', "disconnected");
} }

View File

@@ -791,6 +791,11 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt
} }
private updateConnection(databaseName: string): void { private updateConnection(databaseName: string): void {
// Ignore if the database name is not provided, this happens when the query editor connection is changed to
// a provider that does not support database.
if (!databaseName) {
return;
}
this._isConnected = true; this._isConnected = true;
this._currentDatabaseName = databaseName; this._currentDatabaseName = databaseName;
// Set the value immediately to the initial database so the user can see that, and then // Set the value immediately to the initial database so the user can see that, and then

View File

@@ -42,6 +42,8 @@ import { IRange } from 'vs/editor/common/core/range';
import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput';
import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { IEditorOptions } from 'vs/platform/editor/common/editor'; import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { ConnectionOptionSpecialType } from 'sql/platform/connection/common/interfaces';
const QUERY_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'queryEditorViewState'; const QUERY_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'queryEditorViewState';
@@ -107,6 +109,7 @@ export class QueryEditor extends EditorPane {
@IInstantiationService private readonly instantiationService: IInstantiationService, @IInstantiationService private readonly instantiationService: IInstantiationService,
@IConfigurationService private readonly configurationService: IConfigurationService, @IConfigurationService private readonly configurationService: IConfigurationService,
@IModeService private readonly modeService: IModeService, @IModeService private readonly modeService: IModeService,
@ICapabilitiesService private readonly capabilitiesService: ICapabilitiesService
) { ) {
super(QueryEditor.ID, telemetryService, themeService, storageService); super(QueryEditor.ID, telemetryService, themeService, storageService);
@@ -266,73 +269,43 @@ export class QueryEditor extends EditorPane {
} }
private setTaskbarContent(): void { private setTaskbarContent(): void {
// Create HTML Elements for the taskbar
const separator = Taskbar.createTaskbarSeparator();
let content: ITaskbarContent[];
const previewFeaturesEnabled = this.configurationService.getValue('workbench')['enablePreviewFeatures']; const previewFeaturesEnabled = this.configurationService.getValue('workbench')['enablePreviewFeatures'];
let connectionProfile = this.connectionManagementService.getConnectionProfile(this.input?.uri); const connectionProfile = this.connectionManagementService.getConnectionProfile(this.input?.uri);
let fileExtension = path.extname(this.input?.uri || ''); const fileExtension = path.extname(this.input?.uri || '');
const providerId = connectionProfile?.providerName || const providerId = connectionProfile?.providerName ||
this.connectionManagementService.getProviderIdFromUri(this.input?.uri) || this.connectionManagementService.getProviderIdFromUri(this.input?.uri) ||
this.connectionManagementService.getDefaultProviderId(); this.connectionManagementService.getDefaultProviderId();
// TODO: Make it more generic, some way for extensions to register the commands it supports const content: ITaskbarContent[] = [
if ((providerId === 'KUSTO') || this.modeService.getExtensions('Kusto').indexOf(fileExtension) > -1) { { action: this._runQueryAction },
if (this.input instanceof UntitledQueryEditorInput) { // Sets proper language mode for untitled query editor based on the connection selected by user. { action: this._cancelQueryAction },
{ element: Taskbar.createTaskbarSeparator() },
{ action: this._toggleConnectDatabaseAction },
{ action: this._changeConnectionAction }
];
// TODO: Allow query provider to provide the language mode.
if (this.input instanceof UntitledQueryEditorInput) {
if ((providerId === 'KUSTO') || this.modeService.getExtensions('Kusto').indexOf(fileExtension) > -1) {
this.input.setMode('kusto'); this.input.setMode('kusto');
} }
else if (providerId === 'LOGANALYTICS' || this.modeService.getExtensions('LogAnalytics').indexOf(fileExtension) > -1) {
content = [
{ action: this._runQueryAction },
{ action: this._cancelQueryAction },
{ element: separator },
{ action: this._toggleConnectDatabaseAction },
{ action: this._changeConnectionAction },
{ action: this._listDatabasesAction }
];
}
else if (providerId === 'LOGANALYTICS' || this.modeService.getExtensions('LogAnalytics').indexOf(fileExtension) > -1) {
if (this.input instanceof UntitledQueryEditorInput) {
this.input.setMode('loganalytics'); this.input.setMode('loganalytics');
} }
content = [
{ action: this._runQueryAction },
{ action: this._cancelQueryAction },
{ element: separator },
{ action: this._toggleConnectDatabaseAction },
{ action: this._changeConnectionAction },
{ action: this._listDatabasesAction }
];
} }
else {
if (previewFeaturesEnabled) {
content = [
{ action: this._runQueryAction },
{ action: this._cancelQueryAction },
{ element: separator },
{ action: this._toggleConnectDatabaseAction },
{ action: this._changeConnectionAction },
{ action: this._listDatabasesAction },
];
if (providerId === 'MSSQL') { // Only show the databases dropdown if the connection provider supports it.
content.push({ element: separator }, if (this.capabilitiesService.getCapabilities(providerId).connection?.connectionOptions?.find(option => option.specialValueType === ConnectionOptionSpecialType.databaseName)) {
{ action: this._estimatedQueryPlanAction }, content.push({ action: this._listDatabasesAction });
{ action: this._toggleSqlcmdMode } }
);
content.push({ action: this._exportAsNotebookAction }); // TODO: Allow extensions to contribute toolbar actions.
} if (previewFeaturesEnabled && providerId === 'MSSQL') {
} else { content.push(
content = [ { element: Taskbar.createTaskbarSeparator() },
{ action: this._runQueryAction }, { action: this._estimatedQueryPlanAction },
{ action: this._cancelQueryAction }, { action: this._toggleSqlcmdMode },
{ element: separator }, { action: this._exportAsNotebookAction }
{ action: this._toggleConnectDatabaseAction }, );
{ action: this._changeConnectionAction },
{ action: this._listDatabasesAction }
];
}
} }
this.taskbar.setContent(content); this.taskbar.setContent(content);