mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Fix connection sorting by name in OE (#19991)
* use localeCompare & sort by title instead of name * fix tests
This commit is contained in:
@@ -48,6 +48,7 @@ export class ConnectionConfig {
|
|||||||
const config = this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY);
|
const config = this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY);
|
||||||
let { userValue } = config;
|
let { userValue } = config;
|
||||||
const { workspaceValue } = config;
|
const { workspaceValue } = config;
|
||||||
|
const sortBy = this.configurationService.getValue<string>(CONNECTIONS_SORT_BY_CONFIG_KEY);
|
||||||
|
|
||||||
if (userValue) {
|
if (userValue) {
|
||||||
if (workspaceValue) {
|
if (workspaceValue) {
|
||||||
@@ -57,23 +58,8 @@ export class ConnectionConfig {
|
|||||||
allGroups = allGroups.concat(userValue);
|
allGroups = allGroups.concat(userValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortBy = this.configurationService.getValue<string>(CONNECTIONS_SORT_BY_CONFIG_KEY);
|
|
||||||
let sortFunc: (a: IConnectionProfileGroup, b: IConnectionProfileGroup) => number;
|
|
||||||
|
|
||||||
if (sortBy === ConnectionsSortOrder.displayName) {
|
if (sortBy === ConnectionsSortOrder.displayName) {
|
||||||
sortFunc = ((a, b) => {
|
allGroups.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
if (a.name < b.name) {
|
|
||||||
return -1;
|
|
||||||
} else if (a.name > b.name) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sortFunc) {
|
|
||||||
allGroups.sort(sortFunc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return deepClone(allGroups).map(g => {
|
return deepClone(allGroups).map(g => {
|
||||||
@@ -249,24 +235,10 @@ export class ConnectionConfig {
|
|||||||
let connectionProfiles = this.getIConnectionProfileStores(getWorkspaceConnections).map(p => {
|
let connectionProfiles = this.getIConnectionProfileStores(getWorkspaceConnections).map(p => {
|
||||||
return ConnectionProfile.createFromStoredProfile(p, this._capabilitiesService);
|
return ConnectionProfile.createFromStoredProfile(p, this._capabilitiesService);
|
||||||
});
|
});
|
||||||
|
|
||||||
const sortBy = this.configurationService.getValue<string>(CONNECTIONS_SORT_BY_CONFIG_KEY);
|
const sortBy = this.configurationService.getValue<string>(CONNECTIONS_SORT_BY_CONFIG_KEY);
|
||||||
let sortFunc: (a: ConnectionProfile, b: ConnectionProfile) => number;
|
|
||||||
|
|
||||||
if (sortBy === ConnectionsSortOrder.displayName) {
|
if (sortBy === ConnectionsSortOrder.displayName) {
|
||||||
sortFunc = ((a, b) => {
|
connectionProfiles.sort((a, b) => a.title.localeCompare(b.title));
|
||||||
if (a.title < b.title) {
|
|
||||||
return -1;
|
|
||||||
} else if (a.title > b.title) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sortFunc) {
|
|
||||||
connectionProfiles.sort(sortFunc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return connectionProfiles;
|
return connectionProfiles;
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ suite('ConnectionConfig', () => {
|
|||||||
|
|
||||||
assert.strictEqual(allGroups.length, testGroups.length, 'did not meet the expected length');
|
assert.strictEqual(allGroups.length, testGroups.length, 'did not meet the expected length');
|
||||||
assert.ok(groupsAreEqual(allGroups, testGroups), 'the groups returned did not match expectation');
|
assert.ok(groupsAreEqual(allGroups, testGroups), 'the groups returned did not match expectation');
|
||||||
assert.ok(allGroups.slice(1).every((item, i) => allGroups[i].name <= item.name), 'the groups are not sorted correctly');
|
assert.ok(allGroups.slice(1).every((item, i) => allGroups[i].name.localeCompare(item.name) <= 0), 'the groups are not sorted correctly');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getAllGroups should return groups sorted by date added given datasource.connectionsSortOrder is set to \'' + ConnectionsSortOrder.dateAdded + '\'', () => {
|
test('getAllGroups should return groups sorted by date added given datasource.connectionsSortOrder is set to \'' + ConnectionsSortOrder.dateAdded + '\'', () => {
|
||||||
@@ -420,7 +420,7 @@ suite('ConnectionConfig', () => {
|
|||||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||||
let allConnections = config.getConnections(true);
|
let allConnections = config.getConnections(true);
|
||||||
assert.strictEqual(allConnections.length, testConnections.length, 'The result connections length is invalid');
|
assert.strictEqual(allConnections.length, testConnections.length, 'The result connections length is invalid');
|
||||||
assert.ok(allConnections.slice(1).every((item, i) => allConnections[i].title <= item.title), 'The connections are not sorted correctly');
|
assert.ok(allConnections.slice(1).every((item, i) => allConnections[i].title.localeCompare(item.title) <= 0), 'The connections are not sorted correctly');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getConnections should return connections sorted by date added given datasource.connectionsSortOrder is set to \'' + ConnectionsSortOrder.dateAdded + '\'', () => {
|
test('getConnections should return connections sorted by date added given datasource.connectionsSortOrder is set to \'' + ConnectionsSortOrder.dateAdded + '\'', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user