add sorting option for saved connections (#15229)

* add sort by name option for saved connections and groups
This commit is contained in:
Hai Cao
2021-04-28 11:41:09 -07:00
committed by GitHub
parent 13ab2bc487
commit 9bc1797e88
5 changed files with 128 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/co
import { DataExplorerContainerExtensionHandler } from 'sql/workbench/contrib/dataExplorer/browser/dataExplorerExtensionPoint';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { DataExplorerViewletViewsContribution } from 'sql/workbench/contrib/dataExplorer/browser/dataExplorerViewlet';
import { GROUPS_CONFIG_KEY, CONNECTIONS_CONFIG_KEY, CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortBy } from 'sql/platform/connection/common/connectionConfig';
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(DataExplorerViewletViewsContribution, LifecyclePhase.Starting);
@@ -22,13 +23,23 @@ configurationRegistry.registerConfiguration({
'title': localize('databaseConnections', "Database Connections"),
'type': 'object',
'properties': {
'datasource.connections': {
[CONNECTIONS_CONFIG_KEY]: {
'description': localize('datasource.connections', "data source connections"),
'type': 'array'
},
'datasource.connectionGroups': {
[GROUPS_CONFIG_KEY]: {
'description': localize('datasource.connectionGroups', "data source groups"),
'type': 'array'
},
[CONNECTIONS_SORT_BY_CONFIG_KEY]: {
'type': 'string',
'enum': [ConnectionsSortBy.dateAdded, ConnectionsSortBy.displayName],
'enumDescriptions': [
localize('connections.sortBy.dateAdded', 'Saved connections are sorted by the dates they were added.'),
localize('connections.sortBy.displayName', 'Saved connections are sorted by their display names alphabetically.')
],
'default': ConnectionsSortBy.dateAdded,
'description': localize('datasource.connections.sortBy', "Order used for sorting saved connections and connection groups")
}
}
});

View File

@@ -41,6 +41,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { AsyncServerTree, ServerTreeElement } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
import { coalesce } from 'vs/base/common/arrays';
import { CONNECTIONS_SORT_BY_CONFIG_KEY } from 'sql/platform/connection/common/connectionConfig';
/**
* ServerTreeview implements the dynamic tree view.
@@ -196,6 +197,11 @@ export class ServerTreeView extends Disposable implements IServerTreeView {
this.deleteObjectExplorerNodeAndRefreshTree(connectionParams.connectionProfile).catch(errors.onUnexpectedError);
}
}));
this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(CONNECTIONS_SORT_BY_CONFIG_KEY)) {
this.refreshTree().catch(err => errors.onUnexpectedError);
}
}));
if (this._objectExplorerService && this._objectExplorerService.onUpdateObjectExplorerNodes) {
this._register(this._objectExplorerService.onUpdateObjectExplorerNodes(args => {

View File

@@ -12,6 +12,7 @@ import { ConnectionProfile } from 'sql/platform/connection/common/connectionProf
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import { attachInputBoxStyler } from 'sql/platform/theme/common/styler';
import { ITreeItem } from 'sql/workbench/common/views';
import { CONNECTIONS_SORT_BY_CONFIG_KEY } from 'sql/platform/connection/common/connectionConfig';
import { IConnectionTreeDescriptor, IConnectionTreeService } from 'sql/workbench/services/connection/common/connectionTreeService';
import { AsyncRecentConnectionTreeDataSource } from 'sql/workbench/services/objectExplorer/browser/asyncRecentConnectionTreeDataSource';
import { ServerTreeElement } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
@@ -91,7 +92,8 @@ export class ConnectionBrowserView extends Disposable implements IPanelView {
@ICommandService private readonly commandService: ICommandService,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
@IConnectionManagementService private readonly connectionManagementService: IConnectionManagementService,
@ICapabilitiesService private readonly capabilitiesService: ICapabilitiesService
@ICapabilitiesService private readonly capabilitiesService: ICapabilitiesService,
@IConfigurationService private readonly configurationService: IConfigurationService,
) {
super();
this.connectionTreeService.setView(this);
@@ -224,6 +226,13 @@ export class ConnectionBrowserView extends Disposable implements IPanelView {
this._register(this.themeService.onDidColorThemeChange(async () => {
await this.refresh();
}));
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(CONNECTIONS_SORT_BY_CONFIG_KEY)) {
this.updateSavedConnectionsNode();
}
}));
}
private handleTreeElementSelection(selectedNode: TreeElement, connect: boolean): void {