From f5dc4de1c123e929a7c893ae9ef10c30fafd9f28 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 4 Jul 2025 14:12:36 +0300 Subject: [PATCH] feat(views/table): parse relations --- .../widgets/view_widgets/table_view/data.ts | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) 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 3ad275821..1cc8b19e7 100644 --- a/apps/client/src/widgets/view_widgets/table_view/data.ts +++ b/apps/client/src/widgets/view_widgets/table_view/data.ts @@ -15,7 +15,7 @@ export type TableData = { export interface PromotedAttributeInformation { name: string; title?: string; - type?: LabelType; + type?: LabelType | "relation"; } const labelTypeMappings: Record> = { @@ -130,7 +130,9 @@ export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], inf const labels: typeof definitions[0]["labels"] = {}; for (const { name, type } of infos) { - if (type === "boolean") { + if (type === "relation") { + labels[name] = note.getRelationValue(name); + } else if (type === "boolean") { labels[name] = note.hasLabel(name); } else { labels[name] = note.getLabelValue(name); @@ -146,28 +148,37 @@ export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], inf }); } + console.log("Built row definitions", definitions); + return definitions; } export default function getPromotedAttributeInformation(parentNote: FNote) { const info: PromotedAttributeInformation[] = []; for (const promotedAttribute of parentNote.getPromotedDefinitionAttributes()) { - if (promotedAttribute.type !== "label") { - console.warn("Relations are not supported for now"); - continue; - } - const def = promotedAttribute.getDefinition(); if (def.multiplicity !== "single") { console.warn("Multiple values are not supported for now"); continue; } + const [ labelType, name ] = promotedAttribute.name.split(":", 2); + if (promotedAttribute.type !== "label") { + console.warn("Relations are not supported for now"); + continue; + } + + let type: LabelType | "relation" = def.labelType || "text"; + if (labelType === "relation") { + type = "relation"; + } + info.push({ - name: promotedAttribute.name.split(":", 2)[1], + name, title: def.promotedAlias, - type: def.labelType - }) + type + }); } + console.log("Promoted attribute information", info); return info; }