feat(views/table): parse relations

This commit is contained in:
Elian Doran 2025-07-04 14:12:36 +03:00
parent d8cb5efd2d
commit f5dc4de1c1
No known key found for this signature in database

View File

@ -15,7 +15,7 @@ export type TableData = {
export interface PromotedAttributeInformation { export interface PromotedAttributeInformation {
name: string; name: string;
title?: string; title?: string;
type?: LabelType; type?: LabelType | "relation";
} }
const labelTypeMappings: Record<LabelType, Partial<ColumnDefinition>> = { const labelTypeMappings: Record<LabelType, Partial<ColumnDefinition>> = {
@ -130,7 +130,9 @@ export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], inf
const labels: typeof definitions[0]["labels"] = {}; const labels: typeof definitions[0]["labels"] = {};
for (const { name, type } of infos) { 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); labels[name] = note.hasLabel(name);
} else { } else {
labels[name] = note.getLabelValue(name); 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; return definitions;
} }
export default function getPromotedAttributeInformation(parentNote: FNote) { export default function getPromotedAttributeInformation(parentNote: FNote) {
const info: PromotedAttributeInformation[] = []; const info: PromotedAttributeInformation[] = [];
for (const promotedAttribute of parentNote.getPromotedDefinitionAttributes()) { for (const promotedAttribute of parentNote.getPromotedDefinitionAttributes()) {
if (promotedAttribute.type !== "label") {
console.warn("Relations are not supported for now");
continue;
}
const def = promotedAttribute.getDefinition(); const def = promotedAttribute.getDefinition();
if (def.multiplicity !== "single") { if (def.multiplicity !== "single") {
console.warn("Multiple values are not supported for now"); console.warn("Multiple values are not supported for now");
continue; 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({ info.push({
name: promotedAttribute.name.split(":", 2)[1], name,
title: def.promotedAlias, title: def.promotedAlias,
type: def.labelType type
}) });
} }
console.log("Promoted attribute information", info);
return info; return info;
} }