From 39d02461d9c530996cdcd5fbac4fe3a932550c4a Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Mon, 2 Sep 2024 05:11:55 -0400
Subject: gpt provides more basic info + slight refactor started (ofc it didn't
 work first try >_<)

---
 src/client/views/nodes/DataVizBox/DataVizBox.tsx | 59 ++++++++++++++++--------
 1 file changed, 41 insertions(+), 18 deletions(-)

(limited to 'src/client/views/nodes/DataVizBox/DataVizBox.tsx')

diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
index 82df141fa..c72aa1711 100644
--- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx
+++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
@@ -33,7 +33,7 @@ import { LineChart } from './components/LineChart';
 import { PieChart } from './components/PieChart';
 import { TableBox } from './components/TableBox';
 import { LinkManager } from '../../../util/LinkManager';
-import { DataVizTemplateInfo, DataVizTemplateLayout, DocCreatorMenu, LayoutType, TemplateFieldType } from './DocCreatorMenu';
+import { Col, DataVizTemplateInfo, DataVizTemplateLayout, DocCreatorMenu, TemplateFieldSize, LayoutType, TemplateFieldType } from './DocCreatorMenu';
 import { CollectionFreeFormView, MarqueeView } from '../../collections/collectionFreeForm';
 import { PrefetchProxy } from '../../../../fields/Proxy';
 import { AclAdmin, AclAugment, AclEdit } from '../../../../fields/DocSymbols';
@@ -43,6 +43,7 @@ import { listSpec } from '../../../../fields/Schema';
 import { ObjectField } from '../../../../fields/ObjectField';
 import { Id } from '../../../../fields/FieldSymbols';
 import { GPTCallType, gptAPICall } from '../../../apis/gpt/GPT';
+import { TbSortDescendingShapes } from 'react-icons/tb';
 
 export enum DataVizView {
     TABLE = 'table',
@@ -64,9 +65,8 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
     @observable _marqueeing: number[] | undefined = undefined;
     @observable _savedAnnotations = new ObservableMap<number, HTMLDivElement[]>();
     @observable _specialHighlightedRow: number | undefined = undefined;
-    @observable GPTSummary: ObservableMap<string, string> | undefined = undefined;
-    @observable colDescriptions: ObservableMap<string, string> = new ObservableMap();
-    @observable fieldTypes: ObservableMap<string, TemplateFieldType> = new ObservableMap();
+    @observable GPTSummary: ObservableMap<string, {desc?: string, type?: TemplateFieldType, size?: TemplateFieldSize}> | undefined = undefined;
+    @observable colsInfo: ObservableMap<string, Col> = new ObservableMap();
     @observable _GPTLoading: boolean = false;
 
     constructor(props: FieldViewProps) {
@@ -155,24 +155,26 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
         this._specialHighlightedRow = row;
     }
 
-    @action setFieldType = (field: string, type: TemplateFieldType) => {
-        this.fieldTypes?.set(field, type);
+    @action setColumnType = (field: string, type: TemplateFieldType) => {
+        const colInfo = this.colsInfo.get(field);
+        if (colInfo) { colInfo.type = type };
     }
 
-    @action setFieldDesc = (field: string, desc: string) => {
-        if (!desc) { 
-            this.colDescriptions.set(field, this.GPTSummary?.get(field) ?? '');
-        } else {
-            this.colDescriptions.set(field, desc);
-        }
+    @action setColumnSize = (field: string, size: TemplateFieldSize) => {
+        const colInfo = this.colsInfo.get(field);
+        if (colInfo) { colInfo.size = size };
     }
 
-    getFieldType = (field: string): TemplateFieldType => {
-        return this.fieldTypes?.get(field) ?? TemplateFieldType.UNSET;
+    @action setColumnDesc = (field: string, desc: string) => {
+        const colInfo = this.colsInfo.get(field);
+        if (colInfo) {
+            if (!desc) { colInfo.desc = this.GPTSummary?.get(field)?.desc ?? ''; } 
+            else { colInfo.desc = desc; }
+        }
     }
 
-    getFieldDescription = (field: string): string => {
-        return this.colDescriptions?.get(field) ?? '';
+    @computed get colInfo(){
+        return this.colsInfo;
     }
 
     @action // pinned / linked anchor doc includes selected rows, graph titles, and graph colors
@@ -549,8 +551,29 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                 this.GPTSummary = new ObservableMap();
                 const descs: {[col: string]: string} = JSON.parse(res);
                 for (const [key, val] of Object.entries(descs)) {
-                    this.GPTSummary.set(key, val);
-                    if (!this.colDescriptions.get(key)) this.colDescriptions.set(key, val);
+                    this.GPTSummary.set(key, {desc: val});
+                    if (!this.colsInfo.get(key)?.desc) this.setColumnDesc(key, val);
+                }
+            }
+        } catch (err) {
+            console.error(err);
+        } 
+
+        try {
+            const res = await gptAPICall('Info:' + prompt, GPTCallType.VIZSUM2);
+
+            if (res) {
+                !this.GPTSummary && (this.GPTSummary = new ObservableMap());
+                const info: {[col: string]: {type: TemplateFieldType, size: TemplateFieldSize}} = JSON.parse(res);
+                console.log(info)
+                for (const [key, val] of Object.entries(info)) {
+                    const colSummary = this.GPTSummary.get(key);
+                    if (colSummary) {
+                        colSummary.size = val.size;
+                        colSummary.type = val.type;
+                        this.setColumnType(key, val.type);
+                        this.setColumnSize(key, val.size);
+                    }
                 }
 
             }
-- 
cgit v1.2.3-70-g09d2

