From a0bf5df79d53ed7b4b3bf62957fa15e1f89fe36e Mon Sep 17 00:00:00 2001 From: Hai Cao Date: Thu, 29 Apr 2021 10:52:35 -0700 Subject: [PATCH] Use a different config name for connection sorting (#15275) * use a different sort config name --- .../connection/common/connectionConfig.ts | 8 ++++---- .../test/common/connectionConfig.test.ts | 18 +++++++++--------- .../browser/dataExplorer.contribution.ts | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/sql/platform/connection/common/connectionConfig.ts b/src/sql/platform/connection/common/connectionConfig.ts index b566915643..8ebe84889f 100644 --- a/src/sql/platform/connection/common/connectionConfig.ts +++ b/src/sql/platform/connection/common/connectionConfig.ts @@ -16,9 +16,9 @@ import { deepClone } from 'vs/base/common/objects'; export const GROUPS_CONFIG_KEY = 'datasource.connectionGroups'; export const CONNECTIONS_CONFIG_KEY = 'datasource.connections'; -export const CONNECTIONS_SORT_BY_CONFIG_KEY = 'datasource.connections.sortBy'; +export const CONNECTIONS_SORT_BY_CONFIG_KEY = 'datasource.connectionsSortOrder'; -export const enum ConnectionsSortBy { +export const enum ConnectionsSortOrder { dateAdded = 'dateAdded', displayName = 'displayName' } @@ -59,7 +59,7 @@ export class ConnectionConfig { const sortBy = this.configurationService.getValue(CONNECTIONS_SORT_BY_CONFIG_KEY); let sortFunc: (a: IConnectionProfileGroup, b: IConnectionProfileGroup) => number; - if (sortBy === ConnectionsSortBy.displayName) { + if (sortBy === ConnectionsSortOrder.displayName) { sortFunc = ((a, b) => { if (a.name < b.name) { return -1; @@ -243,7 +243,7 @@ export class ConnectionConfig { const sortBy = this.configurationService.getValue(CONNECTIONS_SORT_BY_CONFIG_KEY); let sortFunc: (a: ConnectionProfile, b: ConnectionProfile) => number; - if (sortBy === ConnectionsSortBy.displayName) { + if (sortBy === ConnectionsSortOrder.displayName) { sortFunc = ((a, b) => { if (a.title < b.title) { return -1; diff --git a/src/sql/platform/connection/test/common/connectionConfig.test.ts b/src/sql/platform/connection/test/common/connectionConfig.test.ts index c0af0381b5..fe3b26576c 100644 --- a/src/sql/platform/connection/test/common/connectionConfig.test.ts +++ b/src/sql/platform/connection/test/common/connectionConfig.test.ts @@ -6,7 +6,7 @@ import * as assert from 'assert'; import * as azdata from 'azdata'; import { ProviderFeatures } from 'sql/platform/capabilities/common/capabilitiesService'; -import { ConnectionConfig, ISaveGroupResult, CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortBy } from 'sql/platform/connection/common/connectionConfig'; +import { ConnectionConfig, ISaveGroupResult, CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortOrder } from 'sql/platform/connection/common/connectionConfig'; import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile'; import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup'; import { IConnectionProfile, IConnectionProfileStore, ConnectionOptionSpecialType, ServiceOptionType } from 'sql/platform/connection/common/interfaces'; @@ -239,11 +239,11 @@ suite('ConnectionConfig', () => { assert.ok(groupsAreEqual(allGroups, testGroups), 'the groups returned did not match expectation'); }); - test('getAllGroups should return groups sorted alphabetically by display name given datasource.connections.sortBy is set to \'' + ConnectionsSortBy.displayName + '\'', () => { + test('getAllGroups should return groups sorted alphabetically by display name given datasource.connectionsSortOrder is set to \'' + ConnectionsSortOrder.displayName + '\'', () => { let configurationService = new TestConfigurationService(); configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups).slice(0, 3), ConfigurationTarget.USER); configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups).slice(2, testGroups.length), ConfigurationTarget.WORKSPACE); - configurationService.updateValue(CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortBy.displayName, ConfigurationTarget.USER); + configurationService.updateValue(CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortOrder.displayName, ConfigurationTarget.USER); let config = new ConnectionConfig(configurationService, capabilitiesService.object); let allGroups = config.getAllGroups(); @@ -253,11 +253,11 @@ suite('ConnectionConfig', () => { assert.ok(allGroups.slice(1).every((item, i) => allGroups[i].name <= item.name), 'the groups are not sorted correctly'); }); - test('getAllGroups should return groups sorted by date added given datasource.connections.sortBy is set to \'' + ConnectionsSortBy.dateAdded + '\'', () => { + test('getAllGroups should return groups sorted by date added given datasource.connectionsSortOrder is set to \'' + ConnectionsSortOrder.dateAdded + '\'', () => { let configurationService = new TestConfigurationService(); configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups).slice(0, 3).reverse(), ConfigurationTarget.USER); configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups).slice(2, testGroups.length).reverse(), ConfigurationTarget.WORKSPACE); - configurationService.updateValue(CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortBy.dateAdded, ConfigurationTarget.USER); + configurationService.updateValue(CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortOrder.dateAdded, ConfigurationTarget.USER); let config = new ConnectionConfig(configurationService, capabilitiesService.object); let allGroups = config.getAllGroups(); @@ -411,11 +411,11 @@ suite('ConnectionConfig', () => { }); }); - test('getConnections should return connections sorted alphabetically by title given datasource.connections.sortBy is set to \'' + ConnectionsSortBy.displayName + '\'', () => { + test('getConnections should return connections sorted alphabetically by title given datasource.connectionsSortOrder is set to \'' + ConnectionsSortOrder.displayName + '\'', () => { let configurationService = new TestConfigurationService(); configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(0, 2).reverse(), ConfigurationTarget.USER); configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(2, testConnections.length).reverse(), ConfigurationTarget.WORKSPACE); - configurationService.updateValue(CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortBy.displayName, ConfigurationTarget.USER); + configurationService.updateValue(CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortOrder.displayName, ConfigurationTarget.USER); let config = new ConnectionConfig(configurationService, capabilitiesService.object); let allConnections = config.getConnections(true); @@ -423,10 +423,10 @@ suite('ConnectionConfig', () => { assert.ok(allConnections.slice(1).every((item, i) => allConnections[i].title <= item.title), 'The connections are not sorted correctly'); }); - test('getConnections should return connections sorted by date added given datasource.connections.sortBy is set to \'' + ConnectionsSortBy.dateAdded + '\'', () => { + test('getConnections should return connections sorted by date added given datasource.connectionsSortOrder is set to \'' + ConnectionsSortOrder.dateAdded + '\'', () => { let configurationService = new TestConfigurationService(); configurationService.updateValue('datasource.connections', deepClone(testConnections).reverse(), ConfigurationTarget.USER); - configurationService.updateValue(CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortBy.dateAdded, ConfigurationTarget.USER); + configurationService.updateValue(CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortOrder.dateAdded, ConfigurationTarget.USER); let config = new ConnectionConfig(configurationService, capabilitiesService.object); let allConnections = config.getConnections(false); diff --git a/src/sql/workbench/contrib/dataExplorer/browser/dataExplorer.contribution.ts b/src/sql/workbench/contrib/dataExplorer/browser/dataExplorer.contribution.ts index 1067626b5d..658fa00859 100644 --- a/src/sql/workbench/contrib/dataExplorer/browser/dataExplorer.contribution.ts +++ b/src/sql/workbench/contrib/dataExplorer/browser/dataExplorer.contribution.ts @@ -11,7 +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'; +import { GROUPS_CONFIG_KEY, CONNECTIONS_CONFIG_KEY, CONNECTIONS_SORT_BY_CONFIG_KEY, ConnectionsSortOrder } from 'sql/platform/connection/common/connectionConfig'; const workbenchRegistry = Registry.as(WorkbenchExtensions.Workbench); workbenchRegistry.registerWorkbenchContribution(DataExplorerViewletViewsContribution, LifecyclePhase.Starting); @@ -33,13 +33,13 @@ configurationRegistry.registerConfiguration({ }, [CONNECTIONS_SORT_BY_CONFIG_KEY]: { 'type': 'string', - 'enum': [ConnectionsSortBy.dateAdded, ConnectionsSortBy.displayName], + 'enum': [ConnectionsSortOrder.dateAdded, ConnectionsSortOrder.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.') + localize('connectionsSortOrder.dateAdded', 'Saved connections are sorted by the dates they were added.'), + localize('connectionsSortOrder.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") + 'default': ConnectionsSortOrder.dateAdded, + 'description': localize('datasource.connectionsSortOrder', "Controls sorting order of saved connections and connection groups.") } } });