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
client: fix some issues
Adorian Doranbb67c016f269
diff --git a/apps/client/src/services/attributes.spec.ts b/apps/client/src/services/attributes.spec.tsindex f4b0d0147c..92c1979ea7 100644--- a/apps/client/src/services/attributes.spec.ts+++ b/apps/client/src/services/attributes.spec.ts@@ -138,6 +138,36 @@ describe("Set boolean with inheritance", () => {}, undefined);});+ it("compares with the inherited value when the note owns the label too", async () => {+ buildNote({+ title: "Parent note",+ "#foo(inheritable)": "",+ "children": [+ { id: "ownsTrue", title: "Owns true", "#foo": "" },+ { id: "ownsFalse", title: "Owns false", "#foo": "false" }+ ]+ });+ const ownsTrue = froca.notes["ownsTrue"];+ const ownsFalse = froca.notes["ownsFalse"];++ const overrideId = ownsFalse.getOwnedLabel("foo")?.attributeId;+ expect(overrideId).toBeTruthy();+ await setBooleanWithInheritance(ownsFalse, "foo", true);+ expect(server.remove).toHaveBeenCalledWith(`notes/ownsFalse/attributes/${overrideId}`);+ expect(server.put).not.toHaveBeenCalled();++ vi.clearAllMocks();+ // Removing the owned label would leave the inherited one in effect.+ await setBooleanWithInheritance(ownsTrue, "foo", false);+ expect(server.put).toHaveBeenCalledWith(`notes/ownsTrue/set-attribute`, {+ type: "label",+ name: "foo",+ value: "false",+ isInheritable: false+ }, undefined);+ expect(server.remove).not.toHaveBeenCalled();+ });+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"));diff --git a/apps/client/src/services/attributes.ts b/apps/client/src/services/attributes.tsindex 64a3bea2f7..e3c0d395de 100644--- a/apps/client/src/services/attributes.ts+++ b/apps/client/src/services/attributes.ts@@ -45,21 +45,15 @@ export async function setRelation(noteId: string, name: string, value: string =* @param value the boolean value to set for the label.*/export async function setBooleanWithInheritance(note: FNote, labelName: string, value: boolean) {- const actualValue = note.isLabelTruthy(labelName);- if (actualValue === value) return;- const hasInheritedValue = !note.hasOwnedLabel(labelName) && note.hasLabel(labelName);+ if (note.isLabelTruthy(labelName) === value) return;- if (hasInheritedValue) {- if (value) {- await setLabel(note.noteId, labelName, "");- } else {- // Label is inherited - override to false.- await setLabel(note.noteId, labelName, "false");- }- } else if (value) {- await setLabel(note.noteId, labelName, "");- } else {+ const inheritedLabel = note.getLabels(labelName).find((label) => label.noteId !== note.noteId);+ const inheritedValue = !!inheritedLabel && inheritedLabel.value !== "false";++ if (value === inheritedValue) {await removeOwnedLabelByName(note, labelName);+ } else {+ await setLabel(note.noteId, labelName, value ? "" : "false");}}diff --git a/apps/client/src/widgets/react/Menu.css b/apps/client/src/widgets/react/Menu.cssindex 80298766a2..05e27c0a1d 100644--- a/apps/client/src/widgets/react/Menu.css+++ b/apps/client/src/widgets/react/Menu.css@@ -222,7 +222,6 @@ body.desktop .dropdown-item.dropdown-submenu.submenu-open,}.tn-menu-filter-clear {- /* Takes the 1em of the magnifier it replaces, so the box keeps its size. */margin: calc((1em - var(--icon-button-size)) / 2);}