import { IconProp, library } from '@fortawesome/fontawesome-svg-core'; import { faCaretDown, faCaretRight, faTrashAlt } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { action, observable, trace } from "mobx"; import { observer } from "mobx-react"; import { Document } from "../../../fields/Document"; import { FieldWaiting } from "../../../fields/Field"; import { KeyStore } from "../../../fields/KeyStore"; import { ListField } from "../../../fields/ListField"; import { setupDrag } from "../../util/DragManager"; import { EditableView } from "../EditableView"; import "./CollectionTreeView.scss"; import { CollectionView, COLLECTION_BORDER_WIDTH } from "./CollectionView"; import { CollectionViewBase } from "./CollectionViewBase"; import React = require("react") export interface TreeViewProps { document: Document; deleteDoc: (doc: Document) => void; } export enum BulletType { Collapsed, Collapsible, List } library.add(faTrashAlt); library.add(faCaretDown); library.add(faCaretRight); @observer /** * Component that takes in a document prop and a boolean whether it's collapsed or not. */ class TreeView extends React.Component { @observable _collapsed: boolean = true; delete = () => this.props.deleteDoc(this.props.document); @action remove = (document: Document) => { var children = this.props.document.GetT>(KeyStore.Data, ListField); if (children && children !== FieldWaiting) { children.Data.splice(children.Data.indexOf(document), 1); } } renderBullet(type: BulletType) { let onClicked = action(() => this._collapsed = !this._collapsed); let bullet: IconProp | undefined = undefined; switch (type) { case BulletType.Collapsed: bullet = "caret-right"; break; case BulletType.Collapsible: bullet = "caret-down"; break; } return
{bullet ? : ""}
} /** * Renders the EditableView title element for placement into the tree. */ renderTitle() { let reference = React.createRef(); let onItemDown = setupDrag(reference, () => this.props.document, (containingCollection: CollectionView) => this.props.deleteDoc(this.props.document)); let editableView = (titleString: string) => ( this.props.document.Title} SetValue={(value: string) => { this.props.document.SetText(KeyStore.Title, value); return true; }} />); return (
{editableView(this.props.document.Title)}
) } render() { let bulletType = BulletType.List; let childElements: JSX.Element | undefined = undefined; var children = this.props.document.GetT>(KeyStore.Data, ListField); if (children && children !== FieldWaiting) { // add children for a collection if (!this._collapsed) { bulletType = BulletType.Collapsible; childElements =
    {children.Data.map(value => )}
} else bulletType = BulletType.Collapsed; } return
  • {this.renderBullet(bulletType)} {this.renderTitle()} {childElements ? childElements : (null)}
  • } } @observer export class CollectionTreeView extends CollectionViewBase { @action remove = (document: Document) => { var children = this.props.Document.GetT>(KeyStore.Data, ListField); if (children && children !== FieldWaiting) { children.Data.splice(children.Data.indexOf(document), 1); } } render() { 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` }}>
    this.props.Document.Title} SetValue={(value: string) => { this.props.Document.SetText(KeyStore.Title, value); return true; }} />

      {childrenElement}
    ); } }