[ui] sorting improvements

feat/vaults
Tomáš Mládek 2022-02-15 22:17:23 +01:00
parent 9639bec677
commit 604292d56d
No known key found for this signature in database
GPG Key ID: 65E225C8B3E2ED8A
1 changed files with 23 additions and 4 deletions

View File

@ -5,6 +5,13 @@ export type SortKeys = { [key: string]: string[] };
export function sortByValue(entries: UpEntry[], sortKeys: SortKeys): void {
entries
.sort((aEntry, bEntry) => {
return String(aEntry.value.c).length - String(bEntry.value.c).length;
})
.sort((aEntry, bEntry) => {
if (aEntry.value.t === "Number" && bEntry.value.t === "Number") {
return bEntry.value.c - aEntry.value.c;
}
if (
!sortKeys[aEntry.value.c]?.length ||
!sortKeys[bEntry.value.c]?.length
@ -20,7 +27,11 @@ export function sortByValue(entries: UpEntry[], sortKeys: SortKeys): void {
) {
return 1;
} else {
return String(aEntry.value.c).localeCompare(String(bEntry.value.c));
return String(aEntry.value.c).localeCompare(
String(bEntry.value.c),
undefined,
{ numeric: true, sensitivity: "base" }
);
}
} else {
return sortKeys[aEntry.value.c][0].localeCompare(
@ -29,9 +40,6 @@ export function sortByValue(entries: UpEntry[], sortKeys: SortKeys): void {
{ numeric: true, sensitivity: "base" }
);
}
})
.sort((aEntry, bEntry) => {
return String(aEntry.value.c).length - String(bEntry.value.c).length;
});
}
@ -82,3 +90,14 @@ export function defaultEntitySort(
sortByEntity(entries, sortKeys);
return result;
}
export function entityValueSort(
entries: UpEntry[],
sortKeys: SortKeys
): UpEntry[] {
const result = entries.concat();
sortByEntity(entries, sortKeys);
sortByAttribute(entries);
sortByValue(entries, sortKeys);
return result;
}