Skip to content

Build your personal knowledge base with Trilium Notes

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.ts
index 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.ts
index 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);
+ }
}
}