feat(views/table): allow limiting depth

This commit is contained in:
Elian Doran 2025-07-17 19:34:29 +03:00
parent aef824d262
commit 876c6e9252
No known key found for this signature in database
2 changed files with 13 additions and 5 deletions

View File

@ -104,6 +104,7 @@ export default class TableView extends ViewMode<StateInfo> {
private persistentData: StateInfo["tableData"]; private persistentData: StateInfo["tableData"];
private colEditing?: TableColumnEditing; private colEditing?: TableColumnEditing;
private rowEditing?: TableRowEditing; private rowEditing?: TableRowEditing;
private maxDepth: number = -1;
constructor(args: ViewModeArgs) { constructor(args: ViewModeArgs) {
super(args, "table"); super(args, "table");
@ -135,7 +136,8 @@ export default class TableView extends ViewMode<StateInfo> {
const viewStorage = await this.viewStorage.restore(); const viewStorage = await this.viewStorage.restore();
this.persistentData = viewStorage?.tableData || {}; 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 movableRows = canReorderRows(this.parentNote) && !hasChildren;
const columnDefs = buildColumnDefinitions(info, movableRows, this.persistentData.columns); const columnDefs = buildColumnDefinitions(info, movableRows, this.persistentData.columns);
let opts: Options = { let opts: Options = {
@ -203,6 +205,12 @@ export default class TableView extends ViewMode<StateInfo> {
return await this.#manageRowsUpdate(); 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 ?? "")) if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))
|| loadResults.getNoteIds().some(noteId => this.noteIds.includes(noteId) || loadResults.getNoteIds().some(noteId => this.noteIds.includes(noteId)
|| loadResults.getAttributeRows().some(attr => this.noteIds.includes(attr.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 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. // Force a refresh if the data tree needs enabling/disabling.
if (this.api.options.dataTree !== hasSubtree) { if (this.api.options.dataTree !== hasSubtree) {

View File

@ -12,7 +12,7 @@ export type TableData = {
_children?: 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[] = []; const definitions: TableData[] = [];
let hasSubtree = false; let hasSubtree = false;
for (const branch of parentNote.getChildBranches()) { for (const branch of parentNote.getChildBranches()) {
@ -40,8 +40,8 @@ export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDef
branchId: branch.branchId, branchId: branch.branchId,
} }
if (note.hasChildren()) { if (note.hasChildren() && (maxDepth < 0 || currentDepth < maxDepth)) {
def._children = (await buildRowDefinitions(note, infos)).definitions; def._children = (await buildRowDefinitions(note, infos, maxDepth, currentDepth + 1)).definitions;
hasSubtree = true; hasSubtree = true;
} }