From 76ca4c61c5bf68649b889ed6ac8b5f6dc5b16e0b Mon Sep 17 00:00:00 2001
From: Sam Wilkins <samwilkins333@gmail.com>
Date: Sat, 18 Jan 2020 23:25:22 -0500
Subject: added initial DocumentFromField implementation

---
 .../collections/CollectionStackingViewFieldColumn.tsx   | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

(limited to 'src/client/views/collections/CollectionStackingViewFieldColumn.tsx')

diff --git a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
index 9cdb9b281..23a664359 100644
--- a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
+++ b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
@@ -138,18 +138,11 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
         if (value === ":freeForm") {
             return this.props.parent.props.addDocument(Docs.Create.FreeformDocument([], { width: 200, height: 200 }));
         } else if (value.startsWith(":")) {
-            const field = value.substring(1);
-            if (this.props.parent.props.Document[field] instanceof ImageField) {
-                let doc = Docs.Create.ImageDocument((this.props.parent.props.Document[field] as ImageField).url.href, {});
-                doc.layout = ImageBox.LayoutString(field);
-                doc.proto = Doc.GetProto(this.props.parent.props.Document);
-                return this.props.parent.props.addDocument(doc);
-            } else {
-                let doc = Docs.Create.TextDocument({ width: 200, height: 25, autoHeight: true });
-                doc.layout = FormattedTextBox.LayoutString(field);
-                doc.proto = Doc.GetProto(this.props.parent.props.Document);
-                return this.props.parent.props.addDocument(doc);
-            }
+            const { Document, addDocument } = this.props.parent.props;
+            const fieldKey = value.substring(1);
+            const proto = Doc.GetProto(Document);
+            const created = Docs.Get.DocumentFromField(Document, fieldKey, proto);
+            return created ? addDocument(created) : false;
         }
         this._createAliasSelected = false;
         const key = StrCast(this.props.parent.props.Document.sectionFilter);
-- 
cgit v1.2.3-70-g09d2

