From 5e528b752b37b890d8c9b2421ef3db6efd3e13bb Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sun, 15 Aug 2021 10:12:30 +0200 Subject: [PATCH] feat(List/Matrix View): :sparkles: Setting: Filter implied siblings of different types --- src/BreadcrumbsSettingTab.ts | 16 ++++++++++++++++ src/MatrixView.ts | 10 +++++++++- src/interfaces.ts | 1 + src/main.ts | 1 + src/sharedFunctions.ts | 5 ++++- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index ebb480d9..00f67196 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -331,6 +331,7 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { }) ); + // TODO I don't think this setting works anymore. I removed it's functionality when adding multiple hierarchies new Setting(MLViewDetails) .setName("Show all field names or just relation types") .setDesc( @@ -361,6 +362,21 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { }) ); + new Setting(MLViewDetails) + .setName("Filter Implied Siblings") + .setDesc( + "Implied siblings are: 1) notes with the same parent, or 2) notes that are real siblings. This setting only applies to type 1 implied siblings. If enabled, Breadcrumbs will filter type 1 implied siblings so that they not only share the same parent, but the parent relation has the exact same type. For example, the two real relations B --parent-> A, and A --parent-> A create an implied sibling between B and C (they have the same parent, A). The two real relations B --parent-> A, and A --up-> A create an implied sibling between B and C (they also have the same parent, A). But if this setting is turned on, the second implied sibling would not show, because the parent types are differnet (parent versus up)." + ) + .addToggle((toggle) => + toggle + .setValue(plugin.settings.filterImpliedSiblingsOfDifferentTypes) + .onChange(async (value) => { + plugin.settings.filterImpliedSiblingsOfDifferentTypes = value; + await plugin.saveSettings(); + await plugin.getActiveMatrixView().draw(); + }) + ); + new Setting(MLViewDetails) .setName("Open View in Right or Left side") .setDesc( diff --git a/src/MatrixView.ts b/src/MatrixView.ts index a5c547b8..bfd78a86 100644 --- a/src/MatrixView.ts +++ b/src/MatrixView.ts @@ -295,7 +295,15 @@ export default class MatrixView extends ItemView { const indexCurrNote = impliedSiblings.indexOf(currFile.basename); impliedSiblings.splice(indexCurrNote, 1); - // Create thie implied sibling SquareProps + if (settings.filterImpliedSiblingsOfDifferentTypes) { + impliedSiblings = impliedSiblings.filter((iSibling) => { + const iSiblingType = currUpG.node(iSibling).fieldName; + const currNodeType = currUpG.node(currFile.basename).fieldName; + console.log({ iSiblingType, currNodeType }); + return iSiblingType === currNodeType; + }); + } + // Create the implied sibling SquareProps impliedSiblings.forEach((impliedSibling) => { iSameArr.push({ to: impliedSibling, diff --git a/src/interfaces.ts b/src/interfaces.ts index 5fbb6080..f8a2f60b 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -12,6 +12,7 @@ export interface BreadcrumbsSettings { defaultView: boolean; showNameOrType: boolean; showRelationType: boolean; + filterImpliedSiblingsOfDifferentTypes: boolean; rlLeaf: boolean; showTrail: boolean; trailOrTable: 1 | 2 | 3; diff --git a/src/main.ts b/src/main.ts index deb52000..a9fac21e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -48,6 +48,7 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = { defaultView: true, showNameOrType: true, showRelationType: true, + filterImpliedSiblingsOfDifferentTypes: false, rlLeaf: true, showTrail: true, trailOrTable: 3, diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts index 2ff16a71..010d754d 100644 --- a/src/sharedFunctions.ts +++ b/src/sharedFunctions.ts @@ -481,7 +481,10 @@ export function mergeGs(...graphs: Graph[]) { const outG = new Graph(); graphs.forEach((graph) => { graph.edges().forEach((edge) => { - outG.setEdge(edge); + const nodeLabel = graph.node(edge.v); + outG.setNode(edge.v, nodeLabel); + const edgeLabel = graph.edge(edge); + outG.setEdge(edge, edgeLabel); }); }); return outG;