diff options
author | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-04-09 18:05:57 -0400 |
---|---|---|
committer | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-04-09 18:05:57 -0400 |
commit | 79a0d8d66204868158849afda6518f6c641c826b (patch) | |
tree | c36b6064cb8577f375107c6df4885c7a3e0dc9e0 /src/client/views/nodes/KeyValuePair.tsx | |
parent | b7d02ec188ecf043300ed858fdb68148b3e52a71 (diff) | |
parent | 89fd4327db1536990b4a4dc218819a1077f82445 (diff) |
merged with master
Diffstat (limited to 'src/client/views/nodes/KeyValuePair.tsx')
-rw-r--r-- | src/client/views/nodes/KeyValuePair.tsx | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/client/views/nodes/KeyValuePair.tsx b/src/client/views/nodes/KeyValuePair.tsx index 7ed5ee272..a1050dc6e 100644 --- a/src/client/views/nodes/KeyValuePair.tsx +++ b/src/client/views/nodes/KeyValuePair.tsx @@ -1,16 +1,18 @@ import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app import "./KeyValueBox.scss"; import "./KeyValuePair.scss"; -import React = require("react") +import React = require("react"); import { FieldViewProps, FieldView } from './FieldView'; import { Opt, Field } from '../../../fields/Field'; -import { observer } from "mobx-react" +import { observer } from "mobx-react"; import { observable, action } from 'mobx'; import { Document } from '../../../fields/Document'; import { Key } from '../../../fields/Key'; -import { Server } from "../../Server" +import { Server } from "../../Server"; import { EditableView } from "../EditableView"; import { CompileScript, ToField } from "../../util/Scripting"; +import { Transform } from '../../util/Transform'; +import { returnFalse, emptyFunction } from '../../../Utils'; // Represents one row in a key value plane @@ -23,7 +25,7 @@ export interface KeyValuePairProps { export class KeyValuePair extends React.Component<KeyValuePairProps> { @observable - private key: Opt<Key> + private key: Opt<Key>; constructor(props: KeyValuePairProps) { super(props); @@ -39,18 +41,21 @@ export class KeyValuePair extends React.Component<KeyValuePairProps> { render() { if (!this.key) { - return <tr><td>error</td><td></td></tr> + return <tr><td>error</td><td></td></tr>; } let props: FieldViewProps = { - doc: this.props.doc, + Document: this.props.doc, fieldKey: this.key, - isSelected: () => false, - select: () => { }, + isSelected: returnFalse, + select: emptyFunction, isTopMost: false, - bindings: {}, selectOnLoad: false, - } + active: returnFalse, + onActiveChanged: emptyFunction, + ScreenToLocalTransform: Transform.Identity, + focus: emptyFunction, + }; let contents = ( <FieldView {...props} /> ); @@ -61,39 +66,41 @@ export class KeyValuePair extends React.Component<KeyValuePairProps> { <div className="container"> <div>{this.key.Name}</div> <button className="delete" onClick={() => { - let field = props.doc.Get(props.fieldKey); + let field = props.Document.Get(props.fieldKey); if (field && field instanceof Field) { - props.doc.Set(props.fieldKey, undefined); + props.Document.Set(props.fieldKey, undefined); } }}>X</button> </div> </td> <td><EditableView contents={contents} height={36} GetValue={() => { - let field = props.doc.Get(props.fieldKey); + let field = props.Document.Get(props.fieldKey); if (field && field instanceof Field) { return field.ToScriptString(); } return field || ""; }} SetValue={(value: string) => { - let script = CompileScript(value, undefined, true); + let script = CompileScript(value, { addReturn: true }); if (!script.compiled) { return false; } - let field = script(); + let res = script.run(); + if (!res.success) return false; + const field = res.result; if (field instanceof Field) { - props.doc.Set(props.fieldKey, field); + props.Document.Set(props.fieldKey, field); return true; } else { let dataField = ToField(field); if (dataField) { - props.doc.Set(props.fieldKey, dataField); + props.Document.Set(props.fieldKey, dataField); return true; } } return false; }}></EditableView></td> </tr> - ) + ); } }
\ No newline at end of file |