aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/apis/gpt/GPT.ts6
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx6
-rw-r--r--src/client/views/nodes/DataVizBox/components/TableBox.tsx187
-rw-r--r--src/client/views/nodes/formattedText/FormattedTextBox.tsx23
4 files changed, 139 insertions, 83 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts
index 2de87586b..8747a00a6 100644
--- a/src/client/apis/gpt/GPT.ts
+++ b/src/client/apis/gpt/GPT.ts
@@ -45,7 +45,7 @@ const gptAPICall = async (inputText: string, callType: GPTCallType, prompt?: any
};
const openai = new OpenAI(configuration);
- let usePrompt = prompt? opts.prompt+prompt: opts.prompt;
+ let usePrompt = prompt ? opts.prompt + prompt : opts.prompt;
let messages: ChatCompletionMessageParam[] = [
{ role: 'system', content: usePrompt },
{ role: 'user', content: inputText },
@@ -53,9 +53,9 @@ const gptAPICall = async (inputText: string, callType: GPTCallType, prompt?: any
const response = await openai.chat.completions.create({
model: opts.model,
- messages: messages,
- temperature: opts.temp,
max_tokens: opts.maxTokens,
+ temperature: opts.temp,
+ messages,
});
const content = response.choices[0].message.content;
return content;
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 3fab00968..079a5d977 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -1412,7 +1412,11 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
presentation_transition: 500,
annotationOn: this.Document,
});
- PresBox.pinDocView(anchor, { pinDocLayout: pinProps?.pinDocLayout, pinData: { ...(pinProps?.pinData ?? {}), pannable: !this.Document.isGroup, type_collection: true, filters: true } }, this.Document);
+ PresBox.pinDocView(
+ anchor,
+ { pinDocLayout: pinProps?.pinDocLayout, pinData: { ...(pinProps?.pinData ? { ...pinProps.pinData, poslayoutview: pinProps.pinData.dataview } : {}), pannable: !this.Document.isGroup, type_collection: true, filters: true } },
+ this.Document
+ );
if (addAsAnnotation) {
if (Cast(this.dataDoc[this._props.fieldKey + '_annotations'], listSpec(Doc), null) !== undefined) {
diff --git a/src/client/views/nodes/DataVizBox/components/TableBox.tsx b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
index 5578b10cb..7ad5a0e6b 100644
--- a/src/client/views/nodes/DataVizBox/components/TableBox.tsx
+++ b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
@@ -12,7 +12,7 @@ import { ObservableReactComponent } from '../../../ObservableReactComponent';
import { DocumentView } from '../../DocumentView';
import { DataVizView } from '../DataVizBox';
import './Chart.scss';
-import { undoBatch } from '../../../../util/UndoManager';
+import { undoable } from '../../../../util/UndoManager';
const { DATA_VIZ_TABLE_ROW_HEIGHT } = require('../../../global/globalCssVariables.module.scss'); // prettier-ignore
interface TableBoxProps {
Document: Doc;
@@ -41,9 +41,9 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
@observable settingTitle: boolean = false; // true when setting a title column
@observable hasRowsToFilter: boolean = false; // true when any rows are selected
@observable filtering: boolean = false; // true when the filtering menu is open
- @observable filteringColumn: any = ""; // column to filter
- @observable filteringType: string = "Value"; // "Value" or "Range"
- filteringVal: any[] = ["", ""]; // value or range to filter the column with
+ @observable filteringColumn: any = ''; // column to filter
+ @observable filteringType: string = 'Value'; // "Value" or "Range"
+ filteringVal: any[] = ['', '']; // value or range to filter the column with
@observable _scrollTop = -1;
@observable _tableHeight = 0;
@@ -59,7 +59,7 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
// then we need to remove any selected rows that are no longer part of the visualized dataset.
this._inputChangedDisposer = reaction(() => this._tableData.slice(), this.filterSelectedRowsDown, { fireImmediately: true });
const selected = NumListCast(this._props.layoutDoc.dataViz_selectedRows);
- if (selected.length>0) this.hasRowsToFilter = true;
+ if (selected.length > 0) this.hasRowsToFilter = true;
this.handleScroll();
}
componentWillUnmount() {
@@ -123,7 +123,7 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
} else selected?.push(rowId);
}
e.stopPropagation();
- this.hasRowsToFilter = (selected.length>0)? true : false;
+ this.hasRowsToFilter = selected.length > 0 ? true : false;
};
columnPointerDown = (e: React.PointerEvent, col: string) => {
@@ -164,9 +164,9 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
},
emptyFunction,
action(e => {
- if (e.shiftKey || this.settingTitle){
+ if (e.shiftKey || this.settingTitle) {
if (this.settingTitle) this.settingTitle = false;
- if (this._props.titleCol == col) this._props.titleCol = "";
+ if (this._props.titleCol == col) this._props.titleCol = '';
else this._props.titleCol = col;
this._props.selectTitleCol(this._props.titleCol);
} else {
@@ -183,45 +183,43 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
/**
* These functions handle the filtering popup for when the "filter" button is pressed to select rows
*/
- @undoBatch
- filter = (e: any) => {
+ filter = undoable((e: any) => {
var start: any;
var end: any;
- if (this.filteringType=="Range"){
- start = Number.isNaN(Number(this.filteringVal[0]))? this.filteringVal[0]: Number(this.filteringVal[0]);
- end = Number.isNaN(Number(this.filteringVal[1]))? this.filteringVal[1]: Number(this.filteringVal[1]);
+ if (this.filteringType === 'Range') {
+ start = Number.isNaN(Number(this.filteringVal[0])) ? this.filteringVal[0] : Number(this.filteringVal[0]);
+ end = Number.isNaN(Number(this.filteringVal[1])) ? this.filteringVal[1] : Number(this.filteringVal[1]);
}
this._tableDataIds.forEach(rowID => {
- if (this.filteringType=="Value"){
- if (this._props.records[rowID][this.filteringColumn]==this.filteringVal[0]) {
+ if (this.filteringType == 'Value') {
+ if (this._props.records[rowID][this.filteringColumn] == this.filteringVal[0]) {
if (!NumListCast(this._props.layoutDoc.dataViz_selectedRows).includes(rowID)) {
this.tableRowClick(e, rowID);
}
}
- }
- else {
- let compare = this._props.records[rowID][this.filteringColumn]
- if (!Number.isNaN(Number(compare))) compare = Number(compare)
- if (start<=compare && compare<=end){
+ } else {
+ let compare = this._props.records[rowID][this.filteringColumn];
+ if (compare as Number) compare = Number(compare);
+ if (start <= compare && compare <= end) {
if (!NumListCast(this._props.layoutDoc.dataViz_selectedRows).includes(rowID)) {
this.tableRowClick(e, rowID);
}
}
}
- })
+ });
this.filtering = false;
- this.filteringColumn = "";
- this.filteringVal = ["", ""];
- }
+ this.filteringColumn = '';
+ this.filteringVal = ['', ''];
+ }, 'filter table');
@action
- setFilterColumn = (e:any) => {
+ setFilterColumn = (e: any) => {
this.filteringColumn = e.currentTarget.value;
- }
+ };
@action
- setFilterType = (e:any) => {
+ setFilterType = (e: any) => {
this.filteringType = e.currentTarget.value;
- }
+ };
changeFilterValue = action((e: React.ChangeEvent<HTMLInputElement>) => {
this.filteringVal[0] = e.target.value;
});
@@ -232,47 +230,82 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
this.filteringVal[1] = e.target.value;
});
@computed get renderFiltering() {
- if (this.filteringColumn==="") this.filteringColumn = this.columns[0];
+ if (this.filteringColumn === '') this.filteringColumn = this.columns[0];
return (
- <div className="tableBox-filterPopup" style={{right: this._props.width*.05}}>
+ <div className="tableBox-filterPopup" style={{ right: this._props.width * 0.05 }}>
<div className="tableBox-filterPopup-selectColumn">
Column:
- <select className="tableBox-filterPopup-selectColumn-each" value={this.filteringColumn!=""? this.filteringColumn : this.columns[0]} onChange={e => this.setFilterColumn(e)}>
+ <select className="tableBox-filterPopup-selectColumn-each" value={this.filteringColumn != '' ? this.filteringColumn : this.columns[0]} onChange={e => this.setFilterColumn(e)}>
{this.columns.map(column => (
- <option className="" key={column} value={column}> {column} </option>
+ <option className="" key={column} value={column}>
+ {' '}
+ {column}{' '}
+ </option>
))}
</select>
</div>
<div className="tableBox-filterPopup-setValue">
<select className="tableBox-filterPopup-setValue-each" value={this.filteringType} onChange={e => this.setFilterType(e)}>
- <option className="" key={"Value"} value={"Value"}> {"Value"} </option>
- <option className="" key={"Range"} value={"Range"}> {"Range"} </option>
+ <option className="" key={'Value'} value={'Value'}>
+ {' '}
+ {'Value'}{' '}
+ </option>
+ <option className="" key={'Range'} value={'Range'}>
+ {' '}
+ {'Range'}{' '}
+ </option>
</select>
:
- {this.filteringType=="Value"?
- <input className="tableBox-filterPopup-setValue-input" defaultValue="" autoComplete="off"
- onChange={this.changeFilterValue} onKeyDown={e => {e.stopPropagation();}}
- type="text" placeholder="" id="search-input"
+ {this.filteringType == 'Value' ? (
+ <input
+ className="tableBox-filterPopup-setValue-input"
+ defaultValue=""
+ autoComplete="off"
+ onChange={this.changeFilterValue}
+ onKeyDown={e => {
+ e.stopPropagation();
+ }}
+ type="text"
+ placeholder=""
+ id="search-input"
/>
- :
+ ) : (
<div>
- <input className="tableBox-filterPopup-setValue-input" defaultValue="" autoComplete="off"
- onChange={this.changeFilterRange0} onKeyDown={e => {e.stopPropagation();}}
- type="text" placeholder="" id="search-input" style={{width: this._props.width*.15}}
+ <input
+ className="tableBox-filterPopup-setValue-input"
+ defaultValue=""
+ autoComplete="off"
+ onChange={this.changeFilterRange0}
+ onKeyDown={e => {
+ e.stopPropagation();
+ }}
+ type="text"
+ placeholder=""
+ id="search-input"
+ style={{ width: this._props.width * 0.15 }}
/>
- to
- <input className="tableBox-filterPopup-setValue-input" defaultValue="" autoComplete="off"
- onChange={this.changeFilterRange1} onKeyDown={e => {e.stopPropagation();}}
- type="text" placeholder="" id="search-input" style={{width: this._props.width*.15}}
+ to
+ <input
+ className="tableBox-filterPopup-setValue-input"
+ defaultValue=""
+ autoComplete="off"
+ onChange={this.changeFilterRange1}
+ onKeyDown={e => {
+ e.stopPropagation();
+ }}
+ type="text"
+ placeholder=""
+ id="search-input"
+ style={{ width: this._props.width * 0.15 }}
/>
</div>
- }
+ )}
</div>
<div className="tableBox-filterPopup-setFilter">
- <Button onClick={action((e) => this.filter(e))} text="Set Filter" type={Type.SEC} color={'black'} />
+ <Button onClick={action(e => this.filter(e))} text="Set Filter" type={Type.SEC} color={'black'} />
</div>
</div>
- )
+ );
}
render() {
@@ -293,16 +326,32 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
<Button onClick={action(() => (this.settingTitle = !this.settingTitle))} text="Select Title Column" type={Type.SEC} color={'black'} />
</div>
<div className="tableBox-filtering">
- {this.filtering? this.renderFiltering : null}
+ {this.filtering ? this.renderFiltering : null}
<Button onClick={action(() => (this.filtering = !this.filtering))} text="Filter" type={Type.SEC} color={'black'} />
<div className="tableBox-filterAll">
- {this.hasRowsToFilter? <Button onClick={action(() => {
- this._props.layoutDoc.dataViz_selectedRows = new List<number>();
- this.hasRowsToFilter = false; })} text="Deselect All" type={Type.SEC} color={'black'} tooltip="Select rows to be displayed in any DataViz boxes dragged off of this one." />
- : <Button onClick={action(() => {
- this._props.layoutDoc.dataViz_selectedRows = new List<number>(this._tableDataIds)
- this.hasRowsToFilter = true; })} text="Select All" type={Type.SEC} color={'black'} tooltip="Select rows to be displayed in any DataViz boxes dragged off of this one." />
- }
+ {this.hasRowsToFilter ? (
+ <Button
+ onClick={action(() => {
+ this._props.layoutDoc.dataViz_selectedRows = new List<number>();
+ this.hasRowsToFilter = false;
+ })}
+ text="Deselect All"
+ type={Type.SEC}
+ color={'black'}
+ tooltip="Select rows to be displayed in any DataViz boxes dragged off of this one."
+ />
+ ) : (
+ <Button
+ onClick={action(() => {
+ this._props.layoutDoc.dataViz_selectedRows = new List<number>(this._tableDataIds);
+ this.hasRowsToFilter = true;
+ })}
+ text="Select All"
+ type={Type.SEC}
+ color={'black'}
+ tooltip="Select rows to be displayed in any DataViz boxes dragged off of this one."
+ />
+ )}
</div>
</div>
</div>
@@ -338,13 +387,23 @@ export class TableBox extends ObservableReactComponent<TableBoxProps> {
<th
key={this.columns.indexOf(col)}
style={{
- color: this._props.axes.slice().reverse().lastElement() === col ? 'darkgreen'
- : (this._props.axes.length>2 && this._props.axes.lastElement() === col) ? 'darkred'
- : (this._props.axes.lastElement()===col || (this._props.axes.length>2 && this._props.axes[1]==col))? 'darkblue' : undefined,
- background: this.settingTitle? 'lightgrey'
- : this._props.axes.slice().reverse().lastElement() === col ? '#E3fbdb'
- : (this._props.axes.length>2 && this._props.axes.lastElement() === col) ? '#Fbdbdb'
- : (this._props.axes.lastElement()===col || (this._props.axes.length>2 && this._props.axes[1]==col))? '#c6ebf7' : undefined,
+ color:
+ this._props.axes.slice().reverse().lastElement() === col
+ ? 'darkgreen'
+ : this._props.axes.length > 2 && this._props.axes.lastElement() === col
+ ? 'darkred'
+ : this._props.axes.lastElement() === col || (this._props.axes.length > 2 && this._props.axes[1] == col)
+ ? 'darkblue'
+ : undefined,
+ background: this.settingTitle
+ ? 'lightgrey'
+ : this._props.axes.slice().reverse().lastElement() === col
+ ? '#E3fbdb'
+ : this._props.axes.length > 2 && this._props.axes.lastElement() === col
+ ? '#Fbdbdb'
+ : this._props.axes.lastElement() === col || (this._props.axes.length > 2 && this._props.axes[1] == col)
+ ? '#c6ebf7'
+ : undefined,
fontWeight: 'bolder',
border: '3px solid black',
}}
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
index bae93beec..43010b2ed 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
@@ -981,13 +981,10 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB
};
animateRes = (resIndex: number, newText: string) => {
- if (!this._editorView) return;
if (resIndex < newText.length) {
- const marks = this._editorView.state.storedMarks ?? [];
- this._editorView.dispatch(this._editorView.state.tr.insertText(newText[resIndex]).setStoredMarks(marks));
- setTimeout(() => {
- this.animateRes(resIndex + 1, newText);
- }, 20);
+ const marks = this._editorView?.state.storedMarks ?? [];
+ this._editorView?.dispatch(this._editorView?.state.tr.insertText(newText[resIndex]).setStoredMarks(marks));
+ setTimeout(() => this.animateRes(resIndex + 1, newText), 20);
}
};
@@ -996,15 +993,11 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB
let res = await gptAPICall((this.dataDoc.text as RichTextField)?.Text, GPTCallType.COMPLETION);
if (!res) {
this.animateRes(0, 'Something went wrong.');
- } else {
- if (!this._editorView) return;
- // No animation
- // this._editorView.dispatch(this._editorView.state.tr.insertText(res));
-
- // Animation
- // Set selection at end
- const sel = Selection.atEnd(this._editorView.state.doc);
- this._editorView.dispatch(this._editorView.state.tr.setSelection(sel));
+ } else if (this._editorView) {
+ const { dispatch, state } = this._editorView;
+ // for no animation, use: dispatch(state.tr.insertText(res));
+ // for animted response starting at end of text, use:
+ dispatch(state.tr.setSelection(Selection.atEnd(state.doc)));
this.animateRes(0, '\n\n' + res);
}
} catch (err) {