aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/FieldView.tsx
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-02-10 22:12:04 -0500
committeryipstanley <stanley_yip@brown.edu>2019-02-10 22:12:04 -0500
commit69f0b463a78c82aaf78ceb6a5162431424452311 (patch)
treea54c7129f36d307420422b3babfa6da4d85db67e /src/client/views/nodes/FieldView.tsx
parent2e930b98726a09e597106d43a6763dd36d038771 (diff)
parent099c5823f05285fc5086c5a433658cf06dc4a04b (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into server_implementation
Diffstat (limited to 'src/client/views/nodes/FieldView.tsx')
-rw-r--r--src/client/views/nodes/FieldView.tsx56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/client/views/nodes/FieldView.tsx b/src/client/views/nodes/FieldView.tsx
new file mode 100644
index 000000000..12371eb2e
--- /dev/null
+++ b/src/client/views/nodes/FieldView.tsx
@@ -0,0 +1,56 @@
+import React = require("react")
+import { observer } from "mobx-react";
+import { computed } from "mobx";
+import { Field, Opt, FieldWaiting, FieldValue } from "../../../fields/Field";
+import { Document } from "../../../fields/Document";
+import { TextField } from "../../../fields/TextField";
+import { NumberField } from "../../../fields/NumberField";
+import { RichTextField } from "../../../fields/RichTextField";
+import { ImageField } from "../../../fields/ImageField";
+import { Key } from "../../../fields/Key";
+import { FormattedTextBox } from "./FormattedTextBox";
+import { ImageBox } from "./ImageBox";
+import { DocumentView } from "./DocumentView";
+
+//
+// these properties get assigned through the render() method of the DocumentView when it creates this node.
+// However, that only happens because the properties are "defined" in the markup for the field view.
+// See the LayoutString method on each field view : ImageBox, FormattedTextBox, etc.
+//
+export interface FieldViewProps {
+ fieldKey: Key;
+ doc: Document;
+ DocumentViewForField: Opt<DocumentView>
+}
+
+@observer
+export class FieldView extends React.Component<FieldViewProps> {
+ public static LayoutString(fieldType: string) { return `<${fieldType} doc={Document} DocumentViewForField={DocumentView} fieldKey={DataKey} />`; }
+ @computed
+ get field(): FieldValue<Field> {
+ const { doc, fieldKey } = this.props;
+ return doc.Get(fieldKey);
+ }
+ render() {
+ const field = this.field;
+ if (!field) {
+ return <p>{'<null>'}</p>
+ }
+ if (field instanceof TextField) {
+ return <p>{field.Data}</p>
+ }
+ else if (field instanceof RichTextField) {
+ return <FormattedTextBox {...this.props} />
+ }
+ else if (field instanceof ImageField) {
+ return <ImageBox {...this.props} />
+ }
+ else if (field instanceof NumberField) {
+ return <p>{field.Data}</p>
+ } else if (field != FieldWaiting) {
+ return <p>{field.GetValue}</p>
+ } else
+ return <p> {"Waiting for server..."} </p>
+ }
+
+} \ No newline at end of file