diff options
5 files changed, 56 insertions, 41 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx index 6f3647133..faa6cffa8 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx @@ -568,17 +568,13 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { let prompt: string = `(${origCount}) ${inputText}`; - console.log('prompt is: ', prompt) - this._GPTLoading = true; try { const res = await gptAPICall(prompt, GPTCallType.TEMPLATE); if (res) { - console.log('res is: ', res) const assignments: { [templateTitle: string]: { [fieldID: string]: string } } = JSON.parse(res); - console.log('assignments: ', assignments) const brokenDownAssignments: [Template, { [fieldID: number]: Col }][] = []; Object.entries(assignments).forEach(([tempTitle, assignment]) => { @@ -598,9 +594,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { }, {} as { [field: number]: Col } ); - console.log('all assignments: ', toObj) brokenDownAssignments.push([template, toObj]); - console.log('brokendownassignments: ', brokenDownAssignments) }); return brokenDownAssignments; @@ -733,14 +727,14 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { fields.filter(title => title).forEach(title => { const field = templateCopy.getFieldByTitle(title); - if (field === undefined) { return }; - field.setContent(content[title]); + if (field === undefined) return; + field.setContent(content[title], field.viewType); }); const gptPromises = this._userCreatedFields.filter(field => field.type === TemplateFieldType.TEXT).map(field => { const title = field.title; const templateField = templateCopy.getFieldByTitle(title); - if (templateField === undefined) { return }; + if (templateField === undefined) return; const templatefieldID = templateField.getID; return this.renderGPTTextCall(templateCopy, field, templatefieldID); @@ -749,7 +743,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { const imagePromises = this._userCreatedFields.filter(field => field.type === TemplateFieldType.VISUAL).map(field => { const title = field.title; const templateField = templateCopy.getFieldByTitle(title); - if (templateField === undefined) { return }; + if (templateField === undefined) return; const templatefieldID = templateField.getID; return this.renderGPTImageCall(templateCopy, field, templatefieldID); diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx index e5f080645..7ffb1884e 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx @@ -32,7 +32,7 @@ export class DynamicField extends Field { // ); } - setContent = (content: string, type?: ViewType) => { return }; + setContent = (content: string, type: ViewType) => { return }; getContent = () => { return '' }; get isContentField(): boolean { return false }; diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx index 9427d6c5c..6c78e15ad 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx @@ -50,6 +50,7 @@ export abstract class Field { get getDimensions() { return this.dimensions }; get getID() { return this.id }; get getDescription(): string { return this.settings.description ?? '' }; + get viewType(): ViewType { return this.settings.viewType } setTitle = (title: string) => { this.title = title; @@ -58,9 +59,20 @@ export abstract class Field { getTitle = () => { return this.title }; abstract get isContentField(): boolean; - abstract setContent(content: string, type?: ViewType): void; + abstract setContent(content: string, type: ViewType): void; abstract getContent(): string; + changeFieldType = (newType: ViewType): Field => { + this.settings.viewType = newType; + const newField: Field = this.initField(this.settings, this.id, this.parent); + this.parent.exchangeFields(newField, this); + return newField; + } + + exchangeFields = (newField: Field, oldField: Field) => { + this.subfields.splice(this.subfields.indexOf(oldField), 1, newField); + } + setupFieldChangeReaction = () => { } diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx index baa5e71ec..627d3a939 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx @@ -5,6 +5,7 @@ import { Field, FieldDimensions, FieldSettings, ViewType } from "./Field"; import { RichTextField } from "../../../../../../fields/RichTextField"; import { DocData } from "../../../../../../fields/DocSymbols"; import { ImageField } from "../../../../../../fields/URLField"; +import { ViewComponentType } from "@fullcalendar/core"; export abstract class StaticContentField extends Field { @@ -19,7 +20,7 @@ export abstract class StaticContentField extends Field { this.subfields = this.setupSubfields(this); }; - abstract setContent(content: string, type?: ViewType): void; + abstract setContent(content: string, type: ViewType): void; getContent = () => { return this.content ?? 'unset'}; get isContentField(): boolean { return true }; @@ -35,10 +36,15 @@ export class ImageTemplateField extends StaticContentField { this.renderedDocument = this.initRenderedDoc(); } - setContent = (url: string, type?: ViewType) => { - const imgField = new ImageField(url); - this.renderedDocument[DocData]['data'] = imgField; - this.content = url; + setContent = (url: string, type: ViewType) => { + if (type === ViewType.IMG){ + const imgField = new ImageField(url); + this.renderedDocument[DocData]['data'] = imgField; + this.content = url; + } else { + const updatedField = this.changeFieldType(type); + updatedField.setContent(url, type); + } }; initRenderedDoc = (): Doc => { @@ -64,29 +70,33 @@ export class TextTemplateField extends StaticContentField { this.renderedDocument = this.initRenderedDoc(); } - setContent = (text: string) => { - console.log('content set to: ', text); - const rtf = { - doc: { - type: 'doc', - content: [ - { - type: 'paragraph', - content: [ - { - type: 'text', - text, - }, - ], - }, - ], - }, - selection: { type: 'text', anchor: 1, head: 1 }, - storedMarks: [], - }; - this.content = text; - const field = new RichTextField(JSON.stringify(rtf), text); - this.renderedDocument[DocData]['text'] = field; + setContent = (text: string, type: ViewType) => { + if (type === ViewType.TEXT) { + const rtf = { + doc: { + type: 'doc', + content: [ + { + type: 'paragraph', + content: [ + { + type: 'text', + text, + }, + ], + }, + ], + }, + selection: { type: 'text', anchor: 1, head: 1 }, + storedMarks: [], + }; + this.content = text; + const field = new RichTextField(JSON.stringify(rtf), text); + this.renderedDocument[DocData]['text'] = field; + } else { + const updatedField = this.changeFieldType(type); + updatedField.setContent(text, type); + } }; initRenderedDoc = (): Doc => { diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx index 178af3df6..a80df8468 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx @@ -19,7 +19,6 @@ export class Template { makeAutoObservable(this); this.settings = templateInfo; this.mainField = this.setupMainField(templateInfo); - console.log(templateInfo); } get childFields(): Field[] { return this.mainField.getSubfields }; |