Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(commons): write an explicit ascending level as `asc`
BeatLink8aee14a26538
diff --git a/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx b/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsxindex 5fa0c9ab12..060ed1ad8a 100644--- a/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx+++ b/apps/client/src/widgets/dialogs/sort_child_notes.spec.tsx@@ -18,7 +18,7 @@ describe("serializeSortLevels", () => {{ kind: "label", labelName: "", direction: "asc" },{ kind: "dateCreated", labelName: "", direction: "asc" },{ kind: "title", labelName: "ignored", direction: "desc" }- ])).toBe("priority desc, dateCreated, title desc");+ ])).toBe("priority desc, dateCreated asc, title desc");});});@@ -86,7 +86,7 @@ describe("SortChildNotesDialog", () => {expect(levels()[0].querySelector(".sort-level-remove")).toHaveProperty("disabled", true);await submit();expect(put).toHaveBeenCalledWith("notes/parent/sort-children", expect.objectContaining({- sortBy: "title",+ sortBy: "title asc",foldersFirst: false,sortNatural: false}));@@ -109,7 +109,7 @@ describe("SortChildNotesDialog", () => {await submit();expect(put).toHaveBeenCalledWith("notes/parent/sort-children", expect.objectContaining({- sortBy: "priority desc, dateModified"+ sortBy: "priority desc, dateModified asc"}));});@@ -123,7 +123,7 @@ describe("SortChildNotesDialog", () => {await click(second.querySelector(".sort-level-up"));await submit();expect(put).toHaveBeenCalledWith("notes/parent/sort-children", expect.objectContaining({- sortBy: "dateCreated, title"+ sortBy: "dateCreated asc, title asc"}));});diff --git a/apps/client/src/widgets/dialogs/sort_child_notes.tsx b/apps/client/src/widgets/dialogs/sort_child_notes.tsxindex 7499f848ce..dfe0106822 100644--- a/apps/client/src/widgets/dialogs/sort_child_notes.tsx+++ b/apps/client/src/widgets/dialogs/sort_child_notes.tsx@@ -177,7 +177,7 @@ export default function SortChildNotesDialog() {)}-/** Writes the levels in the `#sorted` grammar, skipping a label level that names no label. */+/** Writes the levels in the `#sorted` grammar with their directions, skipping a nameless label. */export function serializeSortLevels(levels: SortLevel[]) {const criteria: SortCriterion[] = [];for (const level of levels) {diff --git a/packages/commons/src/lib/sort_criteria.spec.ts b/packages/commons/src/lib/sort_criteria.spec.tsindex ca2e1f8979..a12d26592f 100644--- a/packages/commons/src/lib/sort_criteria.spec.ts+++ b/packages/commons/src/lib/sort_criteria.spec.ts@@ -28,8 +28,7 @@ describe("sort criteria", () => {{ key: "title", descending: undefined }];const written = serializeSortCriteria(criteria);- expect(written).toBe("priority desc, dateCreated, title");- expect(parseSortCriteria(written).map((c) => Boolean(c.descending)))- .toEqual(criteria.map((c) => Boolean(c.descending)));+ expect(written).toBe("priority desc, dateCreated asc, title");+ expect(parseSortCriteria(written)).toEqual(criteria);});});diff --git a/packages/commons/src/lib/sort_criteria.ts b/packages/commons/src/lib/sort_criteria.tsindex 3da99a77cd..3edfc82f6e 100644--- a/packages/commons/src/lib/sort_criteria.ts+++ b/packages/commons/src/lib/sort_criteria.ts@@ -25,9 +25,14 @@ export function parseSortCriteria(value: string | null | undefined): SortCriterireturn criteria.length > 0 ? criteria : [{ key: "title" }];}-/** Writes levels back into the `#sorted` grammar; a level that is not descending is written bare. */+/** Writes levels back into the `#sorted` grammar; only a level without a direction is bare. */export function serializeSortCriteria(criteria: SortCriterion[]) {return criteria- .map(({ key, descending }) => (descending ? `${key} desc` : key))+ .map(({ key, descending }) => {+ if (descending === undefined) {+ return key;+ }+ return `${key} ${descending ? "desc" : "asc"}`;+ }).join(", ");}