From b3bba6da52f0620b491b30c1f80bb267354a6878 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Thu, 16 Dec 2021 09:30:22 +0200 Subject: [PATCH] fix(Hierarchy Note): :bug: Don't merge all HNs, rather do one at a time (Fix #216) --- main.js | 30 +++++++++++++----------------- src/main.ts | 34 +++++++++++++++------------------- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/main.js b/main.js index a9f82c2c..bfe9f72f 100644 --- a/main.js +++ b/main.js @@ -51925,33 +51925,32 @@ class BCPlugin extends require$$0.Plugin { db.end2G({ filteredLinks }); return filteredLinks; } - addHNsToGraph(hierarchyNotesArr, mainG) { + addHNsToGraph(hnArr, mainG) { const { HNUpField, userHiers } = this.settings; const upFields = getFields(userHiers, "up"); - hierarchyNotesArr.forEach((hnItem, i) => { + hnArr.forEach((hnItem, i) => { var _a, _b; const { note, field, parent } = hnItem; const upField = field !== null && field !== void 0 ? field : (HNUpField || upFields[0]); - const downField = (_a = getOppFields(userHiers, upField)[0]) !== null && _a !== void 0 ? _a : `${upField}`; + const downField = (_a = getOppFields(userHiers, upField)[0]) !== null && _a !== void 0 ? _a : fallbackOppField(upField, "up"); if (parent === null) { const s = note; - const t = (_b = hierarchyNotesArr[i + 1]) === null || _b === void 0 ? void 0 : _b.note; + const t = (_b = hnArr[i + 1]) === null || _b === void 0 ? void 0 : _b.note; addNodesIfNot(mainG, [s, t]); addEdgeIfNot(mainG, s, t, { dir: "down", field: downField }); } else { - const aUp = { + addNodesIfNot(mainG, [note, parent]); + addEdgeIfNot(mainG, note, parent, { dir: "up", field: upField, - }; - addNodesIfNot(mainG, [note, parent]); - addEdgeIfNot(mainG, note, parent, aUp); - const aDown = { + }); + // I don't think this needs to be done if the reverse is done above + addNodesIfNot(mainG, [parent, note]); + addEdgeIfNot(mainG, parent, note, { dir: "down", field: downField, - }; - addNodesIfNot(mainG, [parent, note]); - addEdgeIfNot(mainG, parent, note, aDown); + }); } }); } @@ -52215,21 +52214,18 @@ class BCPlugin extends require$$0.Plugin { // !SECTION Juggl Links // SECTION Hierarchy Notes db.start2G("Hierarchy Notes"); - const hierarchyNotesArr = []; if (settings.hierarchyNotes[0] !== "") { for (const note of settings.hierarchyNotes) { const file = app.metadataCache.getFirstLinkpathDest(note, ""); if (file) { - hierarchyNotesArr.push(...(await this.getHierarchyNoteItems(file))); + this.addHNsToGraph(await this.getHierarchyNoteItems(file), mainG); } else { new require$$0.Notice(`${note} is no longer in your vault. It is best to remove it in Breadcrumbs settings.`); } } } - if (hierarchyNotesArr.length) - this.addHNsToGraph(hierarchyNotesArr, mainG); - db.end2G({ hierarchyNotesArr }); + db.end2G(); // !SECTION Hierarchy Notes console.time("Folder-Notes"); this.addFolderNotesToGraph(eligableAlts[BC_FOLDER_NOTE], frontms, mainG); diff --git a/src/main.ts b/src/main.ts index 0ebae084..87ea8540 100644 --- a/src/main.ts +++ b/src/main.ts @@ -79,6 +79,7 @@ import MatrixView from "./MatrixView"; import { createOrUpdateYaml, dropWikilinks, + fallbackOppField, getBaseFromMDPath, getDVBasename, getFields, @@ -794,37 +795,35 @@ export default class BCPlugin extends Plugin { return filteredLinks; } - addHNsToGraph(hierarchyNotesArr: HierarchyNoteItem[], mainG: MultiGraph) { + addHNsToGraph(hnArr: HierarchyNoteItem[], mainG: MultiGraph) { const { HNUpField, userHiers } = this.settings; const upFields = getFields(userHiers, "up"); - hierarchyNotesArr.forEach((hnItem, i) => { + hnArr.forEach((hnItem, i) => { const { note, field, parent } = hnItem; const upField = field ?? (HNUpField || upFields[0]); const downField = - getOppFields(userHiers, upField)[0] ?? `${upField}`; + getOppFields(userHiers, upField)[0] ?? fallbackOppField(upField, "up"); if (parent === null) { const s = note; - const t = hierarchyNotesArr[i + 1]?.note; + const t = hnArr[i + 1]?.note; addNodesIfNot(mainG, [s, t]); addEdgeIfNot(mainG, s, t, { dir: "down", field: downField }); } else { - const aUp = { + addNodesIfNot(mainG, [note, parent]); + addEdgeIfNot(mainG, note, parent, { dir: "up", field: upField, - }; - - addNodesIfNot(mainG, [note, parent]); - addEdgeIfNot(mainG, note, parent, aUp); + }); - const aDown = { + // I don't think this needs to be done if the reverse is done above + addNodesIfNot(mainG, [parent, note]); + addEdgeIfNot(mainG, parent, note, { dir: "down", field: downField, - }; - addNodesIfNot(mainG, [parent, note]); - addEdgeIfNot(mainG, parent, note, aDown); + }); } }); } @@ -1219,15 +1218,15 @@ export default class BCPlugin extends Plugin { this.addJugglLinksToGraph(jugglLinks, frontms, mainG); // !SECTION Juggl Links + // SECTION Hierarchy Notes db.start2G("Hierarchy Notes"); - const hierarchyNotesArr: HierarchyNoteItem[] = []; if (settings.hierarchyNotes[0] !== "") { for (const note of settings.hierarchyNotes) { const file = app.metadataCache.getFirstLinkpathDest(note, ""); if (file) { - hierarchyNotesArr.push(...(await this.getHierarchyNoteItems(file))); + this.addHNsToGraph(await this.getHierarchyNoteItems(file), mainG); } else { new Notice( `${note} is no longer in your vault. It is best to remove it in Breadcrumbs settings.` @@ -1236,10 +1235,7 @@ export default class BCPlugin extends Plugin { } } - if (hierarchyNotesArr.length) - this.addHNsToGraph(hierarchyNotesArr, mainG); - - db.end2G({ hierarchyNotesArr }); + db.end2G(); // !SECTION Hierarchy Notes console.time("Folder-Notes");