[ui] entry value length takes priority to better match expectations

feat/vaults
Tomáš Mládek 2022-02-19 18:39:13 +01:00
parent 9ce4c21b93
commit d8314c0596
No known key found for this signature in database
GPG Key ID: 65E225C8B3E2ED8A
1 changed files with 8 additions and 3 deletions

View File

@ -3,9 +3,6 @@ import type { UpEntry } from "upend";
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;
});
entries.sort((aEntry, bEntry) => {
if (aEntry.value.t === "Number" && bEntry.value.t === "Number") {
return bEntry.value.c - aEntry.value.c;
@ -42,6 +39,12 @@ export function sortByValue(entries: UpEntry[], sortKeys: SortKeys): void {
});
}
export function sortByValueLength(entries: UpEntry[]) {
entries.sort((aEntry, bEntry) => {
return String(aEntry.value.c).length - String(bEntry.value.c).length;
});
}
export function sortByAttribute(entries: UpEntry[]): void {
entries.sort((aEntry, bEntry) => {
return aEntry.attribute.localeCompare(bEntry.attribute);
@ -81,6 +84,7 @@ export function defaultEntitySort(
): UpEntry[] {
const result = entries.concat();
sortByValue(result, sortKeys);
sortByValueLength(result);
sortByAttribute(result);
sortByEntity(result, sortKeys);
return result;
@ -93,6 +97,7 @@ export function entityValueSort(
const result = entries.concat();
sortByEntity(result, sortKeys);
sortByAttribute(result);
sortByValueLength(result);
sortByValue(result, sortKeys);
return result;
}