From 5be235c8ca1b4ad5d499fac96133e77c773b7c6d Mon Sep 17 00:00:00 2001 From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> Date: Mon, 12 May 2025 01:27:50 -0400 Subject: data fields --- .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx | 93 ++++++++++++---------- 1 file changed, 49 insertions(+), 44 deletions(-) (limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx') diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx index 2565a9332..873bfa734 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx @@ -30,7 +30,7 @@ import './DocCreatorMenu.scss'; import { TemplateField, ViewType } from './TemplateFieldTypes/TemplateField'; import { Template } from './Template'; import { TemplateFieldSize, TemplateFieldType, TemplateLayouts } from './TemplateBackend'; -import { TemplateManager } from './Backend/TemplateManager'; +import { Conditional, TemplateManager } from './Backend/TemplateManager'; import { DrawingFillHandler } from '../../../smartdraw/DrawingFillHandler'; import { CgPathIntersect } from 'react-icons/cg'; import { StaticContentField } from './TemplateFieldTypes/StaticContentField'; @@ -71,15 +71,6 @@ export type Col = { AIGenerated?: boolean; }; -export type Conditional = { - field: string; - operator: '=' | '>' | '<'; - condition: string; - target: 'self' | 'template'; - attribute: string; - value: string; -} - interface DocCreateMenuProps { addDocTab: (doc: Doc | Doc[], where: OpenWhere) => boolean; } @@ -364,15 +355,6 @@ export class DocCreatorMenu extends ObservableReactComponent this._pageY = y + translation.y; }; - async getIcon(doc: Doc) { - const docView = DocumentView.getDocumentView(doc); - if (docView) { - docView.ComponentView?.updateIcon?.(); - return new Promise(res => setTimeout(() => res(ImageCast(docView.Document.icon)), 500)); - } - return undefined; - } - @action updateRenderedPreviewCollection = async (template: Template) => { this._docsRendering = true; this._fullyRenderedDocs = this._dataViz ? ((await this.templateManager.createDocsFromTemplate(this._dataViz, template, this.fieldsInfos, this.DEBUG_MODE)).filter(doc => doc).map(doc => doc!) ?? []) as unknown as Doc[] : []; @@ -469,11 +451,18 @@ export class DocCreatorMenu extends ObservableReactComponent }; @action setColType = (column: Col, type: TemplateFieldType) => { + if (type === TemplateFieldType.DATA) { + this.templateManager.addDataField(column.title); + } else if (column.type === TemplateFieldType.DATA) { + this.templateManager.removeDataField(column.title); + } + if (this.selectedFields.includes(column.title)) { this._dataViz?.setColumnType(column.title, type); } else { column.type = type; } + this.forceUpdate(); }; @@ -576,9 +565,11 @@ export class DocCreatorMenu extends ObservableReactComponent } else { this._dataViz?.updateColDefaults(); - templates.push(...this.templateManager.getValidTemplates(this.fieldsInfos)); + const contentFields = this.fieldsInfos.filter(field => field.type !== TemplateFieldType.DATA); + + templates.push(...this.templateManager.getValidTemplates(contentFields)); - const assignments = await this.assignColsToFields(templates, this.fieldsInfos); + const assignments = await this.assignColsToFields(templates, contentFields); const renderedTemplatePromises = assignments.map(([template, assgns]) => TemplateMenuAIUtils.applyGPTContentToTemplate(template, assgns)); @@ -918,6 +909,8 @@ export class DocCreatorMenu extends ObservableReactComponent } get dashboardContents() { + const contentFieldTitles = this.fieldsInfos.filter(field => field.type !== TemplateFieldType.DATA).map(field => field.title).concat('template'); + const conditionForm = (title: string, parameters?: Conditional, empty: boolean = false) => { const params: Conditional = parameters ?? this._currEditingConditional; @@ -942,8 +935,9 @@ export class DocCreatorMenu extends ObservableReactComponent
then
{params.target ?? 'self'} -
{params.target = 'self'}}>{'own'}
-
{params.target = 'template'}}>{`template's`}
+ {contentFieldTitles.map(fieldTitle => +
{params.target = fieldTitle}}>{fieldTitle === title ? 'own' : fieldTitle}
+ )}