diff options
-rw-r--r-- | src/client/views/collections/CollectionSchemaCells.tsx | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx index 2e6186680..b1dc82ce2 100644 --- a/src/client/views/collections/CollectionSchemaCells.tsx +++ b/src/client/views/collections/CollectionSchemaCells.tsx @@ -236,14 +236,40 @@ export class CollectionSchemaCell extends React.Component<CellProps> { Field.IsField(cfield) ? Field.toScriptString(cfield) : ""; }} SetValue={action((value: string) => { + // sets what is displayed after the user makes an input let retVal = false; if (value.startsWith(":=") || value.startsWith("=:=")) { + // decides how to compute a value when given either of the above strings const script = value.substring(value.startsWith("=:=") ? 3 : 2); retVal = this.props.setComputed(script, value.startsWith(":=") ? this._rowDataDoc : this._rowDoc, this.renderFieldKey, this.props.row, this.props.col); } else { - const inputscript = value.substring(value.startsWith("=") ? 1 : 0); - const script = CompileScript(inputscript, { 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)); + const inputAsNum: number = parseInt(value); + // check if the input is a number + if (isNaN(inputAsNum)) { + // if it's not a number, it's a string, and should be processed as such + //TODO: maake the input not "thing" when it is being edited + const inputscript = value.substring(value.startsWith("=") ? 1 : 0); + let inputAsString = '"'; + // escape any quotes in the string + //TODO: remove this note to self: when the type is number, it behaves liek I want any to behave + for (const i of inputscript) { + if (i == '"') { + inputAsString += '\\"'; + } else { + inputAsString += i; + } + } + 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(inputscript.length !== value.length ? this._rowDoc : this._rowDataDoc, this.props.row, this.props.col, script.run)); + } else { + //TODO: make accept numbers + const inputscript = value.substring(value.startsWith("=") ? 1 : 0); + const inputAsString = '"' + inputscript + '"'; + const script = CompileScript(inputscript, { 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)); + } } if (retVal) { this._isEditing = false; // need to set this here. otherwise, the assignment of the field will invalidate & cause render() to be called with the wrong value for 'editing' |