From 337183e190c30216fe138600a8d599774260f784 Mon Sep 17 00:00:00 2001 From: anika-ahluwalia Date: Tue, 19 May 2020 13:49:38 -0500 Subject: adding number types, fixed doc type errors --- src/client/views/nodes/ScriptingBox.tsx | 101 ++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/ScriptingBox.tsx b/src/client/views/nodes/ScriptingBox.tsx index 86baa0f6f..f84b996ab 100644 --- a/src/client/views/nodes/ScriptingBox.tsx +++ b/src/client/views/nodes/ScriptingBox.tsx @@ -17,6 +17,8 @@ import { List } from "../../../fields/List"; import { DragManager } from "../../util/DragManager"; import { Doc } from "../../../fields/Doc"; import { Dropdown } from "prosemirror-menu"; +import { isNumber } from "util"; +import { faSearch, faKaaba } from "@fortawesome/free-solid-svg-icons"; const ScriptingSchema = createSchema({}); type ScriptingDocument = makeInterface<[typeof ScriptingSchema, typeof documentSchema]>; @@ -37,7 +39,7 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent { console.log("drop"); - const firstParam = this.compileParams[index].split(":"); const droppedDocs = de.complete.docDragData?.droppedDocuments; if (droppedDocs?.length) { const dropped = droppedDocs[0]; this.props.Document[index] = dropped; - // you can't just bind a variable to a specific Doc. The Doc would have to be added to 'capturedVariables' field of the compile options, but I think it makes more sense to just be declaring this variable to be a Doc + const num = this._paramsNames.indexOf(index); + this._paramsValues[num] = StrCast(dropped.title); } } @action onDelete = (num: number) => { this.compileParams.splice(num, 1); + // delete from fields, delete from _paramNames, _paramTypes, _paramValues } render() { - // var Dropdown = require('react-simple-dropdown'); - // var DropdownTrigger = Dropdown.DropdownTrigger; - // var DropdownContent = Dropdown.DropdownContent; - const params = ; + + // might want to change this display later on const listParams = this.compileParams.map((parameter, i) =>
); + const settingParams = this._paramsNames.map((parameter: string, i: number) =>
StrCast(this.props.Document[parameter]) ?? "undefined"} + GetValue={() => this._paramsValues[i]} onDrop={(e: Event, de: DragManager.DropEvent) => this.onDrop(e, de, parameter)} SetValue={value => { runInAction(() => { @@ -313,18 +320,20 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent
: null} + {this._paramsTypes[i] === "string" ?
-
- {parameter + ":" + this._paramsValues[i] + " = "} + {parameter + ":" + this._paramsTypes[i] + " = "}
-
StrCast(this.props.Document[parameter]) ?? "undefined"} SetValue={value => { runInAction(() => { - this.props.Document[parameter] = value; - return true; + if (value !== "" && value !== " ") { + this._errorMessage = ""; + this.props.Document[parameter] = value; + this._paramsValues[i] = value; + return true; + } else { + return false; + } }); return true; }} @@ -361,25 +375,45 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent
: null} - {/* {this._paramsTypes[i].split("|")[1] ?
+ {this._paramsTypes[i] === "number" ?
-
- {parameter + ":" + this._paramsValues[i] + " = "} + {parameter + ":" + this._paramsTypes[i] + " = "}
-
- - Profile - -
{this._paramsTypes[0]}
-
{this._paramsTypes[1]}
-
-
+ StrCast(this.props.Document[parameter]) ?? "undefined"} + SetValue={value => { + runInAction(() => { + if (value !== "" && value !== " ") { + if (parseInt(value)) { + this._errorMessage = ""; + this.props.Document[parameter] = parseInt(value); + this._paramsValues[i] = StrCast(parseInt(value)); + return true; + } else { + this._errorMessage = "not a number"; + return false; + } + } else { + return false; + } + }); + return true; + }} + />
-
: null} */} +
: null} + + +
); @@ -431,6 +465,9 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent; const paramsTools =
+ {this._errorMessage ?
+ {this._errorMessage} +
: null}