feat(book/table): support date type

This commit is contained in:
Elian Doran
2025-06-25 11:56:30 +03:00
parent 7c175da9f1
commit d9443527ee
2 changed files with 20 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
type LabelType = "text" | "number" | "boolean" | "date" | "datetime" | "time" | "url";
export type LabelType = "text" | "number" | "boolean" | "date" | "datetime" | "time" | "url";
type Multiplicity = "single" | "multi";
export interface DefinitionObject {

View File

@@ -1,10 +1,13 @@
import { GridOptions } from "ag-grid-community";
import FNote from "../../../entities/fnote";
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
type Data = {
title: string;
} & Record<string, string>;
type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object';
export function buildData(parentNote: FNote, notes: FNote[]) {
const { columnDefs, expectedLabels } = buildColumnDefinitions(parentNote);
const rowData = buildRowDefinitions(notes, expectedLabels);
@@ -42,7 +45,8 @@ export function buildColumnDefinitions(parentNote: FNote) {
columnDefs.push({
field: attributeName,
headerName: title
headerName: title,
cellDataType: mapDataType(def.labelType)
});
expectedLabels.push(attributeName);
}
@@ -50,6 +54,20 @@ export function buildColumnDefinitions(parentNote: FNote) {
return { columnDefs, expectedLabels };
}
function mapDataType(labelType: LabelType | undefined): GridLabelType {
if (!labelType) {
return "text";
}
switch (labelType) {
case "date":
return "dateString";
case "text":
default:
return "text"
}
}
export function buildRowDefinitions(notes: FNote[], expectedLabels: string[]): GridOptions<Data>["rowData"] {
const definitions: GridOptions<Data>["rowData"] = [];
for (const note of notes) {