Skip to content

Commit afa9255

Browse files
committed
fix(tree): type issues & error if active node is empty
1 parent cc0646e commit afa9255

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

apps/client/src/types-fancytree.d.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,30 @@ declare namespace Fancytree {
215215
enableUpdate(enabled: boolean): void;
216216
}
217217

218+
interface FancytreeNodeData {
219+
noteId: string;
220+
parentNoteId: string;
221+
branchId: string;
222+
isProtected: boolean;
223+
noteType: NoteType;
224+
}
225+
226+
interface FancytreeNewNode extends FancytreeNodeData {
227+
title: string;
228+
extraClasses: string;
229+
icon: string;
230+
refKey: string;
231+
/** True if this node is loaded on demand, i.e. on first expansion. */
232+
lazy: boolean;
233+
/** Folder nodes have different default icons and click behavior. Note: Also non-folders may have children. */
234+
folder: boolean;
235+
/** Use isExpanded(), setExpanded() to access this property. */
236+
expanded: boolean;
237+
/** Node id (must be unique inside the tree) */
238+
key: string;
239+
children?: FancytreeNewNode[];
240+
}
241+
218242
/** A FancytreeNode represents the hierarchical data model and operations. */
219243
interface FancytreeNode {
220244
// #region Properties
@@ -227,7 +251,7 @@ declare namespace Fancytree {
227251
/** Display name (may contain HTML) */
228252
title: string;
229253
/** Contains all extra data that was passed on node creation */
230-
data: any;
254+
data: FancytreeNodeData;
231255
/** 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. */
232256
children: FancytreeNode[];
233257
/** Use isExpanded(), setExpanded() to access this property. */

apps/client/src/widgets/note_tree.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,6 @@ interface ExpandedSubtreeResponse {
173173
branchIds: string[];
174174
}
175175

176-
interface Node extends Fancytree.NodeData {
177-
noteId: string;
178-
parentNoteId: string;
179-
branchId: string;
180-
isProtected: boolean;
181-
noteType: NoteType;
182-
}
183-
184176
interface RefreshContext {
185177
noteIdsToUpdate: Set<string>;
186178
noteIdsToReload: Set<string>;
@@ -769,7 +761,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
769761
prepareChildren(parentNote: FNote) {
770762
utils.assertArguments(parentNote);
771763

772-
const noteList: Node[] = [];
764+
const noteList: Fancytree.FancytreeNewNode[] = [];
773765

774766
const hideArchivedNotes = this.hideArchivedNotes;
775767

@@ -837,7 +829,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
837829

838830
const isFolder = note.isFolder();
839831

840-
const node: Node = {
832+
const node: Fancytree.FancytreeNewNode = {
841833
noteId: note.noteId,
842834
parentNoteId: branch.parentNoteId,
843835
branchId: branch.branchId,
@@ -849,7 +841,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
849841
refKey: note.noteId,
850842
lazy: true,
851843
folder: isFolder,
852-
expanded: branch.isExpanded && note.type !== "search",
844+
expanded: !!branch.isExpanded && note.type !== "search",
853845
key: utils.randomString(12) // this should prevent some "duplicate key" errors
854846
};
855847

@@ -911,7 +903,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
911903
return extraClasses.join(" ");
912904
}
913905

914-
/** @returns {FancytreeNode[]} */
915906
getSelectedNodes(stopOnParents = false) {
916907
return this.tree.getSelectedNodes(stopOnParents);
917908
}
@@ -1532,7 +1523,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
15321523

15331524
// Automatically expand the hoisted note by default
15341525
const node = this.getActiveNode();
1535-
if (node?.data.noteId === this.noteContext.hoistedNoteId){
1526+
if (node && node.data.noteId === this.noteContext.hoistedNoteId){
15361527
this.setExpanded(node.data.branchId, true);
15371528
}
15381529
}

0 commit comments

Comments
 (0)