aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkimdahey <claire_kim1@brown.edu>2019-08-19 14:50:31 -0400
committerkimdahey <claire_kim1@brown.edu>2019-08-19 14:50:31 -0400
commit104e63288b93d4211244f8aa28a07603bd78cd42 (patch)
tree9f6edb8942fe637958d08d198dfe3dd916c345ec /src
parentb037aa89fb564812f880994453ce002054a0ad82 (diff)
added ability to pass down kvp to children
Diffstat (limited to 'src')
-rw-r--r--src/client/views/MetadataEntryMenu.scss4
-rw-r--r--src/client/views/MetadataEntryMenu.tsx24
2 files changed, 26 insertions, 2 deletions
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>
);
}