aboutsummaryrefslogtreecommitdiff
path: root/src/views/collections/CollectionSchemaView.tsx
diff options
context:
space:
mode:
authorHannah <hannah_chow@brown.edu>2019-02-07 15:50:23 -0500
committerHannah <hannah_chow@brown.edu>2019-02-07 15:50:23 -0500
commit090093a50397ddc2a8fc2c50f5097f4a4ea8a74c (patch)
tree32ed9f841109c3607ee70bc99ee4a6c9d5d1c06e /src/views/collections/CollectionSchemaView.tsx
parent5b55e1b6081393989ca35d2964da9604c2a93802 (diff)
started adding editable schema cells
Diffstat (limited to 'src/views/collections/CollectionSchemaView.tsx')
-rw-r--r--src/views/collections/CollectionSchemaView.tsx29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/views/collections/CollectionSchemaView.tsx b/src/views/collections/CollectionSchemaView.tsx
index 8817cb496..c7a3d81a4 100644
--- a/src/views/collections/CollectionSchemaView.tsx
+++ b/src/views/collections/CollectionSchemaView.tsx
@@ -11,6 +11,9 @@ import "./CollectionSchemaView.scss"
import { ScrollBox } from "../../util/ScrollBox";
import { CollectionViewBase } from "./CollectionViewBase";
import { DocumentView } from "../nodes/DocumentView";
+import { EditableView } from "../EditableView";
+import { CompileScript } from "../../util/Scripting";
+import { Field } from "../../fields/Field";
@observer
export class CollectionSchemaView extends CollectionViewBase {
@@ -25,9 +28,29 @@ export class CollectionSchemaView extends CollectionViewBase {
fieldKey: rowProps.value[1],
DocumentViewForField: undefined
}
- return (
+ let contents = (
<FieldView {...props} />
)
+ return (
+ <EditableView contents={contents} GetValue={() => {
+ let field = props.doc.Get(props.fieldKey);
+ if (field && field instanceof Field) {
+ return field.ToScriptString();
+ }
+ return field || "";
+ }} SetValue={(value: string) => {
+ let script = CompileScript(value);
+ if (!script.compiled) {
+ return false;
+ }
+ let field = script();
+ if (field instanceof Field) {
+ props.doc.Set(props.fieldKey, field);
+ return true;
+ }
+ return false;
+ }}></EditableView>
+ )
}
private getTrProps: ComponentPropsGetterR = (state, rowInfo) => {
@@ -74,7 +97,9 @@ export class CollectionSchemaView extends CollectionViewBase {
[KS.Title, KS.Data, KS.Author])
let content;
if (this.selectedIndex != -1) {
- content = (<DocumentView Document={children[this.selectedIndex]} DocumentView={undefined} ContainingCollectionView={this} />)
+ content = (
+ <DocumentView Document={children[this.selectedIndex]} DocumentView={undefined} ContainingCollectionView={this} />
+ )
} else {
content = <div />
}