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
fix(views/table): error when adding a new row
Elian Doranada39cd3c7cc
diff --git a/apps/client/src/widgets/view_widgets/table_view/data.ts b/apps/client/src/widgets/view_widgets/table_view/data.tsindex ef76c477b2..1eb6faebdf 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<TableData>["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.tsindex 1d299c9c0f..399de47247 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<StateInfo> {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<StateInfo> {}}- 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<StateInfo> {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;