blob: 2fcbd25fa2e466ed0231cd54e7b59fca215f3416 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
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 { Id } from "../../../new_fields/FieldSymbols";
import { LinkManager } from "../../util/LinkManager";
interface Props {
docView: DocumentView;
changeFlyout: () => void;
}
@observer
export class LinkMenu extends React.Component<Props> {
@observable private _editingLink?: Doc;
renderGroup = (group: Doc[]): Array<JSX.Element> => {
let source = this.props.docView.Document;
return group.map(linkDoc => {
let destination = LinkManager.Instance.findOppositeAnchor(linkDoc, source);
return <LinkBox key={destination[Id] + source[Id]} linkDoc={linkDoc} sourceDoc={source} destinationDoc={destination} showEditor={action(() => this._editingLink = linkDoc)} />;
});
}
renderAllGroups = (groups: Map<string, Array<Doc>>): Array<JSX.Element> => {
let linkItems: Array<JSX.Element> = [];
groups.forEach((group, groupType) => {
linkItems.push(
<div key={groupType} className="link-menu-group">
<p className="link-menu-group-name">{groupType}:</p>
<div className="link-menu-group-wrapper">
{this.renderGroup(group)}
</div>
</div>
);
});
// source doc has no links
if (linkItems.length === 0) linkItems.push(<p key="">No links have been created yet. Drag the linking button onto another document to create a link.</p>);
return linkItems;
}
render() {
let sourceDoc = this.props.docView.props.Document;
let groups: Map<string, Doc[]> = LinkManager.Instance.findRelatedGroupedLinks(sourceDoc);
if (this._editingLink === undefined) {
return (
<div className="linkMenu">
{/* <input id="linkMenu-searchBar" type="text" placeholder="Search..."></input> */}
<div className="linkMenu-list">
{this.renderAllGroups(groups)}
</div>
</div>
);
} else {
return (
<LinkEditor sourceDoc={this.props.docView.props.Document} linkDoc={this._editingLink} showLinks={action(() => this._editingLink = undefined)}></LinkEditor>
);
}
}
}
|