aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DataVizBox/components/TableBox.tsx
diff options
context:
space:
mode:
authorsrichman333 <sarah_n_richman@brown.edu>2023-08-03 14:38:47 -0400
committersrichman333 <sarah_n_richman@brown.edu>2023-08-03 14:38:47 -0400
commit23e0ee2dcad8df2bc3467647e05c433f27787d54 (patch)
tree43d393f6c13e36c459de532af5b92fe9887d28a0 /src/client/views/nodes/DataVizBox/components/TableBox.tsx
parentde064a6b0acf7f3dff04c579afc2562d782472d2 (diff)
table fixes (selected by guid not extra row + ui changes)
Diffstat (limited to 'src/client/views/nodes/DataVizBox/components/TableBox.tsx')
-rw-r--r--src/client/views/nodes/DataVizBox/components/TableBox.tsx310
1 files changed, 106 insertions, 204 deletions
diff --git a/src/client/views/nodes/DataVizBox/components/TableBox.tsx b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
index 64c6dc940..5653adbce 100644
--- a/src/client/views/nodes/DataVizBox/components/TableBox.tsx
+++ b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
@@ -1,21 +1,20 @@
-import { action, computed, observable } from 'mobx';
+import { action, computed, } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
-import { Doc } from '../../../../../fields/Doc';
-import { Id } from '../../../../../fields/FieldSymbols';
+import { Doc, StrListCast } from '../../../../../fields/Doc';
import { List } from '../../../../../fields/List';
-import { emptyFunction, returnFalse, setupMoveUpEvents, Utils } from '../../../../../Utils';
+import { emptyFunction, setupMoveUpEvents, Utils } from '../../../../../Utils';
import { DragManager } from '../../../../util/DragManager';
import { DocumentView } from '../../DocumentView';
import { DataVizView } from '../DataVizBox';
import { LinkManager } from '../../../../util/LinkManager';
import { Cast, DocCast } from '../../../../../fields/Types';
-import { EditableText, Size, Type } from 'browndash-components';
import './Chart.scss';
import { listSpec } from '../../../../../fields/Schema';
interface TableBoxProps {
rootDoc: Doc;
+ layoutDoc: Doc;
pairs: { [key: string]: any }[];
selectAxes: (axes: string[]) => void;
axes: string[];
@@ -32,13 +31,10 @@ interface TableBoxProps {
@observer
export class TableBox extends React.Component<TableBoxProps> {
- @observable editableHeaders = this.columns;
- @observable editableCells = this._tableData;
@computed get _tableData() {
if (this.incomingLinks.length! <= 0) return this.props.pairs;
- /// StrListCast(this.incomingLinks[0].anchor_1.selected) ==> list of guids that the parent has selected
- return this.props.pairs?.filter(pair => (Array.from(Object.keys(pair)).some(key => pair[key] && key.startsWith('select'))))
+ return this.props.pairs?.filter(pair => this.incomingLinks[0]!.selected && StrListCast(this.incomingLinks[0].selected).includes(pair.guid))
}
@computed get incomingLinks() {
@@ -49,204 +45,110 @@ export class TableBox extends React.Component<TableBoxProps> {
}
@computed get columns() {
- // return this.props.pairs.length ? Array.from(Object.keys(this.props.pairs[0])) : [];
- return this._tableData.length ? Array.from(Object.keys(this._tableData[0])) : [];
+ return this._tableData.length ? Array.from(Object.keys(this._tableData[0])).filter(header => header!='guid' && header!='') : [];
}
- // render() {
- // return (
- // <div className="table-container" style={{height: this.props.height+this.props.margin.top+this.props.margin.bottom}}>
- // <table className="table">
- // <thead>
- // <tr className="table-row">
- // {this.editableHeaders
- // .filter(col => !col.startsWith('select'))
- // .map(col => {
- // const header = React.createRef<HTMLElement>();
- // const displayColName = col;
- // return (
- // <th
- // key={this.editableHeaders.indexOf(col)}
- // ref={header as any}
- // style={{
- // color: this.props.axes.slice().reverse().lastElement() === col ? 'green' : this.props.axes.lastElement() === col ? 'red' : undefined,
- // fontWeight: this.props.axes.includes(col) ? 'bolder' : 'normal',
- // }}
- // onPointerDown={e => {
- // const downX = e.clientX;
- // const downY = e.clientY;
- // setupMoveUpEvents(
- // {},
- // e,
- // e => {
- // const sourceAnchorCreator = () => this.props.docView?.()!.rootDoc!;
- // const targetCreator = (annotationOn: Doc | undefined) => {
- // const embedding = Doc.MakeEmbedding(this.props.docView?.()!.rootDoc!);
- // embedding._dataVizView = DataVizView.LINECHART;
- // embedding._data_vizAxes = new List<string>([col, col]);
- // embedding._draggedFrom = this.props.docView?.()!.rootDoc!;
- // embedding.annotationOn = annotationOn; //this.props.docView?.()!.rootDoc!;
- // return embedding;
- // };
- // if (this.props.docView?.() && !Utils.isClick(e.clientX, e.clientY, downX, downY, Date.now())) {
- // DragManager.StartAnchorAnnoDrag([header.current!], new DragManager.AnchorAnnoDragData(this.props.docView()!, sourceAnchorCreator, targetCreator), downX, downY, {
- // dragComplete: e => {
- // if (!e.aborted && e.annoDragData && e.annoDragData.linkSourceDoc && e.annoDragData.dropDocument && e.linkDocument) {
- // e.linkDocument.link_displayLine = true;
- // e.linkDocument.link_matchEmbeddings = true;
- // // e.annoDragData.linkSourceDoc.followLinkToggle = e.annoDragData.dropDocument.annotationOn === this.props.rootDoc;
- // // e.annoDragData.linkSourceDoc.followLinkZoom = false;
- // }
- // },
- // });
- // return true;
- // }
- // return false;
- // },
- // emptyFunction,
- // action(e => {
- // const newAxes = this.props.axes;
- // if (newAxes.includes(col)) {
- // newAxes.splice(newAxes.indexOf(col), 1);
- // } else if (newAxes.length >= 1) {
- // newAxes[1] = col;
- // } else {
- // newAxes[0] = col;
- // }
- // this.props.selectAxes(newAxes);
- // })
- // );
- // }}>
- // <EditableText
- // val={displayColName}
- // setVal={action(val => {
- // this.editableHeaders[this.editableHeaders.indexOf(col)] = val as string
- // this.props.pairs.map(pair => {
- // pair[val as string] = pair[col];
- // delete pair[col]
- // })
- // })}
- // color={"black"}
- // size={Size.LARGE}
- // />
- // </th>
- // );
- // })}
- // </tr>
- // </thead>
- // <tbody>
- // {this._tableData?.map((p, i) => {
- // return (
- // <tr key={i} className="table-row" onClick={action(e => (p['select' + this.props.docView?.()?.rootDoc![Id]] = !p['select' + this.props.docView?.()?.rootDoc![Id]]))}>
- // {this.editableHeaders.map(col => (
- // <td key={this.editableHeaders.indexOf(col)} style={{ fontWeight: p['select' + this.props.docView?.()?.rootDoc![Id]] ? 'bold' : '' }}>
- // {p[col]}
- // </td>
- // ))}
- // </tr>
- // );
- // })}
- // </tbody>
- // </table>
- // </div>
- // );
- // }
-
-
render() {
- return (
- <div className="table-container" style={{height: this.props.height+this.props.margin.top+this.props.margin.bottom}}>
- <table className="table">
- <thead>
- <tr className="table-row">
- {this.columns
- .filter(col => !col.startsWith('select'))
- .map(col => {
- const header = React.createRef<HTMLElement>();
- return (
- <th
- key={this.columns.indexOf(col)}
- ref={header as any}
- style={{
- color: this.props.axes.slice().reverse().lastElement() === col ? 'green' : this.props.axes.lastElement() === col ? 'red' : undefined,
- fontWeight: this.props.axes.includes(col) ? 'bolder' : 'normal',
- }}
- onPointerDown={e => {
- const downX = e.clientX;
- const downY = e.clientY;
- setupMoveUpEvents(
- {},
- e,
- e => {
- const sourceAnchorCreator = () => this.props.docView?.()!.rootDoc!;
- const targetCreator = (annotationOn: Doc | undefined) => {
- const embedding = Doc.MakeEmbedding(this.props.docView?.()!.rootDoc!);
- embedding._dataVizView = DataVizView.LINECHART;
- embedding._data_vizAxes = new List<string>([col, col]);
- embedding._draggedFrom = this.props.docView?.()!.rootDoc!;
- embedding.annotationOn = annotationOn; //this.props.docView?.()!.rootDoc!;
- return embedding;
- };
- if (this.props.docView?.() && !Utils.isClick(e.clientX, e.clientY, downX, downY, Date.now())) {
- DragManager.StartAnchorAnnoDrag([header.current!], new DragManager.AnchorAnnoDragData(this.props.docView()!, sourceAnchorCreator, targetCreator), downX, downY, {
- dragComplete: e => {
- if (!e.aborted && e.annoDragData && e.annoDragData.linkSourceDoc && e.annoDragData.dropDocument && e.linkDocument) {
- e.linkDocument.link_displayLine = true;
- e.linkDocument.link_matchEmbeddings = true;
- // e.annoDragData.linkSourceDoc.followLinkToggle = e.annoDragData.dropDocument.annotationOn === this.props.rootDoc;
- // e.annoDragData.linkSourceDoc.followLinkZoom = false;
- }
- },
- });
- return true;
- }
- return false;
- },
- emptyFunction,
- action(e => {
- const newAxes = this.props.axes;
- if (newAxes.includes(col)) {
- newAxes.splice(newAxes.indexOf(col), 1);
- } else if (newAxes.length >= 1) {
- newAxes[1] = col;
- } else {
- newAxes[0] = col;
- }
- this.props.selectAxes(newAxes);
- })
- );
- }}>
- {col}
- </th>
- );
- })}
- </tr>
- </thead>
- <tbody>
- {this._tableData?.map((p, i) => {
- return (
- <tr key={i} className="table-row" onClick={action(e => {
- // if (!this.props.docView?.()!.layoutDoc.selected)
- // this.props.docView!.()!.layoutDoc.selected = new List<string>();
- // const selected = Cast(this.props.docView?.()!.layoutDoc.selected, listSpec("string"), null);
- // // StrListCast(this.props.docView?.()!.layoutDoc.selected)
- // selected.push(p.guid);
- (p['select' + this.props.docView?.()?.rootDoc![Id]] = !p['select' + this.props.docView?.()?.rootDoc![Id]])
- })}>
- {this.columns.map(col => (
- <td key={this.columns.indexOf(col)} style={{ fontWeight: p['select' + this.props.docView?.()?.rootDoc![Id]] ? 'bold' : '' }}>
- {p[col]}
- </td>
- ))}
- </tr>
- );
- })}
- </tbody>
- </table>
+ if (this._tableData.length>0){
+ return (
+ <div className="table-container" style={{height: this.props.height+this.props.margin.top+this.props.margin.bottom}}>
+ <table className="table">
+ <thead>
+ <tr className="table-row">
+ {this.columns
+ .filter(col => !col.startsWith('select'))
+ .map(col => {
+ const header = React.createRef<HTMLElement>();
+ return (
+ <th
+ key={this.columns.indexOf(col)}
+ ref={header as any}
+ style={{
+ color: this.props.axes.slice().reverse().lastElement() === col ? 'green' : this.props.axes.lastElement() === col ? 'red' : undefined,
+ fontWeight: 'bolder', border: '3px solid black'
+ }}
+ onPointerDown={e => {
+ const downX = e.clientX;
+ const downY = e.clientY;
+ setupMoveUpEvents(
+ {},
+ e,
+ e => {
+ const sourceAnchorCreator = () => this.props.docView?.()!.rootDoc!;
+ const targetCreator = (annotationOn: Doc | undefined) => {
+ const embedding = Doc.MakeEmbedding(this.props.docView?.()!.rootDoc!);
+ embedding._dataVizView = DataVizView.TABLE;
+ embedding._data_vizAxes = new List<string>([col, col]);
+ embedding._draggedFrom = this.props.docView?.()!.rootDoc!;
+ embedding.annotationOn = annotationOn; //this.props.docView?.()!.rootDoc!;
+ return embedding;
+ };
+ if (this.props.docView?.() && !Utils.isClick(e.clientX, e.clientY, downX, downY, Date.now())) {
+ DragManager.StartAnchorAnnoDrag([header.current!], new DragManager.AnchorAnnoDragData(this.props.docView()!, sourceAnchorCreator, targetCreator), downX, downY, {
+ dragComplete: e => {
+ if (!e.aborted && e.annoDragData && e.annoDragData.linkSourceDoc && e.annoDragData.dropDocument && e.linkDocument) {
+ e.linkDocument.link_displayLine = true;
+ e.linkDocument.link_matchEmbeddings = true;
+ // e.annoDragData.linkSourceDoc.followLinkToggle = e.annoDragData.dropDocument.annotationOn === this.props.rootDoc;
+ // e.annoDragData.linkSourceDoc.followLinkZoom = false;
+ }
+ },
+ });
+ return true;
+ }
+ return false;
+ },
+ emptyFunction,
+ action(e => {
+ const newAxes = this.props.axes;
+ if (newAxes.includes(col)) {
+ newAxes.splice(newAxes.indexOf(col), 1);
+ } else if (newAxes.length >= 1) {
+ newAxes[1] = col;
+ } else {
+ newAxes[0] = col;
+ }
+ this.props.selectAxes(newAxes);
+ })
+ );
+ }}>
+ {col}
+ </th>
+ );
+ })}
+ </tr>
+ </thead>
+ <tbody>
+ {this._tableData?.map((p, i) => {
+ return (
+ <tr key={i} className="table-row" onClick={action(e => {
+ if (!this.props.layoutDoc.selected) this.props.layoutDoc.selected = new List<string>();
+ const selected = Cast(this.props.layoutDoc.selected, listSpec("string"), null);
+ if (selected.includes(p.guid)) selected.splice(selected.indexOf(p.guid), 1);
+ else {
+ selected.push(p.guid)};
+ })} style={
+ { fontWeight: StrListCast(this.props.layoutDoc.selected).includes(p.guid) ? 'bold' : '' , width: '110%',
+ background: StrListCast(this.props.layoutDoc.selected).includes(p.guid) ? 'lightgrey' : '' }}>
+ {this.columns.map(col => (
+ (this.props.layoutDoc.selected)?
+ <td key={this.columns.indexOf(col)} style={{border: '1px solid black'}}>
+ {p[col]}
+ </td>
+ : <td key={this.columns.indexOf(col)} style={{border: '1px solid black'}}> {p[col]} </td>
+ ))}
+ </tr>
+ );
+ })}
+ </tbody>
+ </table>
+ </div>
+ );
+ }
+ else return (
+ <div className='chart-container'>
+ Selected rows of data from the incoming DataVizBox to display.
</div>
- );
+ )
}
-
-
-
}