refactor(views/table): integrate parser into data

This commit is contained in:
Elian Doran 2025-06-27 17:43:19 +03:00
parent e66aef17df
commit 0b74de275c
No known key found for this signature in database
3 changed files with 29 additions and 34 deletions

View File

@ -2,8 +2,7 @@ import froca from "../../services/froca.js";
import ViewMode, { type ViewModeArgs } from "./view_mode.js";
import { createGrid, AllCommunityModule, ModuleRegistry, GridOptions } from "ag-grid-community";
import { setLabel } from "../../services/attributes.js";
import getPromotedAttributeInformation from "./table_view/parser.js";
import { buildData, TableData } from "./table_view/data.js";
import getPromotedAttributeInformation, { buildData, TableData } from "./table_view/data.js";
import applyHeaderCustomization from "./table_view/header-customization.js";
import server from "../../services/server.js";
import type { GridState } from "ag-grid-community";

View File

@ -1,7 +1,6 @@
import { GridOptions } from "ag-grid-community";
import FNote from "../../../entities/fnote.js";
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
import { default as getPromotedAttributeInformation, type PromotedAttributeInformation } from "./parser.js";
export type TableData = {
noteId: string;
@ -9,6 +8,11 @@ export type TableData = {
labels: Record<string, boolean | string | null>;
};
export interface PromotedAttributeInformation {
name: string;
title?: string;
type?: LabelType;
}
type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object';
@ -84,3 +88,26 @@ export function buildRowDefinitions(notes: FNote[], infos: PromotedAttributeInfo
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;
}
info.push({
name: promotedAttribute.name.split(":", 2)[1],
title: def.promotedAlias,
type: def.labelType
})
}
return info;
}

View File

@ -1,31 +0,0 @@
import FNote from "../../../entities/fnote";
import { LabelType } from "../../../services/promoted_attribute_definition_parser";
export interface PromotedAttributeInformation {
name: string;
title?: string;
type?: LabelType;
}
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;
}
info.push({
name: promotedAttribute.name.split(":", 2)[1],
title: def.promotedAlias,
type: def.labelType
})
}
return info;
}