diff options
Diffstat (limited to 'src/client/views/MetadataEntryMenu.tsx')
-rw-r--r-- | src/client/views/MetadataEntryMenu.tsx | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/client/views/MetadataEntryMenu.tsx b/src/client/views/MetadataEntryMenu.tsx index 426b24212..aed84768e 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 _addChildren = false; @@ -83,19 +85,33 @@ 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") { 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) { @@ -161,7 +177,6 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ onClick = (e: React.ChangeEvent<HTMLInputElement>) => { this._addChildren = !this._addChildren; - console.log(this._addChildren); } render() { @@ -178,9 +193,14 @@ 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> - </div> +>>>>>>> e7883760751d053133c8bb9b867509fa23f40b68 + </div > ); } }
\ No newline at end of file |