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
feat(tree): add option to hide or show subtree
Elian Doranaf537e6a48ed
diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.tsindex 3f5aa94802..d7ff4b777b 100644--- a/apps/client/src/menus/tree_context_menu.ts+++ b/apps/client/src/menus/tree_context_menu.ts@@ -151,8 +151,17 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree{ kind: "separator" },- { title: t("tree-context-menu.expand-subtree"), command: "expandSubtree", keyboardShortcut: "expandSubtree", uiIcon: "bx bx-expand", enabled: noSelectedNotes },- { title: t("tree-context-menu.collapse-subtree"), command: "collapseSubtree", keyboardShortcut: "collapseSubtree", uiIcon: "bx bx-collapse", enabled: noSelectedNotes },+ !hasSubtreeHidden && { title: t("tree-context-menu.expand-subtree"), command: "expandSubtree", keyboardShortcut: "expandSubtree", uiIcon: "bx bx-expand", enabled: noSelectedNotes },+ !hasSubtreeHidden && { title: t("tree-context-menu.collapse-subtree"), command: "collapseSubtree", keyboardShortcut: "collapseSubtree", uiIcon: "bx bx-collapse", enabled: noSelectedNotes },+ {+ title: hasSubtreeHidden ? t("tree-context-menu.show-subtree") : t("tree-context-menu.hide-subtree"),+ uiIcon: "bx bx-show",+ handler: async () => {+ const note = await froca.getNote(this.node.data.noteId);+ if (!note) return;+ attributes.toggleBooleanWithInheritance(note, "subtreeHidden");+ }+ },{title: t("tree-context-menu.sort-by"),command: "sortChildNotes",@@ -165,7 +174,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree{ title: t("tree-context-menu.copy-note-path-to-clipboard"), command: "copyNotePathToClipboard", uiIcon: "bx bx-directions", enabled: true },{ title: t("tree-context-menu.recent-changes-in-subtree"), command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes && notOptionsOrHelp }- ]+ ].filter(Boolean) as MenuItem<TreeCommandNames>[]},{ kind: "separator" },diff --git a/apps/client/src/services/attributes.ts b/apps/client/src/services/attributes.tsindex 4559c8f8b0..359e7ab433 100644--- a/apps/client/src/services/attributes.ts+++ b/apps/client/src/services/attributes.ts@@ -1,14 +1,15 @@-import server from "./server.js";-import froca from "./froca.js";+import { AttributeType } from "@triliumnext/commons";+import type FNote from "../entities/fnote.js";+import froca from "./froca.js";import type { AttributeRow } from "./load_results.js";-import { AttributeType } from "@triliumnext/commons";+import server from "./server.js";async function addLabel(noteId: string, name: string, value: string = "", isInheritable = false) {await server.put(`notes/${noteId}/attribute`, {type: "label",- name: name,- value: value,+ name,+ value,isInheritable});}@@ -16,8 +17,8 @@ async function addLabel(noteId: string, name: string, value: string = "", isInheexport async function setLabel(noteId: string, name: string, value: string = "", isInheritable = false) {await server.put(`notes/${noteId}/set-attribute`, {type: "label",- name: name,- value: value,+ name,+ value,isInheritable});}@@ -25,12 +26,33 @@ export async function setLabel(noteId: string, name: string, value: string = "",export async function setRelation(noteId: string, name: string, value: string = "", isInheritable = false) {await server.put(`notes/${noteId}/set-attribute`, {type: "relation",- name: name,- value: value,+ name,+ value,isInheritable});}+/**+ * Toggles a boolean label on the given note, taking inheritance into account. If the label is owned by the note, it+ * will be removed. If the label is inherited from a parent note, it will be overridden to `false`. If the label does+ * not exist, it will be added with an empty value.+ *+ * @param note the note on which to toggle the label.+ * @param labelName the name of the label to toggle.+ */+export async function toggleBooleanWithInheritance(note: FNote, labelName: string) {+ if (note.hasLabel(labelName)) {+ // Can either be owned by us or inherited from parent.+ if (note.hasOwnedLabel(labelName)) {+ removeOwnedLabelByName(note, labelName);+ } else {+ setLabel(note.noteId, labelName, "false");+ }+ } else {+ addLabel(note.noteId, labelName);+ }+}+async function removeAttributeById(noteId: string, attributeId: string) {await server.remove(`notes/${noteId}/attributes/${attributeId}`);}@@ -142,6 +164,7 @@ export default {setLabel,setRelation,setAttribute,+ toggleBooleanWithInheritance,removeAttributeById,removeOwnedLabelByName,removeOwnedRelationByName,diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 54c10275b2..25499ecbf0 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1655,6 +1655,8 @@"advanced": "Advanced","expand-subtree": "Expand subtree","collapse-subtree": "Collapse subtree",+ "hide-subtree": "Hide subtree",+ "show-subtree": "Show subtree","sort-by": "Sort by...","recent-changes-in-subtree": "Recent changes in subtree","convert-to-attachment": "Convert to attachment",