chore(views/table): support more data types

This commit is contained in:
Elian Doran 2025-06-28 23:29:31 +03:00
parent 09b800b9ad
commit e7ca56e061
No known key found for this signature in database

View File

@ -17,6 +17,35 @@ export interface PromotedAttributeInformation {
type?: LabelType;
}
const labelTypeMappings: Record<LabelType, Partial<ColumnDefinition>> = {
text: {
editor: "input"
},
boolean: {
formatter: "tickCross",
editor: "tickCross"
},
date: {
formatter: "datetime",
editor: "date",
},
datetime: {
formatter: "datetime",
editor: "datetime"
},
number: {
editor: "number"
},
time: {
formatter: "datetime",
editor: "datetime"
},
url: {
formatter: "link",
editor: "input"
}
};
type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object';
export async function buildData(parentNote: FNote, info: PromotedAttributeInformation[], notes: FNote[]) {
@ -69,8 +98,8 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
columnDefs.push({
field: `labels.${name}`,
title: title ?? name,
editor: "input"
// cellDataType: mapDataType(type),
editor: "input",
...labelTypeMappings[type ?? "text"],
});
}
@ -93,24 +122,6 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
return columnDefs;
}
function mapDataType(labelType: LabelType | undefined): GridLabelType {
if (!labelType) {
return "text";
}
switch (labelType) {
case "number":
return "number";
case "boolean":
return "boolean";
case "date":
return "dateString";
case "text":
default:
return "text"
}
}
export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: PromotedAttributeInformation[]) {
const definitions: GridOptions<TableData>["rowData"] = [];
for (const branch of parentNote.getChildBranches()) {