aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionSchemaView.tsx
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-04-07 17:39:23 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-04-07 17:39:23 -0400
commitbf05eac7677997075bc58d2b70c3e101e2e87560 (patch)
tree954ed3322e7630947fa3d6c5902c7e648018ef67 /src/client/views/collections/CollectionSchemaView.tsx
parent44aa6fe49de97998fd84a6d6331501c8a1d7a775 (diff)
Refactored schema scripting
Changed tree view style to not be global
Diffstat (limited to 'src/client/views/collections/CollectionSchemaView.tsx')
-rw-r--r--src/client/views/collections/CollectionSchemaView.tsx21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx
index afe530c1a..b10aaba98 100644
--- a/src/client/views/collections/CollectionSchemaView.tsx
+++ b/src/client/views/collections/CollectionSchemaView.tsx
@@ -86,12 +86,8 @@ export class CollectionSchemaView extends CollectionViewBase {
)
let reference = React.createRef<HTMLDivElement>();
let onItemDown = setupDrag(reference, () => props.doc, (containingCollection: CollectionView) => this.props.removeDocument(props.doc));
- let applyToDoc = (doc: Document, value: string) => {
- let script = CompileScript(value, { addReturn: true, params: { this: "Document" } });
- if (!script.compiled) {
- return false;
- }
- const res = script.run({ this: doc });
+ let applyToDoc = (doc: Document, run: (args?: { [name: string]: any }) => any) => {
+ const res = run({ this: doc });
if (!res.success) return false;
const field = res.result;
if (field instanceof Field) {
@@ -120,13 +116,22 @@ export class CollectionSchemaView extends CollectionViewBase {
return field || "";
}}
SetValue={(value: string) => {
- return applyToDoc(props.doc, value);
+ let script = CompileScript(value, { addReturn: true, params: { this: "Document" } });
+ if (!script.compiled) {
+ return false;
+ }
+ return applyToDoc(props.doc, script.run);
}}
OnFillDown={(value: string) => {
+ let script = CompileScript(value, { addReturn: true, params: { this: "Document" } });
+ if (!script.compiled) {
+ return;
+ }
+ const run = script.run;
//TODO This should be able to be refactored to compile the script once
this.props.Document.GetTAsync<ListField<Document>>(this.props.fieldKey, ListField).then((val) => {
if (val) {
- val.Data.forEach(doc => applyToDoc(doc, value));
+ val.Data.forEach(doc => applyToDoc(doc, run));
}
})
}}>