Skip to content

Commit

Permalink
fix: 🐛 node.dir and node.field is not well-defined
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 25, 2021
1 parent ba4ced5 commit 4e7c0fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/graphUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function getReflexiveClosure(
export function addNodesIfNot(
g: MultiGraph,
nodes: string[],
attr?: { dir: Directions; field: string }
attr?: { order: number }
) {
nodes.forEach((node) => {
if (!g.hasNode(node)) g.addNode(node, attr);
Expand Down
28 changes: 11 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export default class BCPlugin extends Plugin {

writeBCToFile = async (file: TFile) => {
const { app, settings, mainG } = this;
const { limitWriteBCCheckboxStates, writeBCsInline } = settings;
const { limitWriteBCCheckboxStates, writeBCsInline, userHiers } = settings;

const { frontmatter } = app.metadataCache.getFileCache(file);
const api = app.plugins.plugins.metaedit?.api;
Expand All @@ -323,10 +323,12 @@ export default class BCPlugin extends Plugin {
return;
}

const succs = getInNeighbours(mainG, file.basename);
const succInfo = mainG.mapInEdges(file.basename, (k, a, s, t) => {
const oppField = getOppFields(userHiers, a.field)[0];
return { succ: s, field: oppField };
});

for (const succ of succs) {
const { field } = mainG.getNodeAttributes(succ);
for (const { succ, field } of succInfo) {
if (!limitWriteBCCheckboxStates[field]) return;

if (!writeBCsInline) {
Expand Down Expand Up @@ -459,17 +461,10 @@ export default class BCPlugin extends Plugin {
opps?: { oppField: string; oppDir: Directions }
): void {
addNodesIfNot(mainG, [source], {
dir,
field,
//@ts-ignore
order: sourceOrder,
});
// targets.forEach((target) => {

addNodesIfNot(mainG, [target], {
dir,
field,
//@ts-ignore
order: targetOrder,
});

Expand All @@ -483,7 +478,6 @@ export default class BCPlugin extends Plugin {
field: opps.oppField,
});
}
// });
}

async getCSVRows() {
Expand Down Expand Up @@ -518,11 +512,11 @@ export default class BCPlugin extends Plugin {
) {
CSVRows.forEach((row) => {
//@ts-ignore
addNodesIfNot(g, [row.file], { dir, field });
addNodesIfNot(g, [row.file]);
if (field === "" || !row[field]) return;

//@ts-ignore
addNodesIfNot(g, [row[field]], { dir, field });
addNodesIfNot(g, [row[field]]);
//@ts-ignore
addEdgeIfNot(g, row.file, row[field], { dir, field });
});
Expand Down Expand Up @@ -679,7 +673,7 @@ export default class BCPlugin extends Plugin {
const t = hierarchyNotesArr[i + 1]?.currNote;

//@ts-ignore
addNodesIfNot(mainG, [s, t], { dir: "down", field: downField });
addNodesIfNot(mainG, [s, t]);
//@ts-ignore
addEdgeIfNot(mainG, s, t, { dir: "down", field: downField });
} else {
Expand All @@ -688,7 +682,7 @@ export default class BCPlugin extends Plugin {
field: upField,
};
//@ts-ignore
addNodesIfNot(mainG, [hnItem.currNote, hnItem.parentNote], aUp);
addNodesIfNot(mainG, [hnItem.currNote, hnItem.parentNote]);
//@ts-ignore
addEdgeIfNot(mainG, hnItem.currNote, hnItem.parentNote, aUp);

Expand All @@ -697,7 +691,7 @@ export default class BCPlugin extends Plugin {
field: downField,
};
//@ts-ignore
addNodesIfNot(mainG, [hnItem.parentNote, hnItem.currNote], aDown);
addNodesIfNot(mainG, [hnItem.parentNote, hnItem.currNote]);
//@ts-ignore
addEdgeIfNot(mainG, hnItem.parentNote, hnItem.currNote, aDown);
}
Expand Down

0 comments on commit 4e7c0fd

Please sign in to comment.