import { action, observable } from "mobx"; import { observer } from "mobx-react"; import { DocumentView } from "./DocumentView"; import { LinkBox } from "./LinkBox"; import { LinkEditor } from "./LinkEditor"; import './LinkMenu.scss'; import React = require("react"); import { Doc, DocListCast } from "../../../new_fields/Doc"; import { Cast, FieldValue, StrCast } from "../../../new_fields/Types"; import { Id } from "../../../new_fields/FieldSymbols"; import { LinkManager, LinkUtils } from "../../util/LinkManager"; import { number, string } from "prop-types"; import { listSpec } from "../../../new_fields/Schema"; import { Utils } from "../../../Utils"; interface Props { docView: DocumentView; changeFlyout: () => void; } @observer export class LinkMenu extends React.Component { @observable private _editingLink?: Doc; // renderLinkItems(links: Doc[], key: string, type: string) { // return links.map(link => { // let doc = FieldValue(Cast(link[key], Doc)); // if (doc) { // return this._editingLink = link)} type={type} />; // } // }); // } renderGroup(links: Doc[]) { let source = this.props.docView.Document; return links.map(link => { let destination = LinkUtils.findOppositeAnchor(link, source); let doc = FieldValue(Cast(destination, Doc)); if (doc) { return this._editingLink = link)} type={""} />; } }); } renderLinks = (links: Map>): Array => { let linkItems: Array = []; links.forEach((links, group) => { linkItems.push(

{group}:

{this.renderGroup(links)}
) }); if (linkItems.length === 0) { linkItems.push(

no links have been created yet

); } return linkItems; } render() { let related: Map = LinkManager.Instance.findRelatedGroupedLinks(this.props.docView.props.Document); if (this._editingLink === undefined) { return (
{/* */}
{/* {this.renderLinkItems(linkTo, "linkedTo", "Destination: ")} {this.renderLinkItems(linkFrom, "linkedFrom", "Source: ")} */} {this.renderLinks(related)}
); } else { return ( this._editingLink = undefined)}> ); } } }