Sort agents alphabetically by name in all views
Sort the flat list view, org tree view, and sidebar agents list alphabetically by name using localeCompare. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
e61f00d4c1
commit
bdecb1bad2
2 changed files with 16 additions and 8 deletions
|
|
@ -28,6 +28,10 @@ function sortByHierarchy(agents: Agent[]): Agent[] {
|
|||
list.push(a);
|
||||
childrenOf.set(parent, list);
|
||||
}
|
||||
// Sort children at each level alphabetically by name
|
||||
for (const [, list] of childrenOf) {
|
||||
list.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
const sorted: Agent[] = [];
|
||||
const queue = childrenOf.get(null) ?? [];
|
||||
while (queue.length > 0) {
|
||||
|
|
|
|||
|
|
@ -45,17 +45,21 @@ function matchesFilter(status: string, tab: FilterTab, showTerminated: boolean):
|
|||
}
|
||||
|
||||
function filterAgents(agents: Agent[], tab: FilterTab, showTerminated: boolean): Agent[] {
|
||||
return agents.filter((a) => matchesFilter(a.status, tab, showTerminated));
|
||||
return agents
|
||||
.filter((a) => matchesFilter(a.status, tab, showTerminated))
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
function filterOrgTree(nodes: OrgNode[], tab: FilterTab, showTerminated: boolean): OrgNode[] {
|
||||
return nodes.reduce<OrgNode[]>((acc, node) => {
|
||||
const filteredReports = filterOrgTree(node.reports, tab, showTerminated);
|
||||
if (matchesFilter(node.status, tab, showTerminated) || filteredReports.length > 0) {
|
||||
acc.push({ ...node, reports: filteredReports });
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
return nodes
|
||||
.reduce<OrgNode[]>((acc, node) => {
|
||||
const filteredReports = filterOrgTree(node.reports, tab, showTerminated);
|
||||
if (matchesFilter(node.status, tab, showTerminated) || filteredReports.length > 0) {
|
||||
acc.push({ ...node, reports: filteredReports });
|
||||
}
|
||||
return acc;
|
||||
}, [])
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
export function Agents() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue