Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(map): add `mapIncludeRelation` and `mapExcludeRelation` to include only or exclude specific relation types
Kieran9d99da14e1a7
diff --git a/apps/client/src/widgets/note_map.ts b/apps/client/src/widgets/note_map.tsindex d7fb10af47..d0274fc862 100644--- a/apps/client/src/widgets/note_map.ts+++ b/apps/client/src/widgets/note_map.ts@@ -324,7 +324,13 @@ export default class NoteMapWidget extends NoteContextAwareWidget {}const mapRootNoteId = this.getMapRootNoteId();- const data = await this.loadNotesAndRelations(mapRootNoteId);++ const labelValues = (name: string) => this.note?.getLabels(name).map(l => l.value) ?? [];++ const excludeRelations = labelValues("mapExcludeRelation");+ const includeRelations = labelValues("mapIncludeRelation");++ const data = await this.loadNotesAndRelations(mapRootNoteId, excludeRelations, includeRelations);const nodeLinkRatio = data.nodes.length / data.links.length;const magnifiedRatio = Math.pow(nodeLinkRatio, 1.5);@@ -473,8 +479,10 @@ export default class NoteMapWidget extends NoteContextAwareWidget {ctx.restore();}- async loadNotesAndRelations(mapRootNoteId: string): Promise<NotesAndRelationsData> {- const resp = await server.post<PostNotesMapResponse>(`note-map/${mapRootNoteId}/${this.mapType}`);+ async loadNotesAndRelations(mapRootNoteId: string, excludeRelations: string[], includeRelations: string[]): Promise<NotesAndRelationsData> {+ const resp = await server.post<PostNotesMapResponse>(`note-map/${mapRootNoteId}/${this.mapType}`, {+ excludeRelations, includeRelations+ });this.calculateNodeSizes(resp);diff --git a/apps/server/src/routes/api/note_map.ts b/apps/server/src/routes/api/note_map.tsindex 470152bd64..b77c634c22 100644--- a/apps/server/src/routes/api/note_map.ts+++ b/apps/server/src/routes/api/note_map.ts@@ -110,6 +110,11 @@ function getLinkMap(req: Request) {const ignoreExcludeFromNoteMap = mapRootNote.isLabelTruthy("excludeFromNoteMap");let unfilteredNotes;+ const toSet = (data: unknown) => new Set<string>(data instanceof Array ? data : []);++ const excludeRelations = toSet(req.body.excludeRelations);+ const includeRelations = toSet(req.body.includeRelations);+if (mapRootNote.type === "search") {// for search notes, we want to consider the direct search results only without the descendantsunfilteredNotes = mapRootNote.getSearchResultNotes();@@ -152,6 +157,10 @@ function getLinkMap(req: Request) {}return !parentNote.getChildNotes().find((childNote) => childNote.noteId === rel.value);+ } else if (includeRelations.size != 0 && !includeRelations.has(rel.name)) {+ return false;+ } else if (excludeRelations.has(rel.name)) {+ return false;} else {return true;}