From 158a6f960f6c069af16ab0b84df8ce76c7327ebc Mon Sep 17 00:00:00 2001
From: Fawn <fangrui_tong@brown.edu>
Date: Fri, 9 Aug 2019 15:20:11 -0400
Subject: first commit

---
 src/client/views/MetadataEntryMenu.tsx | 2 ++
 1 file changed, 2 insertions(+)

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

diff --git a/src/client/views/MetadataEntryMenu.tsx b/src/client/views/MetadataEntryMenu.tsx
index 36c240dd8..abdd876fa 100644
--- a/src/client/views/MetadataEntryMenu.tsx
+++ b/src/client/views/MetadataEntryMenu.tsx
@@ -169,6 +169,8 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
                     ref={this.autosuggestRef} />
                 Value:
                 <input className="metadataEntry-input" value={this._currentValue} onChange={this.onValueChange} onKeyDown={this.onValueKeyDown} />
+                Spread to children:
+                <input type="checkbox"></input>
             </div>
         );
     }
-- 
cgit v1.2.3-70-g09d2


From e7883760751d053133c8bb9b867509fa23f40b68 Mon Sep 17 00:00:00 2001
From: Fawn <fangrui_tong@brown.edu>
Date: Fri, 9 Aug 2019 15:38:49 -0400
Subject: pushing work so far

---
 src/client/views/MetadataEntryMenu.tsx | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

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

diff --git a/src/client/views/MetadataEntryMenu.tsx b/src/client/views/MetadataEntryMenu.tsx
index abdd876fa..426b24212 100644
--- a/src/client/views/MetadataEntryMenu.tsx
+++ b/src/client/views/MetadataEntryMenu.tsx
@@ -20,6 +20,7 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
     @observable private _currentValue: string = "";
     @observable private suggestions: string[] = [];
     private userModified = false;
+    private _addChildren = false;
 
     private autosuggestRef = React.createRef<Autosuggest>();
 
@@ -82,6 +83,9 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
             e.stopPropagation();
             const script = KeyValueBox.CompileKVPScript(this._currentValue);
             if (!script) return;
+            // add optional adding here
+            let docs = Array<Doc>();
+
             let doc = this.props.docs;
             if (typeof doc === "function") {
                 doc = doc();
@@ -155,6 +159,11 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
         this.suggestions = [];
     }
 
+    onClick = (e: React.ChangeEvent<HTMLInputElement>) => {
+        this._addChildren = !this._addChildren;
+        console.log(this._addChildren);
+    }
+
     render() {
         return (
             <div className="metadataEntry-outerDiv">
@@ -170,7 +179,7 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
                 Value:
                 <input className="metadataEntry-input" value={this._currentValue} onChange={this.onValueChange} onKeyDown={this.onValueKeyDown} />
                 Spread to children:
-                <input type="checkbox"></input>
+                <input type="checkbox" onChange={this.onClick} checked={this._addChildren}></input>
             </div>
         );
     }
-- 
cgit v1.2.3-70-g09d2


From 104e63288b93d4211244f8aa28a07603bd78cd42 Mon Sep 17 00:00:00 2001
From: kimdahey <claire_kim1@brown.edu>
Date: Mon, 19 Aug 2019 14:50:31 -0400
Subject: added ability to pass down kvp to children

---
 src/client/views/MetadataEntryMenu.scss |  4 ++++
 src/client/views/MetadataEntryMenu.tsx  | 24 ++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

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

diff --git a/src/client/views/MetadataEntryMenu.scss b/src/client/views/MetadataEntryMenu.scss
index bcfc9a82d..d665f028c 100644
--- a/src/client/views/MetadataEntryMenu.scss
+++ b/src/client/views/MetadataEntryMenu.scss
@@ -1,6 +1,10 @@
 .metadataEntry-outerDiv {
     display: flex;
     width: 300px;
+
+    input[type=checkbox] {
+        margin-left: 5px;
+    }
 }
 
 .react-autosuggest__container {
diff --git a/src/client/views/MetadataEntryMenu.tsx b/src/client/views/MetadataEntryMenu.tsx
index 36c240dd8..437de741f 100644
--- a/src/client/views/MetadataEntryMenu.tsx
+++ b/src/client/views/MetadataEntryMenu.tsx
@@ -3,9 +3,10 @@ import "./MetadataEntryMenu.scss";
 import { observer } from 'mobx-react';
 import { observable, action, runInAction, trace } from 'mobx';
 import { KeyValueBox } from './nodes/KeyValueBox';
-import { Doc, Field } from '../../new_fields/Doc';
+import { Doc, Field, DocListCast, DocListCastAsync } from '../../new_fields/Doc';
 import * as Autosuggest from 'react-autosuggest';
 import { undoBatch } from '../util/UndoManager';
+import { child } from 'serializr';
 
 export type DocLike = Doc | Doc[] | Promise<Doc> | Promise<Doc[]>;
 export interface MetadataEntryProps {
@@ -19,6 +20,7 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
     @observable private _currentKey: string = "";
     @observable private _currentValue: string = "";
     @observable private suggestions: string[] = [];
+    private _addChildren: boolean = false;
     private userModified = false;
 
     private autosuggestRef = React.createRef<Autosuggest>();
@@ -82,16 +84,28 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
             e.stopPropagation();
             const script = KeyValueBox.CompileKVPScript(this._currentValue);
             if (!script) return;
+
             let doc = this.props.docs;
             if (typeof doc === "function") {
                 doc = doc();
             }
             doc = await doc;
+
             let success: boolean;
             if (doc instanceof Doc) {
                 success = KeyValueBox.ApplyKVPScript(doc, this._currentKey, script);
             } else {
-                success = doc.every(d => KeyValueBox.ApplyKVPScript(d, this._currentKey, script));
+                let childSuccess = true;
+                if (this._addChildren) {
+                    console.log(this._currentKey);
+                    for (let document of doc) {
+                        let collectionChildren = await DocListCastAsync(document.data);
+                        if (collectionChildren) {
+                            childSuccess = collectionChildren.every(c => KeyValueBox.ApplyKVPScript(c, this._currentKey, script));
+                        }
+                    }
+                }
+                success = doc.every(d => KeyValueBox.ApplyKVPScript(d, this._currentKey, script)) && childSuccess;
             }
             if (!success) {
                 if (this.props.onError) {
@@ -155,6 +169,10 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
         this.suggestions = [];
     }
 
+    onClick = (e: React.ChangeEvent<HTMLInputElement>) => {
+        this._addChildren = !this._addChildren;
+    }
+
     render() {
         return (
             <div className="metadataEntry-outerDiv">
@@ -169,6 +187,8 @@ 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>
             </div>
         );
     }
-- 
cgit v1.2.3-70-g09d2


From 616d71c6ad8b15b9736ada0754c557c2a81964bc Mon Sep 17 00:00:00 2001
From: kimdahey <claire_kim1@brown.edu>
Date: Mon, 19 Aug 2019 15:07:31 -0400
Subject: fixed errors

---
 src/client/views/MetadataEntryMenu.tsx | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

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

diff --git a/src/client/views/MetadataEntryMenu.tsx b/src/client/views/MetadataEntryMenu.tsx
index aed84768e..06084aac0 100644
--- a/src/client/views/MetadataEntryMenu.tsx
+++ b/src/client/views/MetadataEntryMenu.tsx
@@ -22,7 +22,6 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
     @observable private suggestions: string[] = [];
     private _addChildren: boolean = false;
     private userModified = false;
-    private _addChildren = false;
 
     private autosuggestRef = React.createRef<Autosuggest>();
 
@@ -85,11 +84,6 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
             e.stopPropagation();
             const script = KeyValueBox.CompileKVPScript(this._currentValue);
             if (!script) return;
-<<<<<<< HEAD
-=======
-            // add optional adding here
-            let docs = Array<Doc>();
->>>>>>> e7883760751d053133c8bb9b867509fa23f40b68
 
             let doc = this.props.docs;
             if (typeof doc === "function") {
@@ -193,13 +187,8 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{
                     ref={this.autosuggestRef} />
                 Value:
                 <input className="metadataEntry-input" value={this._currentValue} onChange={this.onValueChange} onKeyDown={this.onValueKeyDown} />
-<<<<<<< HEAD
-        Children:
-        <input type="checkbox" onChange={this.onClick} ></input>
-=======
-                Spread to children:
-                <input type="checkbox" onChange={this.onClick} checked={this._addChildren}></input>
->>>>>>> e7883760751d053133c8bb9b867509fa23f40b68
+                Children:
+                <input type="checkbox" onChange={this.onClick} ></input>
             </div >
         );
     }
-- 
cgit v1.2.3-70-g09d2


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

