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(client): await the write in setBooleanWithInheritance
irontaekeedec4ac69a4
diff --git a/apps/client/src/services/attributes.spec.ts b/apps/client/src/services/attributes.spec.tsindex b94fe29c46..71179bd346 100644--- a/apps/client/src/services/attributes.spec.ts+++ b/apps/client/src/services/attributes.spec.ts@@ -137,6 +137,18 @@ describe("Set boolean with inheritance", () => {isInheritable: false}, undefined);});++ it("waits for the label write and surfaces its failure", async () => {+ const note = buildNote({ title: "New note" });+ vi.mocked(server.put).mockRejectedValueOnce(new Error("offline"));+ await expect(setBooleanWithInheritance(note, "foo", true)).rejects.toThrow("offline");+ });++ it("waits for the label removal and surfaces its failure", async () => {+ const note = buildNote({ title: "New note", "#foo": "" });+ vi.mocked(server.remove).mockRejectedValueOnce(new Error("offline"));+ await expect(setBooleanWithInheritance(note, "foo", false)).rejects.toThrow("offline");+ });});describe("addLabel / setLabel / setRelation", () => {diff --git a/apps/client/src/services/attributes.ts b/apps/client/src/services/attributes.tsindex 221b07b147..33b1c6f477 100644--- a/apps/client/src/services/attributes.ts+++ b/apps/client/src/services/attributes.ts@@ -51,15 +51,18 @@ export async function setBooleanWithInheritance(note: FNote, labelName: string,if (hasInheritedValue) {if (value) {- setLabel(note.noteId, labelName, "");+ await setLabel(note.noteId, labelName, "");} else {// Label is inherited - override to false.- setLabel(note.noteId, labelName, "false");+ await setLabel(note.noteId, labelName, "false");}} else if (value) {- setLabel(note.noteId, labelName, "");+ await setLabel(note.noteId, labelName, "");} else {- removeOwnedLabelByName(note, labelName);+ const label = note.getOwnedLabel(labelName);+ if (label) {+ await removeAttributeById(note.noteId, label.attributeId);+ }}}