From d6b6fefcf7178fbe3daacb576cad15b8fc472232 Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Thu, 10 Apr 2025 02:30:35 -0400
Subject: conditionals kind of working for full template changes

---
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   | 36 +++++++++++++++++++---
 1 file changed, 32 insertions(+), 4 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 3cf9baa2c..de345a335 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -33,6 +33,7 @@ import { TemplateFieldSize, TemplateFieldType, TemplateLayouts } from './Templat
 import { TemplateManager } from './TemplateManager';
 import { DrawingFillHandler } from '../../../smartdraw/DrawingFillHandler';
 import { CgPathIntersect } from 'react-icons/cg';
+import { StaticContentField } from './TemplateFieldTypes/StaticContentField';
 
 export enum LayoutType {
     FREEFORM = 'Freeform',
@@ -649,6 +650,17 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
                                 const field = template.getFieldByID(Number(fieldID));
                                 field.setContent(col.defaultContent ?? '', col.type === TemplateFieldType.VISUAL ? ViewType.IMG : ViewType.TEXT);
                                 field.setTitle(col.title);
+                                this._conditions.filter(c => c.field === field.getTitle()).forEach(conditional => {
+                                    if (field.getContent() === conditional.condition){
+                                        if (conditional.target === 'self'){
+                                            field.renderedDoc![conditional.attribute] = conditional.value;
+                                            (field.settings.opts as any)[conditional.attribute] = conditional.value;
+                                        } else if (conditional.target === 'template'){
+                                            template._mainField!.renderedDoc![conditional.attribute] = conditional.value;
+                                            (template._mainField!.settings.opts as any)[conditional.attribute] = conditional.value;
+                                        }
+                                    }
+                                })
                             } else {
                                 a[Number(fieldID)] = this.getColByTitle(colTitle);
                             }
@@ -676,7 +688,6 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
         } else {
             this._dataViz?.updateColDefaults();
 
-            console.log('field infos are: ', this.fieldsInfos)
             templates.push(...this.templateManager.getValidTemplates(this.fieldsInfos));
 
             const assignments = await this.assignColsToFields(templates, this.fieldsInfos);
@@ -778,7 +789,23 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
                 .filter(title => title)
                 .forEach(title => {
                     const field = templateCopy.getFieldByTitle(title);
-                    if (field !== undefined) field.setContent(content[title], field.viewType);
+                    if (field !== undefined) {
+                        field.setContent(content[title], field.viewType);
+                        console.log('content set')
+                        this._conditions.filter(c => c.field === title).forEach(conditional => {
+                            console.log('in conditional')
+                            if (content[title] === conditional.condition){
+                                if (conditional.target === 'self'){
+                                    field.renderedDoc![conditional.attribute] = conditional.value;
+                                    (field.settings.opts as any)[conditional.attribute] = conditional.value;
+                                } else if (conditional.target === 'template'){
+                                    console.log('setting', conditional.attribute,  'to: ', conditional.value)
+                                    templateCopy._mainField!.renderedDoc![conditional.attribute] = conditional.value;
+                                    (templateCopy._mainField!.settings.opts as any)[conditional.attribute] = conditional.value;
+                                }
+                            }
+                        })
+                    }
                 });
 
             const gptFunc = (type: TemplateFieldType) => (type === TemplateFieldType.VISUAL ? this.renderGPTImageCall : this.renderGPTTextCall);
@@ -1337,7 +1364,7 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
     }
 
     get dashboardContents() {
-        const conditionForm = (title: String, parameters?: Conditional) => {
+        const conditionForm = (title: string, parameters?: Conditional) => {
 
             const params: Conditional = parameters ?? this._currEditingConditional;
 
@@ -1358,7 +1385,7 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
                         placeholder='value'
                         defaultValue={params.condition}
                     />
-                    <div className='form-row-plain-text'>Then</div>
+                    <div className='form-row-plain-text'>then</div>
                     <div className="operator-options-dropdown">
                         <span className="operator-dropdown-current">{params.target ?? 'self'}</span>
                         <div className='operator-dropdown-option' onPointerDown={() => {params.target = 'self'}}>{'self'}</div>
@@ -1380,6 +1407,7 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
                 </div>
                 <div className='form-action-button' onPointerDown={e => this.setUpButtonClick(e, runInAction(() => () => {
                         if (this._currEditingConditional === params) { 
+                            params.field = title;
                             this._conditions.push(params);
                             this._currEditingConditional = {} as Conditional;
                         } else {
-- 
cgit v1.2.3-70-g09d2

