mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 17:22:59 -05:00
add sorting option for saved connections (#15229)
* add sort by name option for saved connections and groups
This commit is contained in:
@@ -14,8 +14,14 @@ import * as nls from 'vs/nls';
|
||||
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { deepClone } from 'vs/base/common/objects';
|
||||
|
||||
const GROUPS_CONFIG_KEY = 'datasource.connectionGroups';
|
||||
const CONNECTIONS_CONFIG_KEY = 'datasource.connections';
|
||||
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 enum ConnectionsSortBy {
|
||||
dateAdded = 'dateAdded',
|
||||
displayName = 'displayName'
|
||||
}
|
||||
|
||||
export interface ISaveGroupResult {
|
||||
groups: IConnectionProfileGroup[];
|
||||
@@ -49,6 +55,26 @@ export class ConnectionConfig {
|
||||
}
|
||||
allGroups = allGroups.concat(userValue);
|
||||
}
|
||||
|
||||
const sortBy = this.configurationService.getValue<string>(CONNECTIONS_SORT_BY_CONFIG_KEY);
|
||||
let sortFunc: (a: IConnectionProfileGroup, b: IConnectionProfileGroup) => number;
|
||||
|
||||
if (sortBy === ConnectionsSortBy.displayName) {
|
||||
sortFunc = ((a, b) => {
|
||||
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 => {
|
||||
if (g.parentId === '' || !g.parentId) {
|
||||
g.parentId = undefined;
|
||||
@@ -214,6 +240,25 @@ export class ConnectionConfig {
|
||||
return ConnectionProfile.createFromStoredProfile(p, this._capabilitiesService);
|
||||
});
|
||||
|
||||
const sortBy = this.configurationService.getValue<string>(CONNECTIONS_SORT_BY_CONFIG_KEY);
|
||||
let sortFunc: (a: ConnectionProfile, b: ConnectionProfile) => number;
|
||||
|
||||
if (sortBy === ConnectionsSortBy.displayName) {
|
||||
sortFunc = ((a, b) => {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user