Skip to content

Commit

Permalink
fix(List/Matrix View): 🐛 Allow empty reverse fields (Fix #203)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Dec 7, 2021
1 parent 7068d99 commit 3d0cd5d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
27 changes: 23 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22257,13 +22257,15 @@ function swapItems(i, j, arr) {
return arr;
}
const linkClass = (app, to, realQ = true) => `internal-link BC-Link ${isInVault(app, to) ? "" : "is-unresolved"} ${realQ ? "" : "BC-Implied"}`;
const fallbackOppField = (field, dir) => `${field} <${ARROW_DIRECTIONS[getOppDir(dir)]}>`;
/** Remember to filter by hierarchy in MatrixView! */
function getRealnImplied(plugin, currNode, dir = null) {
const realsnImplieds = blankRealNImplied();
const { userHiers } = plugin.settings;
plugin.mainG.forEachEdge(currNode, (k, a, s, t) => {
var _a;
const { field, dir: edgeDir } = a;
const oppField = getOppFields(userHiers, field)[0];
const oppField = (_a = getOppFields(userHiers, field)[0]) !== null && _a !== void 0 ? _a : fallbackOppField(field, edgeDir);
(dir ? [dir, getOppDir(dir)] : DIRECTIONS$1).forEach((currDir) => {
const oppDir = getOppDir(currDir);
// Reals
Expand Down Expand Up @@ -24564,12 +24566,18 @@ class MatrixView extends require$$0.ItemView {
return userHiers.map((hier) => {
const filteredRealNImplied = blankRealNImplied();
for (const dir in realsnImplieds) {
const oppDir = getOppDir(dir);
const arrow = ARROW_DIRECTIONS[dir];
const { reals, implieds } = realsnImplieds[dir];
filteredRealNImplied[dir].reals = reals
.filter((real) => hier[dir].includes(real.field))
.filter((real) => hier[dir].includes(real.field) ||
(real.field.includes(`<${arrow}>`) &&
hier[oppDir].includes(real.field.split(" <")[0])))
.map((item) => this.toInternalLinkObj(item.to, true));
filteredRealNImplied[dir].implieds = implieds
.filter((implied) => hier[dir].includes(implied.field))
.filter((implied) => hier[dir].includes(implied.field) ||
(implied.field.includes(`<${arrow}>`) &&
hier[oppDir].includes(implied.field.split(" <")[0])))
.map((item) => this.toInternalLinkObj(item.to, false));
}
let { up: { reals: ru, implieds: iu }, same: { reals: rs, implieds: is }, down: { reals: rd, implieds: id }, next: { reals: rn, implieds: iN }, prev: { reals: rp, implieds: ip }, } = filteredRealNImplied;
Expand Down Expand Up @@ -24613,7 +24621,18 @@ class MatrixView extends require$$0.ItemView {
squares.forEach((sq) => sq.sort((a, b) => a.to < b.to ? (alphaSortAsc ? -1 : 1) : alphaSortAsc ? 1 : -1));
}
squares.forEach((sq) => sq.sort((a, b) => a.order - b.order));
loglevel.debug({ ru }, { rs }, { rd }, { rn }, { rp }, { iu }, { is }, { id }, { iN }, { ip });
loglevel.info([
{ ru },
{ rs },
{ rd },
{ rn },
{ rp },
{ iu },
{ is },
{ id },
{ iN },
{ ip },
]);
return [
{
realItems: ru,
Expand Down
30 changes: 23 additions & 7 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debug, error } from "loglevel";
import { debug, error, info } from "loglevel";
import { ItemView, Notice, TFile, WorkspaceLeaf } from "obsidian";
import { Debugger } from "src/Debugger";
import Lists from "./Components/Lists.svelte";
Expand All @@ -18,7 +18,11 @@ import type {
UserHier,
} from "./interfaces";
import type BCPlugin from "./main";
import { getRealnImplied, linkClass } from "./sharedFunctions";
import {
fallbackOppField,
getRealnImplied,
linkClass,
} from "./sharedFunctions";

export default class MatrixView extends ItemView {
private plugin: BCPlugin;
Expand Down Expand Up @@ -127,13 +131,25 @@ export default class MatrixView extends ItemView {
} = blankRealNImplied();

for (const dir in realsnImplieds) {
const oppDir = getOppDir(dir as Directions);
const arrow = ARROW_DIRECTIONS[dir];
const { reals, implieds } = realsnImplieds[dir];
filteredRealNImplied[dir].reals = reals
.filter((real) => hier[dir].includes(real.field))
.filter(
(real) =>
hier[dir].includes(real.field) ||
(real.field.includes(`<${arrow}>`) &&
hier[oppDir].includes(real.field.split(" <")[0]))
)
.map((item) => this.toInternalLinkObj(item.to, true));

filteredRealNImplied[dir].implieds = implieds
.filter((implied) => hier[dir].includes(implied.field))
.filter(
(implied) =>
hier[dir].includes(implied.field) ||
(implied.field.includes(`<${arrow}>`) &&
hier[oppDir].includes(implied.field.split(" <")[0]))
)
.map((item) => this.toInternalLinkObj(item.to, false));
}

Expand Down Expand Up @@ -198,7 +214,7 @@ export default class MatrixView extends ItemView {
}
squares.forEach((sq) => sq.sort((a, b) => a.order - b.order));

debug(
info([
{ ru },
{ rs },
{ rd },
Expand All @@ -208,8 +224,8 @@ export default class MatrixView extends ItemView {
{ is },
{ id },
{ iN },
{ ip }
);
{ ip },
]);

return [
{
Expand Down
8 changes: 6 additions & 2 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ export const linkClass = (app: App, to: string, realQ = true) =>
realQ ? "" : "BC-Implied"
}`;

export const fallbackOppField = (field: string, dir: Directions) =>
`${field} <${ARROW_DIRECTIONS[getOppDir(dir)]}>`;

/** Remember to filter by hierarchy in MatrixView! */
export function getRealnImplied(
plugin: BCPlugin,
Expand All @@ -248,8 +251,9 @@ export function getRealnImplied(
const { userHiers } = plugin.settings;

plugin.mainG.forEachEdge(currNode, (k, a, s, t) => {
const { field, dir: edgeDir } = a;
const oppField = getOppFields(userHiers, field)[0];
const { field, dir: edgeDir } = a as { field: string; dir: Directions };
const oppField =
getOppFields(userHiers, field)[0] ?? fallbackOppField(field, edgeDir);

(dir ? [dir, getOppDir(dir)] : DIRECTIONS).forEach((currDir) => {
const oppDir = getOppDir(currDir);
Expand Down
7 changes: 0 additions & 7 deletions src/utils.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils2.ts

This file was deleted.

0 comments on commit 3d0cd5d

Please sign in to comment.