[ui] fix & optimize sort (wow)
parent
5cef2b8960
commit
9ce4c21b93
|
@ -113,7 +113,8 @@
|
||||||
entries.forEach((entry) => {
|
entries.forEach((entry) => {
|
||||||
addSortKeys(
|
addSortKeys(
|
||||||
entry.entity,
|
entry.entity,
|
||||||
$labelListing.getObject(entry.entity).identify()
|
$labelListing.getObject(entry.entity).identify(),
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
if (entry.value.t === "Address") {
|
if (entry.value.t === "Address") {
|
||||||
|
|
|
@ -3,11 +3,10 @@ import type { UpEntry } from "upend";
|
||||||
export type SortKeys = { [key: string]: string[] };
|
export type SortKeys = { [key: string]: string[] };
|
||||||
|
|
||||||
export function sortByValue(entries: UpEntry[], sortKeys: SortKeys): void {
|
export function sortByValue(entries: UpEntry[], sortKeys: SortKeys): void {
|
||||||
entries
|
entries.sort((aEntry, bEntry) => {
|
||||||
.sort((aEntry, bEntry) => {
|
|
||||||
return String(aEntry.value.c).length - String(bEntry.value.c).length;
|
return String(aEntry.value.c).length - String(bEntry.value.c).length;
|
||||||
})
|
});
|
||||||
.sort((aEntry, bEntry) => {
|
entries.sort((aEntry, bEntry) => {
|
||||||
if (aEntry.value.t === "Number" && bEntry.value.t === "Number") {
|
if (aEntry.value.t === "Number" && bEntry.value.t === "Number") {
|
||||||
return bEntry.value.c - aEntry.value.c;
|
return bEntry.value.c - aEntry.value.c;
|
||||||
}
|
}
|
||||||
|
@ -50,15 +49,11 @@ export function sortByAttribute(entries: UpEntry[]): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sortByEntity(entries: UpEntry[], sortKeys: SortKeys): void {
|
export function sortByEntity(entries: UpEntry[], sortKeys: SortKeys): void {
|
||||||
entries
|
entries.sort((aEntry, bEntry) => {
|
||||||
.sort((aEntry, bEntry) => {
|
|
||||||
return aEntry.attribute.localeCompare(bEntry.attribute);
|
return aEntry.attribute.localeCompare(bEntry.attribute);
|
||||||
})
|
});
|
||||||
.sort((aEntry, bEntry) => {
|
entries.sort((aEntry, bEntry) => {
|
||||||
if (
|
if (!sortKeys[aEntry.entity]?.length || !sortKeys[bEntry.entity]?.length) {
|
||||||
!sortKeys[aEntry.entity]?.length ||
|
|
||||||
!sortKeys[bEntry.entity]?.length
|
|
||||||
) {
|
|
||||||
if (
|
if (
|
||||||
Boolean(sortKeys[aEntry.entity]?.length) &&
|
Boolean(sortKeys[aEntry.entity]?.length) &&
|
||||||
!sortKeys[bEntry.entity]?.length
|
!sortKeys[bEntry.entity]?.length
|
||||||
|
@ -85,9 +80,9 @@ export function defaultEntitySort(
|
||||||
sortKeys: SortKeys
|
sortKeys: SortKeys
|
||||||
): UpEntry[] {
|
): UpEntry[] {
|
||||||
const result = entries.concat();
|
const result = entries.concat();
|
||||||
sortByValue(entries, sortKeys);
|
sortByValue(result, sortKeys);
|
||||||
sortByAttribute(entries);
|
sortByAttribute(result);
|
||||||
sortByEntity(entries, sortKeys);
|
sortByEntity(result, sortKeys);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,8 +91,8 @@ export function entityValueSort(
|
||||||
sortKeys: SortKeys
|
sortKeys: SortKeys
|
||||||
): UpEntry[] {
|
): UpEntry[] {
|
||||||
const result = entries.concat();
|
const result = entries.concat();
|
||||||
sortByEntity(entries, sortKeys);
|
sortByEntity(result, sortKeys);
|
||||||
sortByAttribute(entries);
|
sortByAttribute(result);
|
||||||
sortByValue(entries, sortKeys);
|
sortByValue(result, sortKeys);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue