aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
diff options
context:
space:
mode:
authorStanley Yip <stanley_yip@brown.edu>2020-01-08 13:47:29 -0500
committerStanley Yip <stanley_yip@brown.edu>2020-01-08 13:47:29 -0500
commitabfa42b6f2cf863deee19aac19328a23687464cb (patch)
treeb481f23ffa7bccbde7a31de34f50d765b6b73162 /src/client/views/collections/CollectionStackingViewFieldColumn.tsx
parentd8fc218f3481728f221ceacc60ac4bc553f8e295 (diff)
parent19a71cb2788b9c1c8d8ced4af285bf91033ba626 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into pen
Diffstat (limited to 'src/client/views/collections/CollectionStackingViewFieldColumn.tsx')
-rw-r--r--src/client/views/collections/CollectionStackingViewFieldColumn.tsx97
1 files changed, 47 insertions, 50 deletions
diff --git a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
index b9d334b10..39b4e4e1d 100644
--- a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
+++ b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
@@ -2,17 +2,14 @@ import React = require("react");
import { library } from '@fortawesome/fontawesome-svg-core';
import { faPalette } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { action, observable, trace, runInAction } from "mobx";
+import { action, observable, runInAction } from "mobx";
import { observer } from "mobx-react";
-import { Doc, WidthSym } from "../../../new_fields/Doc";
-import { Id } from "../../../new_fields/FieldSymbols";
+import { Doc } from "../../../new_fields/Doc";
import { PastelSchemaPalette, SchemaHeaderField } from "../../../new_fields/SchemaHeaderField";
import { ScriptField } from "../../../new_fields/ScriptField";
import { NumCast, StrCast } from "../../../new_fields/Types";
-import { Utils } from "../../../Utils";
import { Docs } from "../../documents/Documents";
import { DragManager } from "../../util/DragManager";
-import { CompileScript } from "../../util/Scripting";
import { SelectionManager } from "../../util/SelectionManager";
import { Transform } from "../../util/Transform";
import { undoBatch } from "../../util/UndoManager";
@@ -20,6 +17,7 @@ import { anchorPoints, Flyout } from "../DocumentDecorations";
import { EditableView } from "../EditableView";
import { CollectionStackingView } from "./CollectionStackingView";
import "./CollectionStackingView.scss";
+import { TraceMobx } from "../../../new_fields/util";
library.add(faPalette);
@@ -53,28 +51,28 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
this._dropRef = ele;
this.dropDisposer && this.dropDisposer();
if (ele) {
- this.dropDisposer = DragManager.MakeDropTarget(ele, { handlers: { drop: this.columnDrop.bind(this) } });
+ this.dropDisposer = DragManager.MakeDropTarget(ele, this.columnDrop.bind(this));
}
}
@undoBatch
columnDrop = action((e: Event, de: DragManager.DropEvent) => {
this._createAliasSelected = false;
- if (de.data instanceof DragManager.DocumentDragData) {
- let key = StrCast(this.props.parent.props.Document.sectionFilter);
- let castedValue = this.getValue(this._heading);
+ if (de.complete.docDragData) {
+ const key = StrCast(this.props.parent.props.Document.sectionFilter);
+ const castedValue = this.getValue(this._heading);
if (castedValue) {
- de.data.droppedDocuments.forEach(d => d[key] = castedValue);
+ de.complete.docDragData.droppedDocuments.forEach(d => d[key] = castedValue);
}
else {
- de.data.droppedDocuments.forEach(d => d[key] = undefined);
+ de.complete.docDragData.droppedDocuments.forEach(d => d[key] = undefined);
}
this.props.parent.drop(e, de);
e.stopPropagation();
}
});
getValue = (value: string): any => {
- let parsed = parseInt(value);
+ const parsed = parseInt(value);
if (!isNaN(parsed)) {
return parsed;
}
@@ -90,8 +88,8 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
@action
headingChanged = (value: string, shiftDown?: boolean) => {
this._createAliasSelected = false;
- let key = StrCast(this.props.parent.props.Document.sectionFilter);
- let castedValue = this.getValue(value);
+ const key = StrCast(this.props.parent.props.Document.sectionFilter);
+ const castedValue = this.getValue(value);
if (castedValue) {
if (this.props.parent.sectionHeaders) {
if (this.props.parent.sectionHeaders.map(i => i.heading).indexOf(castedValue.toString()) > -1) {
@@ -135,11 +133,11 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
@action
addDocument = (value: string, shiftDown?: boolean) => {
this._createAliasSelected = false;
- let key = StrCast(this.props.parent.props.Document.sectionFilter);
- let newDoc = Docs.Create.TextDocument({ height: 18, width: 200, documentText: "@@@" + value, title: value, autoHeight: true });
+ const key = StrCast(this.props.parent.props.Document.sectionFilter);
+ const newDoc = Docs.Create.TextDocument({ height: 18, width: 200, documentText: "@@@" + value, title: value, autoHeight: true });
newDoc[key] = this.getValue(this.props.heading);
- let maxHeading = this.props.docList.reduce((maxHeading, doc) => NumCast(doc.heading) > maxHeading ? NumCast(doc.heading) : maxHeading, 0);
- let heading = maxHeading === 0 || this.props.docList.length === 0 ? 1 : maxHeading === 1 ? 2 : 3;
+ const maxHeading = this.props.docList.reduce((maxHeading, doc) => NumCast(doc.heading) > maxHeading ? NumCast(doc.heading) : maxHeading, 0);
+ const heading = maxHeading === 0 || this.props.docList.length === 0 ? 1 : maxHeading === 1 ? 2 : 3;
newDoc.heading = heading;
return this.props.parent.props.addDocument(newDoc);
}
@@ -147,10 +145,10 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
@action
deleteColumn = () => {
this._createAliasSelected = false;
- let key = StrCast(this.props.parent.props.Document.sectionFilter);
+ const key = StrCast(this.props.parent.props.Document.sectionFilter);
this.props.docList.forEach(d => d[key] = undefined);
if (this.props.parent.sectionHeaders && this.props.headingObject) {
- let index = this.props.parent.sectionHeaders.indexOf(this.props.headingObject);
+ const index = this.props.parent.sectionHeaders.indexOf(this.props.headingObject);
this.props.parent.sectionHeaders.splice(index, 1);
}
}
@@ -166,10 +164,10 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
}
startDrag = (e: PointerEvent) => {
- let [dx, dy] = this.props.screenToLocalTransform().transformDirection(e.clientX - this._startDragPosition.x, e.clientY - this._startDragPosition.y);
+ const [dx, dy] = this.props.screenToLocalTransform().transformDirection(e.clientX - this._startDragPosition.x, e.clientY - this._startDragPosition.y);
if (Math.abs(dx) + Math.abs(dy) > this._sensitivity) {
- let alias = Doc.MakeAlias(this.props.parent.props.Document);
- let key = StrCast(this.props.parent.props.Document.sectionFilter);
+ const alias = Doc.MakeAlias(this.props.parent.props.Document);
+ const key = StrCast(this.props.parent.props.Document.sectionFilter);
let value = this.getValue(this._heading);
value = typeof value === "string" ? `"${value}"` : value;
alias.viewSpecScript = ScriptField.MakeFunction(`doc.${key} === ${value}`, { doc: Doc.name });
@@ -195,7 +193,7 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
e.stopPropagation();
e.preventDefault();
- let [dx, dy] = this.props.screenToLocalTransform().transformDirection(e.clientX, e.clientY);
+ const [dx, dy] = this.props.screenToLocalTransform().transformDirection(e.clientX, e.clientY);
this._startDragPosition = { x: dx, y: dy };
if (this._createAliasSelected) {
@@ -208,17 +206,17 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
}
renderColorPicker = () => {
- let selected = this.props.headingObject ? this.props.headingObject.color : "#f1efeb";
+ const selected = this.props.headingObject ? this.props.headingObject.color : "#f1efeb";
- let pink = PastelSchemaPalette.get("pink2");
- let purple = PastelSchemaPalette.get("purple4");
- let blue = PastelSchemaPalette.get("bluegreen1");
- let yellow = PastelSchemaPalette.get("yellow4");
- let red = PastelSchemaPalette.get("red2");
- let green = PastelSchemaPalette.get("bluegreen7");
- let cyan = PastelSchemaPalette.get("bluegreen5");
- let orange = PastelSchemaPalette.get("orange1");
- let gray = "#f1efeb";
+ const pink = PastelSchemaPalette.get("pink2");
+ const purple = PastelSchemaPalette.get("purple4");
+ const blue = PastelSchemaPalette.get("bluegreen1");
+ const yellow = PastelSchemaPalette.get("yellow4");
+ const red = PastelSchemaPalette.get("red2");
+ const green = PastelSchemaPalette.get("bluegreen7");
+ const cyan = PastelSchemaPalette.get("bluegreen5");
+ const orange = PastelSchemaPalette.get("orange1");
+ const gray = "#f1efeb";
return (
<div className="collectionStackingView-colorPicker">
@@ -243,7 +241,7 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
}
renderMenu = () => {
- let selected = this._createAliasSelected;
+ const selected = this._createAliasSelected;
return (
<div className="collectionStackingView-optionPicker">
<div className="optionOptions">
@@ -255,23 +253,22 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
@observable private collapsed: boolean = false;
- private toggleVisibility = action(() => {
- this.collapsed = !this.collapsed;
- });
+ private toggleVisibility = action(() => this.collapsed = !this.collapsed);
@observable _headingsHack: number = 1;
render() {
- let cols = this.props.cols();
- let key = StrCast(this.props.parent.props.Document.sectionFilter);
+ TraceMobx();
+ const cols = this.props.cols();
+ const key = StrCast(this.props.parent.props.Document.sectionFilter);
let templatecols = "";
- let headings = this.props.headings();
- let heading = this._heading;
- let style = this.props.parent;
- let singleColumn = style.isStackingView;
- let uniqueHeadings = headings.map((i, idx) => headings.indexOf(i) === idx);
- let evContents = heading ? heading : this.props.type && this.props.type === "number" ? "0" : `NO ${key.toUpperCase()} VALUE`;
- let headerEditableViewProps = {
+ const headings = this.props.headings();
+ const heading = this._heading;
+ const style = this.props.parent;
+ const singleColumn = style.isStackingView;
+ const uniqueHeadings = headings.map((i, idx) => headings.indexOf(i) === idx);
+ const evContents = heading ? heading : this.props.type && this.props.type === "number" ? "0" : `NO ${key.toUpperCase()} VALUE`;
+ const headerEditableViewProps = {
GetValue: () => evContents,
SetValue: this.headingChanged,
contents: evContents,
@@ -281,7 +278,7 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
toggle: this.toggleVisibility,
color: this._color
};
- let newEditableViewProps = {
+ const newEditableViewProps = {
GetValue: () => "",
SetValue: this.addDocument,
contents: "+ NEW",
@@ -290,7 +287,7 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
toggle: this.toggleVisibility,
color: this._color
};
- let headingView = this.props.headingObject ?
+ const headingView = this.props.headingObject ?
<div key={heading} className="collectionStackingView-sectionHeader" ref={this._headerRef}
style={{
width: (style.columnWidth) /
@@ -335,7 +332,7 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
</div>
</div> : (null);
for (let i = 0; i < cols; i++) templatecols += `${style.columnWidth / style.numGroupColumns}px `;
- let chromeStatus = this.props.parent.props.Document.chromeStatus;
+ const chromeStatus = this.props.parent.props.Document.chromeStatus;
return (
<div className="collectionStackingViewFieldColumn" key={heading} style={{ width: `${100 / ((uniqueHeadings.length + ((chromeStatus !== 'view-mode' && chromeStatus !== 'disabled') ? 1 : 0)) || 1)}%`, background: this._background }}
ref={this.createColumnDropRef} onPointerEnter={this.pointerEntered} onPointerLeave={this.pointerLeave}>