Skip to content

Commit

Permalink
feat(List/Matrix View): ✨ Custom sorting of userHierachies
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Aug 13, 2021
1 parent a1a6477 commit 1ec10f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Components/Lists.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import type BreadcrumbsSettings from "src/main";
import type MatrixView from "src/MatrixView";
export let sortedSquaresArr: SquareProps[][];
export let filteredSquaresArr: SquareProps[][];
export let currFile: TFile;
export let settings: BreadcrumbsSettings;
export let matrixView: MatrixView;
export let app: App;
</script>

<div class="breadcrumbs-list">
{#each sortedSquaresArr as squares}
{#each filteredSquaresArr as squares}
<details open>
<summary class="hier-summary"
>{squares.map((square) => square.fieldName).join(", ")}</summary
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Matrix.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import type MatrixView from "src/MatrixView";
import { hoverPreview, openOrSwitch } from "src/sharedFunctions";
export let sortedSquaresArr: SquareProps[][];
export let filteredSquaresArr: SquareProps[][];
export let currFile: TFile;
export let settings: BreadcrumbsSettings;
export let matrixView: MatrixView;
export let app: App;
</script>

<div class="breadcrumbs-matrix markdown-preview-view">
{#each sortedSquaresArr as squares}
{#each filteredSquaresArr as squares}
<div>
{#each squares as square}
{#if square.realItems.length > 0 || square.impliedItems.length > 0}
Expand Down
26 changes: 6 additions & 20 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,50 +345,36 @@ export default class MatrixView extends ItemView {
const upSquare: SquareProps = {
realItems: rUp,
impliedItems: iUp,
fieldName: hier.up.join(", "),
fieldName: hier.up[0] === "" ? "<Parents>" : hier.up.join(", "),
};

const sameSquare: SquareProps = {
realItems: rSame,
impliedItems: iSameArr,
fieldName: hier.same.join(", "),
fieldName: hier.same[0] === "" ? "<Siblings>" : hier.same.join(", "),
};

const downSquare: SquareProps = {
realItems: rDown,
impliedItems: iDown,
fieldName: hier.down.join(", "),
fieldName: hier.down[0] === "" ? "<Children>" : hier.down.join(", "),
};

return [upSquare, sameSquare, downSquare];
});

debug(settings, { hierSquares });
const filteredSquares = hierSquares.filter((squareArr) =>
const filteredSquaresArr = hierSquares.filter((squareArr) =>
squareArr.some(
(square) => square.realItems.length + square.impliedItems.length > 0
)
);

const sortedSquaresArr = filteredSquares.sort(
(a, b) =>
sum(
b.map(
(square) => square.realItems.length + square.impliedItems.length
)
) -
sum(
a.map(
(square) => square.realItems.length + square.impliedItems.length
)
)
);

if (this.matrixQ) {
this.view = new Matrix({
target: this.contentEl,
props: {
sortedSquaresArr,
filteredSquaresArr,
currFile,
settings: settings,
matrixView: this,
Expand All @@ -399,7 +385,7 @@ export default class MatrixView extends ItemView {
this.view = new Lists({
target: this.contentEl,
props: {
sortedSquaresArr,
filteredSquaresArr,
currFile,
settings: settings,
matrixView: this,
Expand Down

0 comments on commit 1ec10f6

Please sign in to comment.