[ui] entry value length takes priority to better match expectations
parent
9ce4c21b93
commit
d8314c0596
|
@ -3,9 +3,6 @@ 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.sort((aEntry, bEntry) => {
|
|
||||||
return String(aEntry.value.c).length - String(bEntry.value.c).length;
|
|
||||||
});
|
|
||||||
entries.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;
|
||||||
|
@ -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 {
|
export function sortByAttribute(entries: UpEntry[]): void {
|
||||||
entries.sort((aEntry, bEntry) => {
|
entries.sort((aEntry, bEntry) => {
|
||||||
return aEntry.attribute.localeCompare(bEntry.attribute);
|
return aEntry.attribute.localeCompare(bEntry.attribute);
|
||||||
|
@ -81,6 +84,7 @@ export function defaultEntitySort(
|
||||||
): UpEntry[] {
|
): UpEntry[] {
|
||||||
const result = entries.concat();
|
const result = entries.concat();
|
||||||
sortByValue(result, sortKeys);
|
sortByValue(result, sortKeys);
|
||||||
|
sortByValueLength(result);
|
||||||
sortByAttribute(result);
|
sortByAttribute(result);
|
||||||
sortByEntity(result, sortKeys);
|
sortByEntity(result, sortKeys);
|
||||||
return result;
|
return result;
|
||||||
|
@ -93,6 +97,7 @@ export function entityValueSort(
|
||||||
const result = entries.concat();
|
const result = entries.concat();
|
||||||
sortByEntity(result, sortKeys);
|
sortByEntity(result, sortKeys);
|
||||||
sortByAttribute(result);
|
sortByAttribute(result);
|
||||||
|
sortByValueLength(result);
|
||||||
sortByValue(result, sortKeys);
|
sortByValue(result, sortKeys);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue