Skip to content

Build your personal knowledge base with Trilium Notes

feat(views/table): allow limiting depth

Elian Doran876c6e925219
diff --git a/apps/client/src/widgets/view_widgets/table_view/index.ts b/apps/client/src/widgets/view_widgets/table_view/index.ts
index 9fb165a8df..3e2f42e6b3 100644
--- a/apps/client/src/widgets/view_widgets/table_view/index.ts
+++ b/apps/client/src/widgets/view_widgets/table_view/index.ts
@@ -104,6 +104,7 @@ export default class TableView extends ViewMode<StateInfo> {
private persistentData: StateInfo["tableData"];
private colEditing?: TableColumnEditing;
private rowEditing?: TableRowEditing;
+ private maxDepth: number = -1;
constructor(args: ViewModeArgs) {
super(args, "table");
@@ -135,7 +136,8 @@ export default class TableView extends ViewMode<StateInfo> {
const viewStorage = await this.viewStorage.restore();
this.persistentData = viewStorage?.tableData || {};
- const { definitions: rowData, hasSubtree: hasChildren } = await buildRowDefinitions(this.parentNote, info);
+ this.maxDepth = parseInt(this.parentNote.getLabelValue("maxNestingDepth") ?? "-1", 10);
+ const { definitions: rowData, hasSubtree: hasChildren } = await buildRowDefinitions(this.parentNote, info, this.maxDepth);
const movableRows = canReorderRows(this.parentNote) && !hasChildren;
const columnDefs = buildColumnDefinitions(info, movableRows, this.persistentData.columns);
let opts: Options = {
@@ -203,6 +205,12 @@ export default class TableView extends ViewMode<StateInfo> {
return await this.#manageRowsUpdate();
}
+ // Refresh max depth
+ if (loadResults.getAttributeRows().find(attr => attr.type === "label" && attr.name === "maxNestingDepth" && attributes.isAffecting(attr, this.parentNote))) {
+ this.maxDepth = parseInt(this.parentNote.getLabelValue("maxNestingDepth") ?? "-1", 10);
+ return await this.#manageRowsUpdate();
+ }
+
if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))
|| loadResults.getNoteIds().some(noteId => this.noteIds.includes(noteId)
|| loadResults.getAttributeRows().some(attr => this.noteIds.includes(attr.noteId!)))) {
@@ -235,7 +243,7 @@ export default class TableView extends ViewMode<StateInfo> {
}
const info = getAttributeDefinitionInformation(this.parentNote);
- const { definitions, hasSubtree } = await buildRowDefinitions(this.parentNote, info);
+ const { definitions, hasSubtree } = await buildRowDefinitions(this.parentNote, info, this.maxDepth);
// Force a refresh if the data tree needs enabling/disabling.
if (this.api.options.dataTree !== hasSubtree) {
diff --git a/apps/client/src/widgets/view_widgets/table_view/rows.ts b/apps/client/src/widgets/view_widgets/table_view/rows.ts
index 615dd7f9be..3ab5cda9cc 100644
--- a/apps/client/src/widgets/view_widgets/table_view/rows.ts
+++ b/apps/client/src/widgets/view_widgets/table_view/rows.ts
@@ -12,7 +12,7 @@ export type TableData = {
_children?: TableData[];
};
-export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDefinitionInformation[]) {
+export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDefinitionInformation[], maxDepth = -1, currentDepth = 0) {
const definitions: TableData[] = [];
let hasSubtree = false;
for (const branch of parentNote.getChildBranches()) {
@@ -40,8 +40,8 @@ export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDef
branchId: branch.branchId,
}
- if (note.hasChildren()) {
- def._children = (await buildRowDefinitions(note, infos)).definitions;
+ if (note.hasChildren() && (maxDepth < 0 || currentDepth < maxDepth)) {
+ def._children = (await buildRowDefinitions(note, infos, maxDepth, currentDepth + 1)).definitions;
hasSubtree = true;
}