diff options
Diffstat (limited to 'src/client/views/PropertiesDocBacklinksSelector.tsx')
-rw-r--r-- | src/client/views/PropertiesDocBacklinksSelector.tsx | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/client/views/PropertiesDocBacklinksSelector.tsx b/src/client/views/PropertiesDocBacklinksSelector.tsx new file mode 100644 index 000000000..4ead8eaf0 --- /dev/null +++ b/src/client/views/PropertiesDocBacklinksSelector.tsx @@ -0,0 +1,53 @@ +import { computed } from "mobx"; +import { observer } from "mobx-react"; +import * as React from "react"; +import { Doc, DocListCast } from "../../fields/Doc"; +import { Cast } from "../../fields/Types"; +import { emptyFunction } from "../../Utils"; +import { DocumentType } from "../documents/DocumentTypes"; +import { LinkManager } from "../util/LinkManager"; +import { SelectionManager } from "../util/SelectionManager"; +import { LinkMenu } from "./linking/LinkMenu"; +import './PropertiesDocBacklinksSelector.scss'; + +type PropertiesDocBacklinksSelectorProps = { + Document: Doc, + Stack?: any, + hideTitle?: boolean, + addDocTab(doc: Doc, location: string): void +}; + +@observer +export class PropertiesDocBacklinksSelector extends React.Component<PropertiesDocBacklinksSelectorProps> { + @computed get _docs() { + const linkSource = this.props.Document; + const links = DocListCast(linkSource.links); + const collectedLinks = [] as Doc[]; + links.map(link => { + const other = LinkManager.getOppositeAnchor(link, linkSource); + const otherdoc = !other ? undefined : other.annotationOn && other.type !== DocumentType.RTF ? Cast(other.annotationOn, Doc, null) : other; + if (otherdoc && !collectedLinks.some(d => Doc.AreProtosEqual(d, otherdoc))) { + collectedLinks.push(otherdoc); + } + }); + return collectedLinks; + } + + getOnClick = (link: Doc) => { + const linkSource = this.props.Document; + const other = LinkManager.getOppositeAnchor(link, linkSource); + const otherdoc = !other ? undefined : other.annotationOn && other.type !== DocumentType.RTF ? Cast(other.annotationOn, Doc, null) : other; + + if (otherdoc) { + otherdoc.hidden = false; + this.props.addDocTab(Doc.IsPrototype(otherdoc) ? Doc.MakeDelegate(otherdoc) : otherdoc, "toggle:right"); + } + } + + render() { + return !SelectionManager.Views().length ? (null) : <div> + {this.props.hideTitle ? (null) : <p key="contexts">Contexts:</p>} + <LinkMenu docView={SelectionManager.Views().lastElement()} clearLinkEditor={emptyFunction} itemHandler={this.getOnClick} position={{ x: 0 }} /> + </div>; + } +}
\ No newline at end of file |