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(tree): type issues & error if active node is empty
Elian Doranafa92551eab6
diff --git a/apps/client/src/types-fancytree.d.ts b/apps/client/src/types-fancytree.d.tsindex e82cb895f8..cb709ea07d 100644--- a/apps/client/src/types-fancytree.d.ts+++ b/apps/client/src/types-fancytree.d.ts@@ -215,6 +215,30 @@ declare namespace Fancytree {enableUpdate(enabled: boolean): void;}+ interface FancytreeNodeData {+ noteId: string;+ parentNoteId: string;+ branchId: string;+ isProtected: boolean;+ noteType: NoteType;+ }++ interface FancytreeNewNode extends FancytreeNodeData {+ title: string;+ extraClasses: string;+ icon: string;+ refKey: string;+ /** True if this node is loaded on demand, i.e. on first expansion. */+ lazy: boolean;+ /** Folder nodes have different default icons and click behavior. Note: Also non-folders may have children. */+ folder: boolean;+ /** Use isExpanded(), setExpanded() to access this property. */+ expanded: boolean;+ /** Node id (must be unique inside the tree) */+ key: string;+ children?: FancytreeNewNode[];+ }+/** A FancytreeNode represents the hierarchical data model and operations. */interface FancytreeNode {// #region Properties@@ -227,7 +251,7 @@ declare namespace Fancytree {/** Display name (may contain HTML) */title: string;/** Contains all extra data that was passed on node creation */- data: any;+ data: FancytreeNodeData;/** Array of child nodes. For lazy nodes, null or undefined means 'not yet loaded'. Use an empty array to define a node that has no children. */children: FancytreeNode[];/** Use isExpanded(), setExpanded() to access this property. */diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.tsindex cb21206870..1fd3735592 100644--- a/apps/client/src/widgets/note_tree.ts+++ b/apps/client/src/widgets/note_tree.ts@@ -173,14 +173,6 @@ interface ExpandedSubtreeResponse {branchIds: string[];}-interface Node extends Fancytree.NodeData {- noteId: string;- parentNoteId: string;- branchId: string;- isProtected: boolean;- noteType: NoteType;-}-interface RefreshContext {noteIdsToUpdate: Set<string>;noteIdsToReload: Set<string>;@@ -769,7 +761,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {prepareChildren(parentNote: FNote) {utils.assertArguments(parentNote);- const noteList: Node[] = [];+ const noteList: Fancytree.FancytreeNewNode[] = [];const hideArchivedNotes = this.hideArchivedNotes;@@ -837,7 +829,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {const isFolder = note.isFolder();- const node: Node = {+ const node: Fancytree.FancytreeNewNode = {noteId: note.noteId,parentNoteId: branch.parentNoteId,branchId: branch.branchId,@@ -849,7 +841,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {refKey: note.noteId,lazy: true,folder: isFolder,- expanded: branch.isExpanded && note.type !== "search",+ expanded: !!branch.isExpanded && note.type !== "search",key: utils.randomString(12) // this should prevent some "duplicate key" errors};@@ -911,7 +903,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {return extraClasses.join(" ");}- /** @returns {FancytreeNode[]} */getSelectedNodes(stopOnParents = false) {return this.tree.getSelectedNodes(stopOnParents);}@@ -1532,7 +1523,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {// Automatically expand the hoisted note by defaultconst node = this.getActiveNode();- if (node?.data.noteId === this.noteContext.hoistedNoteId){+ if (node && node.data.noteId === this.noteContext.hoistedNoteId){this.setExpanded(node.data.branchId, true);}}