mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
fix(views/table): error when adding a new row
This commit is contained in:
parent
b2d20af51a
commit
ada39cd3c7
@ -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") {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user