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(views/table): support recursive children update
Elian Doran402540f48326
diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.tsindex 15ba79c229..ad5f0e556f 100644--- a/apps/client/src/entities/fnote.ts+++ b/apps/client/src/entities/fnote.ts@@ -259,6 +259,7 @@ class FNote {async getSubtreeNoteIds() {let noteIds: (string | string[])[] = [];for (const child of await this.getChildNotes()) {+ noteIds.push(child.noteId);noteIds.push(await child.getSubtreeNoteIds());}return noteIds.flat();diff --git a/apps/client/src/services/note_list_renderer.ts b/apps/client/src/services/note_list_renderer.tsindex 1f9719b8ea..8e4a6312e8 100644--- a/apps/client/src/services/note_list_renderer.ts+++ b/apps/client/src/services/note_list_renderer.ts@@ -6,33 +6,18 @@ import TableView from "../widgets/view_widgets/table_view/index.js";import type { ViewModeArgs } from "../widgets/view_widgets/view_mode.js";import type ViewMode from "../widgets/view_widgets/view_mode.js";+export type ArgsWithoutNoteId = Omit<ViewModeArgs, "noteIds">;export type ViewTypeOptions = "list" | "grid" | "calendar" | "table" | "geoMap";export default class NoteListRenderer {private viewType: ViewTypeOptions;- public viewMode: ViewMode<any> | null;+ private args: ArgsWithoutNoteId;+ public viewMode?: ViewMode<any>;- constructor(args: ViewModeArgs) {+ constructor(args: ArgsWithoutNoteId) {+ this.args = args;this.viewType = this.#getViewType(args.parentNote);-- switch (this.viewType) {- case "list":- case "grid":- this.viewMode = new ListOrGridView(this.viewType, args);- break;- case "calendar":- this.viewMode = new CalendarView(args);- break;- case "table":- this.viewMode = new TableView(args);- break;- case "geoMap":- this.viewMode = new GeoView(args);- break;- default:- this.viewMode = null;- }}#getViewType(parentNote: FNote): ViewTypeOptions {@@ -57,11 +42,36 @@ export default class NoteListRenderer {}async renderList() {- if (!this.viewMode) {- return null;+ const args = this.args;++ let noteIds: string[];+ if (this.viewType === "list" || this.viewType === "grid") {+ noteIds = args.parentNote.getChildNoteIds();+ } else {+ noteIds = await args.parentNote.getSubtreeNoteIds();}- return await this.viewMode.renderList();+ const viewMode = this.#buildViewMode({+ ...args,+ noteIds+ });+ this.viewMode = viewMode;+ return await viewMode.renderList();+ }++ #buildViewMode(args: ViewModeArgs) {+ switch (this.viewType) {+ case "calendar":+ return new CalendarView(args);+ case "table":+ return new TableView(args);+ case "geoMap":+ return new GeoView(args);+ case "list":+ case "grid":+ default:+ return new ListOrGridView(this.viewType, args);+ }}}diff --git a/apps/client/src/widgets/note_list.ts b/apps/client/src/widgets/note_list.tsindex 68687e63c2..65015039a5 100644--- a/apps/client/src/widgets/note_list.ts+++ b/apps/client/src/widgets/note_list.ts@@ -123,8 +123,7 @@ export default class NoteListWidget extends NoteContextAwareWidget {const noteListRenderer = new NoteListRenderer({$parent: this.$content,parentNote: note,- parentNotePath: this.notePath,- noteIds: note.getChildNoteIds()+ parentNotePath: this.notePath});this.$widget.toggleClass("full-height", noteListRenderer.isFullHeight);await noteListRenderer.renderList();diff --git a/apps/client/src/widgets/search_result.ts b/apps/client/src/widgets/search_result.tsindex a98e306b32..6fa69ae13f 100644--- a/apps/client/src/widgets/search_result.ts+++ b/apps/client/src/widgets/search_result.ts@@ -68,7 +68,6 @@ export default class SearchResultWidget extends NoteContextAwareWidget {const noteListRenderer = new NoteListRenderer({$parent: this.$content,parentNote: note,- noteIds: note.getChildNoteIds(),showNotePath: true});await noteListRenderer.renderList();