aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2020-09-22 10:54:11 -0400
committerbobzel <zzzman@gmail.com>2020-09-22 10:54:11 -0400
commitfb4ad82389f52838787c8179e6636428c3dc3185 (patch)
tree824c85248701369054f23ff8b8348e441d52fc9f
parent93954665f0beb8af7694b00f8d113c505d812bdf (diff)
made filters apply to links. automatically removes links that have a missing endpoint unless you own them.
-rw-r--r--src/client/util/LinkManager.ts11
-rw-r--r--src/client/views/nodes/DocumentLinksButton.tsx2
2 files changed, 8 insertions, 5 deletions
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index c7c45ec61..4f3cfcd03 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -2,6 +2,7 @@ import { Doc, DocListCast, Opt } from "../../fields/Doc";
import { List } from "../../fields/List";
import { listSpec } from "../../fields/Schema";
import { Cast, StrCast } from "../../fields/Types";
+import { CurrentUserUtils } from "./CurrentUserUtils";
/*
* link doc:
@@ -61,10 +62,12 @@ export class LinkManager {
// finds all links that contain the given anchor
public getAllDirectLinks(anchor: Doc): Doc[] {
- const related = LinkManager.Instance.getAllLinks().filter(link => {
- const protomatch1 = Doc.AreProtosEqual(anchor, Cast(link.anchor1, Doc, null));
- const protomatch2 = Doc.AreProtosEqual(anchor, Cast(link.anchor2, Doc, null));
- return protomatch1 || protomatch2 || Doc.AreProtosEqual(link, anchor);
+ const related = LinkManager.Instance.getAllLinks().filter(link => link).filter(link => {
+ const a1 = Cast(link.anchor1, Doc, null)
+ const a2 = Cast(link.anchor2, Doc, null);
+ const protomatch1 = Doc.AreProtosEqual(anchor, a1);
+ const protomatch2 = Doc.AreProtosEqual(anchor, a2);
+ return ((a1?.title !== undefined && a2?.title !== undefined) || link.author === Doc.CurrentUserEmail) && (protomatch1 || protomatch2 || Doc.AreProtosEqual(link, anchor));
});
return related;
}
diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx
index ab6cae0ad..0cb5b94f4 100644
--- a/src/client/views/nodes/DocumentLinksButton.tsx
+++ b/src/client/views/nodes/DocumentLinksButton.tsx
@@ -220,7 +220,7 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
@computed
get linkButton() {
TraceMobx();
- const links = new Set<Doc>(this.props.links);
+ const links = DocUtils.FilterDocs(Array.from(new Set<Doc>(this.props.links)), this.props.View.props.docFilters(), []);
const menuTitle = this.props.StartLink ? "Drag or tap to start link" : "Tap to complete link";
const buttonTitle = "Tap to view links";