Vereine Ablage, Akte und Vorgang in einem Navigationsbaum mit Fokus und Nachladen.
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 5m24s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 21s

Der Baum Meine Ablage steht jetzt auch auf den Seiten von Akte und Vorgang und ersetzt die Spalte Struktur. Ein Klick öffnet den Eintrag und klappt seine Struktur auf: Überblick, Kapitel und Unterkapitel, Unterakten, Vorgänge und Teilvorgänge. Der Pfad bleibt offen, die aktuelle Zeile ist hervorgehoben und nach dem Neuladen stimmt der Fokus wieder. Ein Vorgang steht unter jeder Akte, in der er liegt, und unter Vorgänge; ein Klick unter einer Akte öffnet ihn in diesem Aktenkontext. So wechselt man direkt von Vorgang zu Vorgang. Kapitel anlegen und verschieben geht im Baum.

Die Struktur eines Knotens kommt aus neuen schlanken Endpunkten (cases und matters outline), die nur Lesbares liefern, und wird beim Aufklappen einmal nachgeladen. Die Zweispaltenansicht mit dem Lesebereich beginnt erst, wenn neben dem Baum genug Platz bleibt.

Im Browser gegen die lokale Umgebung durchgespielt (Akte, Vorgang unter der Akte, Wechsel zwischen Vorgängen, Kapitel anlegen, Neuladen, Vorgang ohne Akte, Handy, Hell und Dunkel). Die Backend-Suite läuft mit 149 Tests grün, der Frontend-Build und 37 Node-Tests ebenfalls.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-10-22 12:11:36 +02:00
1 parent 322ad491c1
commit 5f60e1fe40
15 files changed
+688 -471

No files matched your search

+53 -118
View File
@@ -1,11 +1,11 @@
import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
import { NavLink, Outlet, useLocation, useSearchParams } from "react-router-dom";
import { Outlet, useLocation } from "react-router-dom";
import { api } from "../api.js";
import { SHARE_DRAG_TYPE, isEmployee, parseShareDrag, shareTargets } from "../admin/admin-core.js";
import { isEmployee, shareTargets } from "../admin/admin-core.js";
import { ErrorNote } from "../pages/widgets.jsx";
import { SessionContext } from "../session.js";
import { effectText, folderTree } from "./library-core.js";
import { MiniIcon } from "./MiniIcon.jsx";
import { effectText } from "./library-core.js";
import { NavTree } from "./NavTree.jsx";
export const LibraryContext = createContext(null);
@@ -15,129 +15,33 @@ export function useLibrary() {
const PLURAL = { case: "cases", matter: "matters" };
function TreeNodes({ nodes, children, hrefFor, parentKey, current, openIds, toggle }) {
return (
<ul className="library-tree__list">
{nodes.map((node) => {
const kids = children.get(node.id) || [];
const open = openIds.has(node.id);
const selected = current === node.id;
return (
<li key={node.id}>
<div className="library-tree__row">
{kids.length ? (
<button type="button" className="library-tree__toggle" aria-label={open ? "Einklappen" : "Aufklappen"} aria-expanded={open} onClick={() => toggle(node.id)}>
{open ? "▾" : "▸"}
</button>
) : <span className="library-tree__toggle is-empty" />}
<NavLink className={`library-tree__link${selected ? " is-current" : ""}`} to={hrefFor(node)} end>
<span className="library-tree__icon"><MiniIcon kind={parentKey === "parent_case_id" ? "case" : "matter"} /></span>
<span className="library-tree__title">{node.title}</span>
</NavLink>
</div>
{open && kids.length ? (
<TreeNodes nodes={kids} children={children} hrefFor={hrefFor} parentKey={parentKey} current={current} openIds={openIds} toggle={toggle} />
) : null}
</li>
);
})}
</ul>
);
const outlineKey = (kind, id, contextId = "") => `${kind}:${id}:${contextId || ""}`;
// A detail page tells the tree which entry is open and what can be done there.
// `actions` are read when a row is clicked, so they may close over the latest state.
export function useLibraryFocus(focus, actions) {
const library = useLibrary();
const signature = JSON.stringify(focus || null);
useEffect(() => {
library?.setFocus(focus || null);
return () => library?.setFocus(null);
}, [signature]);
if (library) library.actionsRef.current = actions || {};
}
function TreeSection({ to, label, items, parentKey, folder, active }) {
const { roots, children } = folderTree(items || [], parentKey);
const [openIds, setOpenIds] = useState(() => new Set());
const byId = new Map((items || []).map((item) => [item.id, item]));
// The path to the selected folder stays open.
const path = new Set();
for (let node = byId.get(folder); node; node = node[parentKey] ? byId.get(node[parentKey]) : null) path.add(node[parentKey]);
const shown = new Set([...openIds, ...path]);
const toggle = (id) =>
setOpenIds((current) => {
const next = new Set(current);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
return (
<div className="library-tree__section">
<NavLink to={to} end className={`library-tree__root${active && !folder ? " is-current" : ""}`}>
<span className="library-tree__icon"><MiniIcon kind={parentKey === "parent_case_id" ? "case" : "matter"} /></span> {label}
<span className="library-tree__count">{(items || []).length}</span>
</NavLink>
<TreeNodes
nodes={roots}
children={children}
parentKey={parentKey}
hrefFor={(node) => `${to}?ordner=${node.id}`}
current={active ? folder : ""}
openIds={shown}
toggle={toggle}
/>
</div>
);
}
function LibraryTree({ cases, matters, rooms, onDropOnRoom, employee }) {
const location = useLocation();
const [params] = useSearchParams();
const folder = params.get("ordner") || "";
const [over, setOver] = useState("");
return (
<nav className="library-tree" aria-label="Ordner">
{employee ? null : (
<>
<h2 className="library-tree__heading">Meine Ablage</h2>
<TreeSection to="/cases" label="Akten" items={cases} parentKey="parent_case_id" folder={folder} active={location.pathname === "/cases"} />
<TreeSection to="/matters" label="Vorgänge" items={matters} parentKey="parent_matter_id" folder={folder} active={location.pathname === "/matters"} />
</>
)}
<h2 className="library-tree__heading">Räume</h2>
<NavLink to="/rooms" end className={({ isActive }) => `library-tree__root${isActive ? " is-current" : ""}`}>
<span className="library-tree__icon"><MiniIcon kind="room" /></span> Alle Räume
</NavLink>
<ul className="library-tree__list">
{(rooms || []).map((room) => (
<li key={room.id}>
<NavLink
to={`/rooms/${room.id}`}
className={({ isActive }) => `library-tree__link library-tree__room${isActive ? " is-current" : ""}${over === room.id ? " is-over" : ""}`}
onDragOver={(event) => {
if (!Array.from(event.dataTransfer?.types || []).includes(SHARE_DRAG_TYPE)) return;
event.preventDefault();
event.dataTransfer.dropEffect = "link";
setOver(room.id);
}}
onDragLeave={() => setOver((current) => (current === room.id ? "" : current))}
onDrop={(event) => {
event.preventDefault();
setOver("");
const text = event.dataTransfer.getData(SHARE_DRAG_TYPE);
const payload = parseShareDrag(text, "case") || parseShareDrag(text, "matter");
if (payload) onDropOnRoom(payload, room);
}}
>
<span className="library-tree__icon"><MiniIcon kind="room" /></span>
<span className="library-tree__title">{room.name}</span>
<span className="library-tree__count">{room.case_count + room.matter_count}</span>
</NavLink>
</li>
))}
</ul>
</nav>
);
}
// Frame of the library: folder tree on the left, tiles on the right, one place for data and messages.
// Frame of the library: one navigation tree on the left, the page on the right.
export function LibraryLayout() {
const { session } = useContext(SessionContext);
const employee = isEmployee(session);
const [data, setData] = useState({ cases: null, matters: null, rooms: null });
const [outlines, setOutlines] = useState(() => new Map());
const [focus, setFocus] = useState(null);
const [error, setError] = useState("");
const [message, setMessage] = useState("");
const [treeOpen, setTreeOpen] = useState(false);
const timer = useRef(null);
const actionsRef = useRef({});
const pending = useRef(new Set());
const location = useLocation();
const reload = useCallback(async () => {
@@ -155,8 +59,34 @@ export function LibraryLayout() {
useEffect(() => {
reload();
setOutlines(new Map());
}, [reload, session.scope.id]);
// Outlines come on demand and stay in memory. `force` fetches again after a change.
const loadOutline = useCallback(async (kind, id, contextId = "", force = false) => {
const key = outlineKey(kind, id, contextId);
if (pending.current.has(key)) return;
if (!force && outlines.has(key)) return;
pending.current.add(key);
try {
const query = kind === "matter" && contextId ? `?context_kind=case&context_id=${contextId}` : "";
const outline = await api(`/api/v1/${PLURAL[kind]}/${id}/outline${query}`);
setOutlines((current) => new Map(current).set(key, outline));
} catch {
setOutlines((current) => new Map(current).set(key, { chapters: [], subcases: [], matters: [], submatters: [] }));
} finally {
pending.current.delete(key);
}
}, [outlines]);
// The open entry changed (a chapter added, a matter moved): fetch its outline and the lists again.
const stamp = focus?.stamp || "";
useEffect(() => {
if (!focus) return;
loadOutline(focus.kind, focus.id, focus.contextId || "", true);
reload();
}, [stamp]);
useEffect(() => {
setTreeOpen(false);
}, [location.pathname, location.search]);
@@ -195,6 +125,11 @@ export function LibraryLayout() {
notify,
share,
unshare,
focus,
setFocus,
outlines,
loadOutline,
actionsRef,
dropOnRoom: (payload, room) => share(payload.kind, { id: payload.id, title: payload.title }, room),
targets: shareTargets(session.rooms),
employee,
@@ -207,7 +142,7 @@ export function LibraryLayout() {
{treeOpen ? "Ordner ausblenden" : "Ordner anzeigen"}
</button>
<aside className={`library__tree${treeOpen ? " is-open" : ""}`}>
<LibraryTree cases={data.cases} matters={data.matters} rooms={data.rooms} onDropOnRoom={value.dropOnRoom} employee={employee} />
<NavTree cases={data.cases} matters={data.matters} rooms={data.rooms} employee={employee} onDropOnRoom={value.dropOnRoom} />
</aside>
<div className="library__main">
<ErrorNote error={error} />
+7
View File
@@ -9,6 +9,13 @@ export function MiniIcon({ kind }) {
</svg>
);
}
if (kind === "plus") {
return (
<svg {...common}>
<path d="M12 5v14M5 12h14" fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinecap="round" />
</svg>
);
}
if (kind === "chapter") {
return (
<svg {...common}>
+274
View File
@@ -0,0 +1,274 @@
import { useEffect, useState } from "react";
import { Link, NavLink } from "react-router-dom";
import { SHARE_DRAG_TYPE, parseShareDrag } from "../admin/admin-core.js";
import { useLibrary } from "./LibraryLayout.jsx";
import { MiniIcon } from "./MiniIcon.jsx";
import {
caseHref,
caseKey,
chapterTree,
focusKeys,
folderTree,
matterHref,
matterKey,
rowState,
} from "./library-core.js";
// One row of the navigation tree. A row with `load` fetches its outline when it opens.
function Row({ node, tree }) {
const library = useLibrary();
const open = tree.isOpen(node.key);
const expandable = Boolean(node.expandable);
useEffect(() => {
if (open && node.load) library.loadOutline(node.load.kind, node.load.id, node.load.contextId);
}, [open, node.key]);
const className = `library-tree__link${node.current ? " is-current" : ""}${node.ancestor ? " is-ancestor" : ""}`;
const inner = (
<>
<span className="library-tree__icon"><MiniIcon kind={node.icon} /></span>
<span className="library-tree__title">{node.title}</span>
{node.count !== undefined ? <span className="library-tree__count">{node.count}</span> : null}
</>
);
return (
<li className={node.className || ""}>
<div className="library-tree__row">
{expandable ? (
<button
type="button"
className="library-tree__toggle"
aria-expanded={open}
aria-label={`${node.title} ${open ? "einklappen" : "ausklappen"}`}
onClick={() => tree.toggle(node.key)}
>
{open ? "▾" : "▸"}
</button>
) : <span className="library-tree__toggle is-empty" aria-hidden="true" />}
{node.href ? (
<Link className={className} to={node.href} aria-current={node.current ? "page" : undefined} title={node.title}>{inner}</Link>
) : (
<button type="button" className={className} onClick={node.onClick} title={node.title}>{inner}</button>
)}
{node.moves ? (
<span className="library-tree__moves">
<button type="button" aria-label={`${node.title} nach oben`} disabled={node.moves.first} onClick={() => library.actionsRef.current.moveChapter?.(node.moves.id, -1)}>↑</button>
<button type="button" aria-label={`${node.title} nach unten`} disabled={node.moves.last} onClick={() => library.actionsRef.current.moveChapter?.(node.moves.id, 1)}>↓</button>
</span>
) : null}
</div>
{open && node.children ? <List nodes={node.children()} tree={tree} /> : null}
</li>
);
}
function List({ nodes, tree }) {
if (!nodes.length) return null;
return (
<ul className="library-tree__list">
{nodes.map((node) => <Row key={node.key} node={node} tree={tree} />)}
</ul>
);
}
// Builds the node descriptions from the lists, the loaded outlines and the focus of the page.
function buildNodes({ cases, matters, library, isOpen }) {
const { focus, outlines } = library;
const caseTree = folderTree(cases || [], "parent_case_id");
const matterTreeAll = folderTree(matters || [], "parent_matter_id");
const chapterNodes = (tree, base, owner, ownerKind, contextId) =>
tree.map(({ chapter, first, last, children }) => {
const state = rowState(focus, ownerKind, owner, contextId);
const href = ownerKind === "case" ? caseHref(owner, { kapitel: chapter.id }) : matterHref(owner, contextId, { kapitel: chapter.id });
return {
key: `k:${chapter.id}:${contextId || ""}`,
icon: "chapter",
title: chapter.title,
href,
current: state.here && state.chapter === chapter.id,
expandable: children.length > 0,
moves: state.here && focus.canReorder ? { id: chapter.id, first, last } : null,
children: () => chapterNodes(children, base, owner, ownerKind, contextId),
};
});
const addChapter = (owner, ownerKind, contextId) => {
const state = rowState(focus, ownerKind, owner, contextId);
if (!state.here || !focus.canEdit) return [];
return [{
key: `add:${owner}:${contextId || ""}`,
icon: "plus",
title: state.chapter ? "Neues Unterkapitel" : "Neues Kapitel",
className: "library-tree__add",
onClick: () => library.actionsRef.current.addChapter?.(state.chapter),
}];
};
function matterNode(item, contextId, subs) {
const key = matterKey(item.id, contextId);
const state = rowState(focus, "matter", item.id, contextId);
return {
key,
icon: "matter",
title: item.title,
href: matterHref(item.id, contextId),
current: state.whole && !isOpen(key),
ancestor: state.here,
expandable: true,
load: { kind: "matter", id: item.id, contextId },
children: () => {
const outline = outlines.get(`matter:${item.id}:${contextId || ""}`);
if (!outline) return [{ key: `${key}:loading`, icon: "contents", title: "Wird geladen …", className: "library-tree__hint", onClick: () => {} }];
const submatters = (outline.submatters || []).map((child) => matterNode(child, contextId, null));
return [
{ key: `${key}:all`, icon: "contents", title: "Alle Inhalte", href: matterHref(item.id, contextId), current: state.whole },
...chapterNodes(chapterTree(outline.chapters || []), "", item.id, "matter", contextId),
...submatters,
...addChapter(item.id, "matter", contextId),
];
},
};
}
function caseNode(item) {
const key = caseKey(item.id);
const state = rowState(focus, "case", item.id);
const kids = caseTree.children.get(item.id) || [];
return {
key,
icon: "case",
title: item.title,
href: caseHref(item.id),
current: state.whole && !isOpen(key),
ancestor: state.here,
expandable: true,
load: { kind: "case", id: item.id },
children: () => {
const outline = outlines.get(`case:${item.id}:`);
if (!outline) return [{ key: `${key}:loading`, icon: "contents", title: "Wird geladen …", className: "library-tree__hint", onClick: () => {} }];
const hasParts = (outline.subcases || []).length > 0 || (outline.matters || []).length > 0;
const rows = [];
if (hasParts) rows.push({ key: `${key}:over`, icon: "contents", title: "Überblick", href: caseHref(item.id, { bereich: "ueberblick" }), current: state.overview });
rows.push({ key: `${key}:direct`, icon: "contents", title: "Direkt in dieser Akte", href: caseHref(item.id), current: state.whole });
rows.push(...chapterNodes(chapterTree(outline.chapters || []), "", item.id, "case", ""));
rows.push(...kids.map(caseNode));
rows.push(...(outline.matters || []).map((matter) => matterNode(matter, item.id, matter.children)));
rows.push(...addChapter(item.id, "case", ""));
return rows;
},
};
}
return {
cases: caseTree.roots.map(caseNode),
matters: matterTreeAll.roots.map((item) => matterNode(item, "", null)),
};
}
function Section({ id, icon, label, count, nodes, tree, to }) {
const open = tree.isOpen(id);
return (
<div className="library-tree__section">
<div className="library-tree__row">
<button type="button" className="library-tree__toggle" aria-expanded={open} aria-label={`${label} ${open ? "einklappen" : "ausklappen"}`} onClick={() => tree.toggle(id)}>
{open ? "▾" : "▸"}
</button>
<NavLink to={to} end className={({ isActive }) => `library-tree__root${isActive ? " is-current" : ""}`}>
<span className="library-tree__icon"><MiniIcon kind={icon} /></span> {label}
<span className="library-tree__count">{count}</span>
</NavLink>
</div>
{open ? <List nodes={nodes} tree={tree} /> : null}
</div>
);
}
export function NavTree({ cases, matters, rooms, employee, onDropOnRoom }) {
const library = useLibrary();
const [opened, setOpened] = useState(() => new Set(["sec:cases", "sec:matters"]));
const [closed, setClosed] = useState(() => new Set());
const [over, setOver] = useState("");
const auto = focusKeys(library.focus, cases || [], matters || []);
const tree = {
isOpen: (key) => {
if (closed.has(key)) return false;
return opened.has(key) || auto.has(key);
},
toggle: (key) => {
const currently = tree.isOpen(key);
setOpened((current) => {
const next = new Set(current);
if (currently) next.delete(key);
else next.add(key);
return next;
});
setClosed((current) => {
const next = new Set(current);
if (currently) next.add(key);
else next.delete(key);
return next;
});
},
};
// A new focus opens its path again, even if the person closed it before.
const focusId = library.focus ? `${library.focus.kind}:${library.focus.id}:${library.focus.contextId || ""}` : "";
useEffect(() => {
if (!focusId) return;
setClosed((current) => {
const next = new Set(current);
for (const key of auto) next.delete(key);
return next;
});
}, [focusId]);
const nodes = buildNodes({ cases, matters, library, isOpen: tree.isOpen });
return (
<nav className="library-tree" aria-label="Ablage">
{employee ? null : (
<>
<h2 className="library-tree__heading">Meine Ablage</h2>
<Section id="sec:cases" icon="case" label="Akten" count={(cases || []).length} nodes={nodes.cases} tree={tree} to="/cases" />
<Section id="sec:matters" icon="matter" label="Vorgänge" count={(matters || []).length} nodes={nodes.matters} tree={tree} to="/matters" />
</>
)}
<h2 className="library-tree__heading">Räume</h2>
<NavLink to="/rooms" end className={({ isActive }) => `library-tree__root${isActive ? " is-current" : ""}`}>
<span className="library-tree__icon"><MiniIcon kind="room" /></span> Alle Räume
</NavLink>
<ul className="library-tree__list">
{(rooms || []).map((room) => (
<li key={room.id}>
<NavLink
to={`/rooms/${room.id}`}
className={({ isActive }) => `library-tree__link library-tree__room${isActive ? " is-current" : ""}${over === room.id ? " is-over" : ""}`}
onDragOver={(event) => {
if (!Array.from(event.dataTransfer?.types || []).includes(SHARE_DRAG_TYPE)) return;
event.preventDefault();
event.dataTransfer.dropEffect = "link";
setOver(room.id);
}}
onDragLeave={() => setOver((current) => (current === room.id ? "" : current))}
onDrop={(event) => {
event.preventDefault();
setOver("");
const text = event.dataTransfer.getData(SHARE_DRAG_TYPE);
const payload = parseShareDrag(text, "case") || parseShareDrag(text, "matter");
if (payload) onDropOnRoom(payload, room);
}}
>
<span className="library-tree__icon"><MiniIcon kind="room" /></span>
<span className="library-tree__title">{room.name}</span>
<span className="library-tree__count">{room.case_count + room.matter_count}</span>
</NavLink>
</li>
))}
</ul>
</nav>
);
}
+84
View File
@@ -104,3 +104,87 @@ export function addable(items, roomId) {
export function roleHint(role) {
return roleLabel(role);
}
// ---- Navigation tree: keys, the path that opens for the focused entry, chapters and links ----
export const caseKey = (id) => `c:${id}`;
export const matterKey = (id, contextId = "") => (contextId ? `m:${id}@${contextId}` : `m:${id}`);
// Keys of all nodes that open so that the focused entry is visible: its sections, parents and itself.
export function focusKeys(focus, cases = [], matters = []) {
const keys = new Set();
if (!focus) return keys;
const caseById = new Map(cases.map((item) => [item.id, item]));
const matterById = new Map(matters.map((item) => [item.id, item]));
const addCaseChain = (caseId) => {
keys.add("sec:cases");
keys.add(caseKey(caseId));
const seen = new Set();
let current = caseById.get(caseId);
while (current && !seen.has(current.id)) {
seen.add(current.id);
keys.add(caseKey(current.id));
current = current.parent_case_id ? caseById.get(current.parent_case_id) : null;
}
};
if (focus.kind === "case") {
addCaseChain(focus.id);
} else if (focus.kind === "matter") {
const context = focus.contextId || "";
if (context) addCaseChain(context);
else keys.add("sec:matters");
keys.add(matterKey(focus.id, context));
const seen = new Set();
let current = matterById.get(focus.id);
while (current && current.parent_matter_id && !seen.has(current.id)) {
seen.add(current.id);
keys.add(matterKey(current.parent_matter_id, context));
current = matterById.get(current.parent_matter_id);
}
}
return keys;
}
// Chapters of one container as a tree. Each node knows its siblings for the move arrows.
export function chapterTree(chapters = [], parentId = "") {
const siblings = chapters.filter((chapter) => (chapter.parent_chapter_id || "") === parentId);
return siblings.map((chapter, index) => ({
chapter,
first: index === 0,
last: index === siblings.length - 1,
children: chapterTree(chapters, chapter.id),
}));
}
export function caseHref(id, extra = {}) {
const query = new URLSearchParams(extra).toString();
return `/cases/${id}${query ? `?${query}` : ""}`;
}
export function matterHref(id, contextId = "", extra = {}) {
const query = new URLSearchParams({ ...(contextId ? { context_kind: "case", context_id: contextId } : {}), ...extra }).toString();
return `/matters/${id}${query ? `?${query}` : ""}`;
}
// Which row is the current one for the focus. The container row is current only when nothing below it is selected.
export function rowState(focus, kind, id, contextId = "") {
const here = Boolean(focus) && focus.kind === kind && focus.id === id && (kind === "case" || (focus.contextId || "") === (contextId || ""));
return {
here,
chapter: here ? focus.chapterId || "" : "",
overview: here && kind === "case" ? Boolean(focus.overview) : false,
whole: here && !focus.chapterId && !focus.overview,
};
}
// A short signature of what the tree shows below an entry. A change reloads that outline.
export function outlineSignature(record) {
if (!record) return "";
const chapters = (record.chapters || []).map((chapter) => `${chapter.id}:${chapter.title}:${chapter.position}:${chapter.parent_chapter_id || ""}`).join("|");
const subcases = (record.subcases || []).map((item) => item.id).join(",");
const matters = [];
const walk = (nodes) => (nodes || []).forEach((node) => { matters.push(node.id); walk(node.children); });
walk(record.matters);
const submatters = (record.submatters || []).map((item) => item.id).join(",");
return [record.id, record.title, chapters, subcases, matters.join(","), submatters].join("#");
}
@@ -61,3 +61,69 @@ test("only own entries that are not yet in the room can be added", () => {
assert.deepEqual(addable(cases, "r1").map((c) => c.id), ["b", "d"]);
assert.deepEqual(addable(cases, "r2").map((c) => c.id), ["a", "b", "d"]);
});
import { caseHref, caseKey, chapterTree, focusKeys, matterHref, matterKey, outlineSignature, rowState } from "./library-core.js";
const allCases = [
{ id: "a", parent_case_id: null },
{ id: "b", parent_case_id: "a" },
];
const allMatters = [
{ id: "m1", parent_matter_id: null },
{ id: "m2", parent_matter_id: "m1" },
];
test("the focus opens the path to a case, its parents and its section", () => {
assert.deepEqual([...focusKeys({ kind: "case", id: "b" }, allCases, allMatters)].sort(), ["c:a", "c:b", "sec:cases"]);
assert.equal(focusKeys(null, allCases, allMatters).size, 0);
});
test("a matter opens under its case context or under the matters section", () => {
const inCase = focusKeys({ kind: "matter", id: "m2", contextId: "b" }, allCases, allMatters);
assert.deepEqual([...inCase].sort(), ["c:a", "c:b", "m:m1@b", "m:m2@b", "sec:cases"]);
const alone = focusKeys({ kind: "matter", id: "m2", contextId: "" }, allCases, allMatters);
assert.deepEqual([...alone].sort(), ["m:m1", "m:m2", "sec:matters"]);
assert.equal(matterKey("x", "c"), "m:x@c");
assert.equal(matterKey("x"), "m:x");
assert.equal(caseKey("x"), "c:x");
});
test("chapters become a tree that knows its first and last sibling", () => {
const chapters = [
{ id: "1", parent_chapter_id: null },
{ id: "2", parent_chapter_id: "1" },
{ id: "3", parent_chapter_id: "1" },
{ id: "4", parent_chapter_id: null },
];
const tree = chapterTree(chapters);
assert.deepEqual(tree.map((n) => [n.chapter.id, n.first, n.last]), [["1", true, false], ["4", false, true]]);
assert.deepEqual(tree[0].children.map((n) => [n.chapter.id, n.first, n.last]), [["2", true, false], ["3", false, true]]);
});
test("links keep the case context of a matter", () => {
assert.equal(caseHref("a"), "/cases/a");
assert.equal(caseHref("a", { kapitel: "k" }), "/cases/a?kapitel=k");
assert.equal(matterHref("m", "a"), "/matters/m?context_kind=case&context_id=a");
assert.equal(matterHref("m", "a", { kapitel: "k" }), "/matters/m?context_kind=case&context_id=a&kapitel=k");
assert.equal(matterHref("m"), "/matters/m");
});
test("a row is current only for its own context", () => {
const focus = { kind: "matter", id: "m", contextId: "a", chapterId: "" };
assert.equal(rowState(focus, "matter", "m", "a").whole, true);
assert.equal(rowState(focus, "matter", "m", "b").here, false);
assert.equal(rowState(focus, "matter", "m", "").here, false);
assert.equal(rowState({ kind: "case", id: "a", overview: true }, "case", "a").overview, true);
assert.equal(rowState({ kind: "case", id: "a", chapterId: "k" }, "case", "a").whole, false);
assert.equal(rowState(null, "case", "a").here, false);
});
test("the outline signature changes with chapters, subcases and matters", () => {
const base = { id: "a", title: "T", chapters: [{ id: "1", title: "K", position: 1 }], subcases: [{ id: "s" }], matters: [{ id: "m", children: [{ id: "n", children: [] }] }] };
const same = outlineSignature(base);
assert.equal(outlineSignature({ ...base }), same);
assert.notEqual(outlineSignature({ ...base, chapters: [...base.chapters, { id: "2", title: "L", position: 2 }] }), same);
assert.notEqual(outlineSignature({ ...base, subcases: [] }), same);
assert.notEqual(outlineSignature({ ...base, matters: [] }), same);
assert.equal(outlineSignature(null), "");
});
+14
View File
@@ -103,3 +103,17 @@ a.button.quiet { background: var(--surface2); border: 1px solid var(--border2);
.mini-icon--room { color: var(--kind-room); }
.library-tree__toggle { font-size: 14px; }
.mark, .chip-popover .popover__button { display: inline-flex; align-items: center; gap: 5px; }
/* Navigation tree below the entries */
.library-tree__link.is-ancestor { font-weight: 700; }
.library-tree__add .library-tree__link, .library-tree__add button { color: var(--accent-dark); font-weight: 600; }
.library-tree__hint .library-tree__link { color: var(--text2); font-style: italic; }
.library-tree__moves { display: inline-flex; gap: 0; flex: none; }
.library-tree__moves button { min-height: 26px; width: 24px; padding: 0; font-size: 13px; background: transparent; color: var(--text2); border-radius: 6px; }
.library-tree__moves button:hover:not(:disabled) { background: var(--accent-light); color: var(--accent-dark); }
.library-tree button.library-tree__link { background: transparent; border: 0; justify-content: flex-start; text-align: left; width: 100%; }
.library__main .workspace { min-height: calc(100vh - 80px); }
.library__main > .page, .library__main > .workspace { max-width: none; }
.library-tree__list { min-width: 0; }
.library-tree__section > .library-tree__row > .library-tree__root { flex: 1; }
.mini-icon--plus { color: var(--accent-dark); }