aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0x85FB9C51 <77808164+0x85FB9C51@users.noreply.github.com>2021-06-28 16:57:56 -0400
committer0x85FB9C51 <77808164+0x85FB9C51@users.noreply.github.com>2021-06-28 16:57:56 -0400
commit501bf6a5d6c81ea1e58509e51ab8c252eaf178ca (patch)
treebb459bbdd7a34f644a3fe9e64a9872193baf02e2
parent40f52d119be06b60515e5058607633409f847e4f (diff)
resolved bugs and removes console.log
-rw-r--r--src/client/util/Scripting.ts1
-rw-r--r--src/client/views/collections/CollectionSchemaCells.tsx22
-rw-r--r--src/client/views/collections/CollectionSchemaMovableTableHOC.tsx92
3 files changed, 60 insertions, 55 deletions
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index 3fe14a2a4..c3c3083be 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -268,7 +268,6 @@ function forEachNode(node: ts.Node, onEnter: Traverser, onExit?: Traverser, inde
export function CompileScript(script: string, options: ScriptOptions = {}): CompileResult {
const { requiredType = "", addReturn = false, params = {}, capturedVariables = {}, typecheck = true } = options;
- console.log("options: " + options.requiredType, options.addReturn, options.params);
if (options.params && !options.params.this) options.params.this = Doc.name;
if (options.params && !options.params.self) options.params.self = Doc.name;
if (options.globals) {
diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx
index 38b3b1628..42c5375ce 100644
--- a/src/client/views/collections/CollectionSchemaCells.tsx
+++ b/src/client/views/collections/CollectionSchemaCells.tsx
@@ -251,9 +251,10 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
}
console.log(inputIsNum);
}
- console.log("value: " + value);
- if (!inputIsNum && !value.startsWith("=")) {
- console.log("I don't beep because I'm not a computer.");
+ // check if the input is a boolean
+ let inputIsBool: boolean = value == "false" || value == "true";
+
+ if (!inputIsNum && !inputIsBool && !value.startsWith("=")) {
// if it's not a number, it's a string, and should be processed as such
// strips the string of quotes when it is edited to prevent quotes form being added to the text automatically
// after each edit
@@ -266,8 +267,6 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
}
let inputAsString = '"';
// escape any quotes in the string
- //TODO: remove this note to self: when the type is number, it behaves like I want any to behave
- //TODO: fix type laziness
for (const i of valueSansQuotes) {
if (i == '"') {
inputAsString += '\\"';
@@ -277,13 +276,12 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
}
// add a closing quote
inputAsString += '"';
- console.log(inputAsString);
//two options here: we can strip off outer quotes or we can figure out what's going on with the script
const script = CompileScript(inputAsString, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
- script.compiled && (retVal = this.applyToDoc(valueSansQuotes.length !== value.length ? this._rowDoc : this._rowDataDoc, this.props.row, this.props.col, script.run));
- } else {
+ script.compiled && (retVal = this.applyToDoc(inputAsString.length !== value.length ? this._rowDoc : this._rowDataDoc, this.props.row, this.props.col, script.run));
+ // handle numbers and expressions
+ } else if (inputIsNum || value.startsWith("=")) {
//TODO: make accept numbers
- console.log("I beep because I'm a computer");
const inputscript = value.substring(value.startsWith("=") ? 1 : 0);
// if commas are not stripped, the parser only considers the numbers after the last comma
let inputSansCommas = "";
@@ -293,7 +291,11 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
}
}
const script = CompileScript(inputSansCommas, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
- script.compiled && (retVal = this.applyToDoc(inputscript.length !== value.length ? this._rowDoc : this._rowDataDoc, this.props.row, this.props.col, script.run));
+ script.compiled && (retVal = this.applyToDoc(inputSansCommas.length + 2 !== value.length ? this._rowDoc : this._rowDataDoc, this.props.row, this.props.col, script.run));
+ // handle booleans
+ } else if (inputIsBool) {
+ const script = CompileScript(value, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
+ script.compiled && (retVal = this.applyToDoc(value.length + 2 !== value.length ? this._rowDoc : this._rowDataDoc, this.props.row, this.props.col, script.run));
}
}
if (retVal) {
diff --git a/src/client/views/collections/CollectionSchemaMovableTableHOC.tsx b/src/client/views/collections/CollectionSchemaMovableTableHOC.tsx
index 881246bd4..a842d629e 100644
--- a/src/client/views/collections/CollectionSchemaMovableTableHOC.tsx
+++ b/src/client/views/collections/CollectionSchemaMovableTableHOC.tsx
@@ -143,16 +143,20 @@ export class MovableRow extends React.Component<MovableRowProps> {
private _header?: React.RefObject<HTMLDivElement> = React.createRef();
private _rowDropDisposer?: DragManager.DragDropDisposer;
+ // Event listeners are only necessary when the user is hovering over the table
+ // Create one when the mouse starts hovering...
onPointerEnter = (e: React.PointerEvent): void => {
if (e.buttons === 1 && SnappingManager.GetIsDragging()) {
this._header!.current!.className = "collectionSchema-row-wrapper";
document.addEventListener("pointermove", this.onDragMove, true);
}
}
+ // ... and delete it when the mouse leaves
onPointerLeave = (e: React.PointerEvent): void => {
this._header!.current!.className = "collectionSchema-row-wrapper";
document.removeEventListener("pointermove", this.onDragMove, true);
}
+ // The method for the event listener, reorders columns when dragged to their new locations.
onDragMove = (e: PointerEvent): void => {
const x = this.props.ScreenToLocalTransform().transformPoint(e.clientX, e.clientY);
const rect = this._header!.current!.getBoundingClientRect();
@@ -167,14 +171,14 @@ export class MovableRow extends React.Component<MovableRowProps> {
this._rowDropDisposer?.();
}
-
+ //
createRowDropTarget = (ele: HTMLDivElement) => {
this._rowDropDisposer?.();
if (ele) {
this._rowDropDisposer = DragManager.MakeDropTarget(ele, this.rowDrop.bind(this));
}
}
-
+ // Controls what hppens when a row is dragged and dropped
rowDrop = (e: Event, de: DragManager.DropEvent) => {
this.onPointerLeave(e as any);
const rowDoc = FieldValue(Cast(this.props.rowInfo.original, Doc));
@@ -200,59 +204,59 @@ export class MovableRow extends React.Component<MovableRowProps> {
return false;
}
- onRowContextMenu = (e: React.MouseEvent): void => {
+ onRowContextMenu = (e: React.MouseEvent): void =>
e.preventDefault();
- const description = this.props.rowWrapped ? "Unwrap text on row" : "Text wrap row";
- ContextMenu.Instance.addItem({ description: description, event: () => this.props.textWrapRow(this.props.rowInfo.original), icon: "file-pdf" });
+ const description = this.props.rowWrapped ? "Unwrap text on row" : "Text wrap row";
+ ContextMenu.Instance.addItem({ description: description, event: () => this.props.textWrapRow(this.props.rowInfo.original), icon: "file-pdf" });
}
- @undoBatch
- @action
- move: DragManager.MoveFunction = (doc: Doc | Doc[], targetCollection: Doc | undefined, addDoc) => {
- const targetView = targetCollection && DocumentManager.Instance.getDocumentView(targetCollection);
- return doc !== targetCollection && doc !== targetView?.props.ContainingCollectionDoc && this.props.removeDoc(doc) && addDoc(doc);
- }
+@undoBatch
+@action
+move: DragManager.MoveFunction = (doc: Doc | Doc[], targetCollection: Doc | undefined, addDoc) => {
+ const targetView = targetCollection && DocumentManager.Instance.getDocumentView(targetCollection);
+ return doc !== targetCollection && doc !== targetView?.props.ContainingCollectionDoc && this.props.removeDoc(doc) && addDoc(doc);
+}
- @action
- onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
- console.log("yes");
- if (e.key === "Backspace" || e.key === "Delete") {
- undoBatch(() => this.props.removeDoc(this.props.rowInfo.original));
- }
+@action
+onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
+ console.log("yes");
+ if (e.key === "Backspace" || e.key === "Delete") {
+ undoBatch(() => this.props.removeDoc(this.props.rowInfo.original));
}
+}
- render() {
- const { children = null, rowInfo } = this.props;
+render() {
+ const { children = null, rowInfo } = this.props;
- if (!rowInfo) {
- return <ReactTableDefaults.TrComponent>{children}</ReactTableDefaults.TrComponent>;
- }
+ if (!rowInfo) {
+ return <ReactTableDefaults.TrComponent>{children}</ReactTableDefaults.TrComponent>;
+ }
- const { original } = rowInfo;
- const doc = FieldValue(Cast(original, Doc));
+ const { original } = rowInfo;
+ const doc = FieldValue(Cast(original, Doc));
- if (!doc) return (null);
+ if (!doc) return (null);
- const reference = React.createRef<HTMLDivElement>();
- const onItemDown = SetupDrag(reference, () => doc, this.move, StrCast(this.props.dropAction) as dropActionType);
+ const reference = React.createRef<HTMLDivElement>();
+ const onItemDown = SetupDrag(reference, () => doc, this.move, StrCast(this.props.dropAction) as dropActionType);
- let className = "collectionSchema-row";
- if (this.props.rowFocused) className += " row-focused";
- if (this.props.rowWrapped) className += " row-wrapped";
+ let className = "collectionSchema-row";
+ if (this.props.rowFocused) className += " row-focused";
+ if (this.props.rowWrapped) className += " row-wrapped";
- return (
- <div className={className} onKeyPress={this.onKeyDown} ref={this.createRowDropTarget} onContextMenu={this.onRowContextMenu}>
- <div className="collectionSchema-row-wrapper" onKeyPress={this.onKeyDown} ref={this._header} onPointerEnter={this.onPointerEnter} onPointerLeave={this.onPointerLeave}>
- <ReactTableDefaults.TrComponent onKeyPress={this.onKeyDown} >
- <div className="row-dragger">
- <div className="row-option" style={{ left: 5 }} onClick={undoBatch(() => this.props.removeDoc(this.props.rowInfo.original))}><FontAwesomeIcon icon="trash" size="sm" /></div>
- <div className="row-option" style={{ cursor: "grab", left: 25 }} ref={reference} onPointerDown={onItemDown}><FontAwesomeIcon icon="grip-vertical" size="sm" /></div>
- <div className="row-option" style={{ left: 40 }} onClick={() => this.props.addDocTab(this.props.rowInfo.original, "add:right")}><FontAwesomeIcon icon="external-link-alt" size="sm" /></div>
- </div>
- {children}
- </ReactTableDefaults.TrComponent>
- </div>
+ return (
+ <div className={className} onKeyPress={this.onKeyDown} ref={this.createRowDropTarget} onContextMenu={this.onRowContextMenu}>
+ <div className="collectionSchema-row-wrapper" onKeyPress={this.onKeyDown} ref={this._header} onPointerEnter={this.onPointerEnter} onPointerLeave={this.onPointerLeave}>
+ <ReactTableDefaults.TrComponent onKeyPress={this.onKeyDown} >
+ <div className="row-dragger">
+ <div className="row-option" style={{ left: 5 }} onClick={undoBatch(() => this.props.removeDoc(this.props.rowInfo.original))}><FontAwesomeIcon icon="trash" size="sm" /></div>
+ <div className="row-option" style={{ cursor: "grab", left: 25 }} ref={reference} onPointerDown={onItemDown}><FontAwesomeIcon icon="grip-vertical" size="sm" /></div>
+ <div className="row-option" style={{ left: 40 }} onClick={() => this.props.addDocTab(this.props.rowInfo.original, "add:right")}><FontAwesomeIcon icon="external-link-alt" size="sm" /></div>
+ </div>
+ {children}
+ </ReactTableDefaults.TrComponent>
</div>
- );
- }
+ </div>
+ );
+}
} \ No newline at end of file