diff options
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DataVizBox.tsx')
-rw-r--r-- | src/client/views/nodes/DataVizBox/DataVizBox.tsx | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx index c72aa1711..6888d5f1e 100644 --- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx +++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx @@ -155,26 +155,43 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { this._specialHighlightedRow = row; } - @action setColumnType = (field: string, type: TemplateFieldType) => { - const colInfo = this.colsInfo.get(field); - if (colInfo) { colInfo.type = type }; + @action setColumnType = (colTitle: string, type: TemplateFieldType) => { + const colInfo = this.colsInfo.get(colTitle); + console.log(colInfo) + if (colInfo) { + colInfo.type = type; + } else { + this.colsInfo.set(colTitle, {title: colTitle, desc: '', type: type, size: TemplateFieldSize.MEDIUM}) + } + console.log(colInfo?.title, colInfo?.type) } - @action setColumnSize = (field: string, size: TemplateFieldSize) => { - const colInfo = this.colsInfo.get(field); - if (colInfo) { colInfo.size = size }; + @action setColumnSize = (colTitle: string, size: TemplateFieldSize) => { + const colInfo = this.colsInfo.get(colTitle); + if (colInfo) { + colInfo.size = size; + } else { + this.colsInfo.set(colTitle, {title: colTitle, desc: '', type: TemplateFieldType.UNSET, size: size}) + } } - @action setColumnDesc = (field: string, desc: string) => { - const colInfo = this.colsInfo.get(field); + @action setColumnDesc = (colTitle: string, desc: string) => { + const colInfo = this.colsInfo.get(colTitle); if (colInfo) { - if (!desc) { colInfo.desc = this.GPTSummary?.get(field)?.desc ?? ''; } + if (!desc) { colInfo.desc = this.GPTSummary?.get(colTitle)?.desc ?? ''; } else { colInfo.desc = desc; } + } else { + this.colsInfo.set(colTitle, {title: colTitle, desc: desc, type: TemplateFieldType.UNSET, size: TemplateFieldSize.MEDIUM}) } } - @computed get colInfo(){ - return this.colsInfo; + @action setColumnDefault = (colTitle: string, cont: string) => { + const colInfo = this.colsInfo.get(colTitle); + if (colInfo) { + colInfo.defaultContent = cont; + } else { + this.colsInfo.set(colTitle, {title: colTitle, desc: '', type: TemplateFieldType.UNSET, size: TemplateFieldSize.MEDIUM, defaultContent: cont}) + } } @action // pinned / linked anchor doc includes selected rows, graph titles, and graph colors @@ -529,7 +546,7 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { prompt += '----------- Rows: ' - rowsToCheck.forEach(row => { + rowsToCheck.forEach((row, i) => { prompt += `Row #${row}: ` cols.forEach(col => { prompt += `${col}: ${this.records[row][col]} -----` @@ -539,11 +556,35 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { return prompt; } + updateColDefaults = () => { + let possibleIds: number[] = this.records.map((_, index) => index); + + for (let i = possibleIds.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [possibleIds[i], possibleIds[j]] = [possibleIds[j], possibleIds[i]]; + } + + const rowToCheck = possibleIds[0]; + + const cols = Array.from(Object.keys(this.records[0])).filter(header => header !== '' && header !== undefined); + + cols.forEach(col => { + this.setColumnDefault(col, `${this.records[rowToCheck][col]}`) + }); + } + updateGPTSummary = async () => { this._GPTLoading = true; + this.updateColDefaults(); + const prompt = this.getColSummary(); + const cols = Array.from(Object.keys(this.records[0])).filter(header => header !== '' && header !== undefined); + cols.forEach(col => { + if (!this.colsInfo.get(col)) this.colsInfo.set(col, {title: col, desc: '', size: TemplateFieldSize.MEDIUM, type: TemplateFieldType.UNSET}); + }); + try { const res = await gptAPICall(prompt, GPTCallType.VIZSUM); |