From d1fbfc3ab46cfd9fea69b356cb5b8825625ab299 Mon Sep 17 00:00:00 2001
From: Sam Wilkins <samwilkins333@gmail.com>
Date: Thu, 22 Aug 2019 12:37:15 -0400
Subject: only shows children option if working entirely with collections

---
 src/client/views/MetadataEntryMenu.tsx | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

(limited to 'src/client/views/MetadataEntryMenu.tsx')

diff --git a/src/client/views/MetadataEntryMenu.tsx b/src/client/views/MetadataEntryMenu.tsx
index 06084aac0..df6b7f721 100644
--- a/src/client/views/MetadataEntryMenu.tsx
+++ b/src/client/views/MetadataEntryMenu.tsx
@@ -97,7 +97,6 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
             } else {
                 let childSuccess = true;
                 if (this._addChildren) {
-                    console.log(this._currentKey);
                     for (let document of doc) {
                         let collectionChildren = await DocListCastAsync(document.data);
                         if (collectionChildren) {
@@ -173,6 +172,29 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
         this._addChildren = !this._addChildren;
     }
 
+    private get considerChildOptions() {
+        let docSource = this.props.docs;
+        if (typeof docSource === "function") {
+            docSource = docSource();
+        }
+        docSource = docSource as Doc[] | Doc;
+        if (docSource instanceof Doc) {
+            if (docSource.viewType === undefined) {
+                return (null);
+            }
+        } else if (Array.isArray(docSource)) {
+            if (!docSource.every(doc => doc.viewType !== undefined)) {
+                return null;
+            }
+        }
+        return (
+            <div style={{ display: "flex" }}>
+                Children:
+                <input type="checkbox" onChange={this.onClick} ></input>
+            </div>
+        );
+    }
+
     render() {
         return (
             <div className="metadataEntry-outerDiv">
@@ -187,8 +209,7 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
                     ref={this.autosuggestRef} />
                 Value:
                 <input className="metadataEntry-input" value={this._currentValue} onChange={this.onValueChange} onKeyDown={this.onValueKeyDown} />
-                Children:
-                <input type="checkbox" onChange={this.onClick} ></input>
+                {this.considerChildOptions}
             </div >
         );
     }
-- 
cgit v1.2.3-70-g09d2

