From fa746ce5faa3f0cd0c1cd53644c6631540284802 Mon Sep 17 00:00:00 2001
From: bob <bcz@cs.brown.edu>
Date: Thu, 30 Jan 2020 13:40:32 -0500
Subject: fixes to embedded documents

---
 src/client/util/RichTextSchema.tsx | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

(limited to 'src/client/util/RichTextSchema.tsx')

diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx
index 6821d9858..287a1049b 100644
--- a/src/client/util/RichTextSchema.tsx
+++ b/src/client/util/RichTextSchema.tsx
@@ -766,27 +766,13 @@ export class DashDocView {
             if (!(dashDoc instanceof Doc)) {
                 alias && DocServer.GetRefField(docid).then(async dashDocBase => {
                     if (dashDocBase instanceof Doc) {
-                        if (node.attrs.fieldKey) {
-                            const fieldDoc = await self._textBox.dataDoc[node.attrs.fieldKey];
-                            if (fieldDoc instanceof Doc) {
-                                self.doRender(Doc.MakeAlias(fieldDoc), removeDoc, node, view, getPos);
-                            } else {
-                                this._dashSpan.innerHTML = `field:'${node.attrs.fieldKey}' is not a document`;
-                            }
-                        } else {
-                            self.doRender(Doc.MakeAlias(dashDocBase), removeDoc, node, view, getPos);
-                        }
+                        const aliasedDoc = Doc.MakeDelegate(dashDocBase, docid + alias);
+                        aliasedDoc.layoutKey = "layout_" + node.attrs.fieldKey;
+                        self.doRender(aliasedDoc, removeDoc, node, view, getPos);
                     }
                 });
             } else {
-                if (node.attrs.fieldKey) {
-                    const fieldDoc = await dashDoc[node.attrs.fieldKey];
-                    if (fieldDoc instanceof Doc) {
-                        self.doRender(fieldDoc, removeDoc, node, view, getPos);
-                    }
-                } else {
-                    self.doRender(dashDoc, removeDoc, node, view, getPos);
-                }
+                self.doRender(dashDoc, removeDoc, node, view, getPos);
             }
         });
         const self = this;
@@ -831,7 +817,7 @@ export class DashDocView {
             }, { fireImmediately: true });
             ReactDOM.render(<DocumentView
                 Document={finalLayout}
-                DataDoc={Doc.AreProtosEqual(this._textBox.Document, dashDoc) ? this._textBox.dataDoc : undefined}
+                DataDoc={!node.attrs.docid ? this._textBox.dataDoc : undefined}
                 LibraryPath={this._textBox.props.LibraryPath}
                 fitToBox={BoolCast(dashDoc._fitToBox)}
                 addDocument={returnFalse}
-- 
cgit v1.2.3-70-g09d2

