From ef4cfe47ba73e63e91bb389ea8a55951baf20067 Mon Sep 17 00:00:00 2001 From: madelinegr Date: Tue, 26 Feb 2019 18:21:52 -0500 Subject: collapsing things no longer make other siblings die --- .../views/collections/CollectionTreeView.tsx | 73 +++++++++++----------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionTreeView.tsx b/src/client/views/collections/CollectionTreeView.tsx index 25885cf49..924312d06 100644 --- a/src/client/views/collections/CollectionTreeView.tsx +++ b/src/client/views/collections/CollectionTreeView.tsx @@ -31,8 +31,6 @@ class TreeView extends React.Component { @observable collapsed: boolean = false; - - // TODO this will eventually come with functions for what to attach to them renderBullet(type: BulletType) { let onClicked = action(() => this.collapsed = !this.collapsed); @@ -47,48 +45,56 @@ class TreeView extends React.Component { } /** - * Renders a single child document. If this child is a collection, it will call renderTreeView again. Otherwise, it will just append a list element. - * @param childDocument The document to render. + * Renders the EditableView title element for placement into the tree. */ - renderChild(childDocument: Document) { - let reference = React.createRef(); - var children = childDocument.GetT>(KeyStore.Data, ListField); - let title = childDocument.GetT(KeyStore.Title, TextField); - let onItemDown = setupDrag(reference, () => childDocument); + renderTitle() { + let title = this.props.document.GetT(KeyStore.Title, TextField); // if the title hasn't loaded, immediately return the div if (!title || title === "") { - return
; + return
; } - // set up the title element, which will be rendered the same way for everyone - let titleElement = { - let title = childDocument.GetT(KeyStore.Title, TextField); + let title = this.props.document.GetT(KeyStore.Title, TextField); if (title && title !== "") return title.Data; return ""; }} SetValue={(value: string) => { - childDocument.SetData(KeyStore.Title, value, TextField); + this.props.document.SetData(KeyStore.Title, value, TextField); return true; }} /> + } + + render() { + var children = this.props.document.GetT>(KeyStore.Data, ListField); + + let reference = React.createRef(); + let onItemDown = setupDrag(reference, () => this.props.document); + let titleElement = this.renderTitle(); - // otherwise, check if it's a collection. - if (children && children !== "") { - // if it's not collapsed, then render the full TreeView. + // check if this document is a collection + if (children && children !== FieldWaiting) { var subView = null; + // render all children elements + let childrenElement = (children.Data.map(value => + ) + ) + + // if uncollapsed, then add the children elements if (!this.collapsed) { subView = -
  • +
  • {this.renderBullet(BulletType.Collapsible)} {titleElement} -
      - +
        + {childrenElement}
      } else { - subView =
    • + subView =
    • {this.renderBullet(BulletType.Collapsed)} {titleElement}
    • @@ -99,24 +105,14 @@ class TreeView extends React.Component { } - // finally, if it's a normal document, then render it as such. + // otherwise this is a normal leaf node else { - return
    • + return
    • {this.renderBullet(BulletType.List)} {titleElement}
    • ; } } - - render() { - var children = this.props.document.GetT>(KeyStore.Data, ListField); - return !children || children === FieldWaiting ? (null) : - (children.Data.map(value => -
      - {this.renderChild(value)} -
      ) - ) - } } @@ -129,6 +125,13 @@ export class CollectionTreeView extends CollectionViewBase { if (title && title !== FieldWaiting) { titleStr = title.Data; } + + var children = this.props.Document.GetT>(KeyStore.Data, ListField); + let childrenElement = !children || children === FieldWaiting ? (null) : + (children.Data.map(value => + ) + ) + return (
      this.onDrop(e, {})} ref={this.createDropTarget} style={{ borderWidth: `${COLLECTION_BORDER_WIDTH}px` }}>

      @@ -144,9 +147,7 @@ export class CollectionTreeView extends CollectionViewBase { }} />

        - + {childrenElement}
      ); -- cgit v1.2.3-70-g09d2