diff --git a/apps/client/src/widgets/view_widgets/table_view/data.ts b/apps/client/src/widgets/view_widgets/table_view/data.ts index ef76c477b..1eb6faebd 100644 --- a/apps/client/src/widgets/view_widgets/table_view/data.ts +++ b/apps/client/src/widgets/view_widgets/table_view/data.ts @@ -20,9 +20,9 @@ export interface PromotedAttributeInformation { type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object'; -export function buildData(parentNote: FNote, info: PromotedAttributeInformation[], notes: FNote[]) { +export async function buildData(parentNote: FNote, info: PromotedAttributeInformation[], notes: FNote[]) { const columnDefs = buildColumnDefinitions(info); - const rowData = buildRowDefinitions(parentNote, notes, info); + const rowData = await buildRowDefinitions(parentNote, notes, info); return { rowData, @@ -75,10 +75,14 @@ function mapDataType(labelType: LabelType | undefined): GridLabelType { } } -export function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: PromotedAttributeInformation[]) { +export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: PromotedAttributeInformation[]) { const definitions: GridOptions["rowData"] = []; for (const branch of parentNote.getChildBranches()) { - const note = branch.getNoteFromCache(); + const note = await branch.getNote(); + if (!note) { + continue; // Skip if the note is not found + } + const labels: typeof definitions[0]["labels"] = {}; for (const { name, type } of infos) { if (type === "boolean") { 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 1d299c9c0..399de4724 100644 --- a/apps/client/src/widgets/view_widgets/table_view/index.ts +++ b/apps/client/src/widgets/view_widgets/table_view/index.ts @@ -95,7 +95,7 @@ export default class TableView extends ViewMode { const info = getPromotedAttributeInformation(this.parentNote); this.api.setColumns(buildColumnDefinitions(info)); - this.api.setData(buildRowDefinitions(this.parentNote, notes, info)); + this.api.setData(await buildRowDefinitions(this.parentNote, notes, info)); } private onSave() { @@ -201,7 +201,11 @@ export default class TableView extends ViewMode { } } - onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">): boolean | void { + async onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">): boolean | void { + if (!this.api) { + return; + } + // Refresh if promoted attributes get changed. if (loadResults.getAttributeRows().find(attr => attr.type === "label" && @@ -209,11 +213,13 @@ export default class TableView extends ViewMode { attributes.isAffecting(attr, this.parentNote))) { const info = getPromotedAttributeInformation(this.parentNote); const columnDefs = buildColumnDefinitions(info); - this.api?.setColumns(columnDefs) + this.api.setColumns(columnDefs) } if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId)) { - return true; + const notes = await froca.getNotes(this.args.noteIds); + const info = getPromotedAttributeInformation(this.parentNote); + this.api.setData(await buildRowDefinitions(this.parentNote, notes, info)); } return false;