Halte Kapitel am gewaehlten Vorgang fest und raeume die Arbeitsflaeche, damit Ziel, Auswahl und Rechte nicht an der Akte haengen bleiben.
Deploy Development / deploy (push) Successful in 23s
Test Suite / pytest-backend (push) Successful in 1m1s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 5s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 11:33:54 +02:00
1 parent 67d48378c9
commit cafa4e8b92
8 files changed
+523 -132

No files matched your search

+146 -47
View File
@@ -1,11 +1,11 @@
import { useContext, useEffect, useState } from "react";
import { Link, useParams } from "react-router-dom";
import { useContext, useEffect, useRef, useState } from "react";
import { Link, useParams, useSearchParams } from "react-router-dom";
import { api, markDirty, textToDocument } from "../api.js";
import { SessionContext } from "../session.js";
import { Modal } from "./Modal.jsx";
import { MailPicker, PaperlessPicker } from "./Sources.jsx";
import { ErrorNote, ShareBox } from "./widgets.jsx";
import { ContentBoard, ObjectMenu, RecordTree, SurfaceView, Trail, WorkLists, WorkSwitch } from "./content.jsx";
import { ContentBoard, ObjectMenu, OrderChoice, RecordTree, SurfaceView, TargetLine, Trail, WorkLists, WorkSwitch, selectionOf, withSelection, writeSelection } from "./content.jsx";
export function CaseList() {
const { session } = useContext(SessionContext);
@@ -156,8 +156,14 @@ function CaseOutline({ record, caseId, scope, chapterId, onScope, onChapter }) {
return (
<nav className="outline-nav" aria-label="Gliederung">
<h2>Gliederung</h2>
<button type="button" className={scope === "all" ? "" : "quiet"} onClick={() => onScope("all")}>Alle Inhalte</button>
<button type="button" className={scope === "direct" && !chapterId ? "" : "quiet"} onClick={() => onScope("direct")}>Direkt in dieser Akte</button>
<button type="button" className={scope === "all" ? "hierarchy__row is-current" : "hierarchy__row"} onClick={() => onScope("all")}>
<span className="hierarchy__kind">Überblick</span>
<strong>Alle Inhalte</strong>
</button>
<button type="button" className={scope === "direct" && !chapterId ? "hierarchy__row is-current" : "hierarchy__row"} onClick={() => onScope("direct")}>
<span className="hierarchy__kind">Akte</span>
<strong>Direkt in dieser Akte</strong>
</button>
<ChapterLinks chapters={record.chapters || []} scopeId="direct" scope={scope} chapterId={chapterId} onChapter={onChapter} />
{hasParent ? (
<p className="hierarchy__parent">Übergeordnet: <Link to={`/cases/${record.parent_case_id}`}>Akte {record.parent_title}</Link></p>
@@ -223,32 +229,86 @@ function mergedCaseItems(record, direction, caseId) {
export function CaseDetail() {
const { id } = useParams();
const [params, setParams] = useSearchParams();
const { scope, chapterId } = selectionOf(params);
const [record, setRecord] = useState(null);
const [error, setError] = useState("");
const [modal, setModal] = useState("");
const [view, setView] = useState("contents");
const [scope, setScope] = useState("all");
const [chapterId, setChapterId] = useState("");
const [dateDir, setDateDir] = useState("asc");
const [outlineOpen, setOutlineOpen] = useState(false);
const pendingChapter = useRef("");
const context = { kind: "case", id };
async function load() {
const detail = await api(`/api/v1/cases/${id}`);
pendingChapter.current = "";
setRecord(detail);
return detail;
}
useEffect(() => {
load().catch((err) => setError(err.message));
let alive = true;
setRecord(null);
setError("");
setView("contents");
setModal("");
setDateDir("asc");
setOutlineOpen(false);
api(`/api/v1/cases/${id}`).then((detail) => {
if (!alive) return;
pendingChapter.current = "";
setRecord(detail);
}).catch((err) => {
if (alive) setError(err.message);
});
return () => { alive = false; };
}, [id]);
useEffect(() => {
if (!record || record.id !== id) return;
const known = new Set(["all", "direct", ...(record.contained || []).map((item) => item.matter_id)]);
const nextScope = known.has(scope) ? scope : "all";
const chapters = nextScope === "direct"
? (record.chapters || [])
: (record.contained || []).find((item) => item.matter_id === nextScope)?.chapters || [];
const nextChapter = chapterId && chapters.some((chapter) => chapter.id === chapterId) ? chapterId : "";
if (chapterId && !nextChapter && pendingChapter.current === chapterId) return;
if (nextScope !== scope || nextChapter !== chapterId) writeSelection(params, setParams, nextScope, nextChapter);
}, [record, id, scope, chapterId, params, setParams]);
function choose(nextScope, nextChapter = "") {
writeSelection(params, setParams, nextScope, nextChapter);
setView("contents");
setOutlineOpen(false);
}
if (error && !record) return <main className="page"><ErrorNote error={error} /></main>;
if (!record) return <main className="page"><p className="muted">Akte wird geladen …</p></main>;
const group = (record.contained || []).find((item) => item.matter_id === scope);
const group = scope !== "all" && scope !== "direct"
? (record.contained || []).find((item) => item.matter_id === scope) || null
: null;
const target = scope === "direct"
? {
scope: "direct",
label: `Akte ${record.title}`,
edit: Boolean(record.rights?.edit),
chapters: record.chapters || [],
chapterPath: `/api/v1/cases/${id}/chapters`,
}
: group
? {
scope: group.matter_id,
label: `${group.kind_label || "Vorgang"} ${group.title}`,
edit: Boolean(group.rights?.edit),
chapters: group.chapters || [],
chapterPath: `/api/v1/matters/${group.matter_id}/chapters?context_kind=case&context_id=${id}`,
}
: null;
const activeChapter = target?.chapters.find((chapter) => chapter.id === chapterId) || null;
const merged = mergedCaseItems(record, dateDir, id);
const addPlacement = group ? { kind: "matter", id: group.matter_id } : null;
const addChapters = group?.chapters || record.chapters;
return (
<main className="page">
@@ -260,12 +320,14 @@ export function CaseDetail() {
<p className="muted">{record.status === "open" ? "Offen" : "Geschlossen"}</p>
</div>
<div className="row">
{record.rights.edit ? <button type="button" onClick={() => setModal("add")}>Inhalt hinzufügen</button> : null}
{target?.edit ? <button type="button" onClick={() => setModal("add")}>Inhalt hinzufügen</button> : null}
<ObjectMenu view={view} onView={setView}>
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("matter")}>Vorgang anlegen und zuordnen</button> : null}
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("assign")}>Vorhandenen Vorgang zuordnen</button> : null}
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("subcase")}>Unterakte anlegen</button> : null}
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("chapter")}>{group ? "Kapitel in diesem Vorgang anlegen" : "Kapitel anlegen"}</button> : null}
{target?.edit ? <button type="button" className="quiet" onClick={() => setModal("chapter")}>Kapitel hinzufügen</button> : null}
{!target ? <p className="muted">Für ein Kapitel zuerst einen Bereich wählen.</p> : null}
{target && !target.edit ? <p className="muted">In {target.label} fehlt das Bearbeitungsrecht.</p> : null}
{record.rights.share || record.is_owner ? <button type="button" className="quiet" onClick={() => setModal("share")}>Teilen</button> : null}
</ObjectMenu>
</div>
@@ -280,19 +342,25 @@ export function CaseDetail() {
caseId={id}
scope={scope}
chapterId={chapterId}
onScope={(next) => { setScope(next); setChapterId(""); setView("contents"); setOutlineOpen(false); }}
onChapter={(nextScope, nextChapter) => { setScope(nextScope); setChapterId(nextChapter); setView("contents"); setOutlineOpen(false); }}
onScope={(next) => choose(next)}
onChapter={(nextScope, nextChapter) => choose(nextScope, nextChapter)}
/>
</div>
</aside>
<div className="record-main">
<WorkSwitch view={view} onView={setView} />
{view === "contents" ? (
<p className="target-line">
{target ? (
<>Bearbeitet wird <strong>{target.label}</strong>{activeChapter ? <> · Kapitel <strong>{activeChapter.title}</strong></> : null}</>
) : (
"Lesesicht aller Inhalte. Zum Bearbeiten einen Bereich in der Gliederung wählen."
)}
</p>
) : null}
{view === "contents" && scope === "all" ? (
<div className="stack">
<div className="order-bar" role="group" aria-label="Lesesicht">
<button type="button" className={dateDir === "asc" ? "" : "quiet"} onClick={() => setDateDir("asc")}>Fachliches Datum, aufsteigend</button>
<button type="button" className={dateDir === "desc" ? "" : "quiet"} onClick={() => setDateDir("desc")}>Fachliches Datum, absteigend</button>
</div>
<OrderChoice mode="date" direction={dateDir} onChange={(_mode, next) => setDateDir(next)} />
<ContentBoard
record={{ bindings: merged, chapters: [], content_order: "date", content_order_dir: dateDir, rights: { edit: false }, version: record.version }}
bindings={merged}
@@ -311,7 +379,7 @@ export function CaseDetail() {
containerId={id}
onlyChapter={chapterId}
onChange={load}
itemHref={(binding) => `/cases/${id}/items/${binding.id}`}
itemHref={(binding) => withSelection(`/cases/${id}/items/${binding.id}`, params)}
/>
) : null}
{view === "contents" && group ? (
@@ -323,7 +391,7 @@ export function CaseDetail() {
containerId={group.matter_id}
onlyChapter={chapterId}
onChange={load}
itemHref={(binding) => `/matters/${group.matter_id}/items/${binding.id}?context_kind=case&context_id=${id}`}
itemHref={(binding) => withSelection(`/matters/${group.matter_id}/items/${binding.id}?context_kind=case&context_id=${id}`, params)}
/>
) : null}
{view === "contents" && scope !== "all" && scope !== "direct" && !group ? (
@@ -350,7 +418,8 @@ export function CaseDetail() {
<Modal open={modal === "assign"} title="Vorhandenen Vorgang zuordnen" onClose={() => setModal("")}>
<AssignMatter caseId={id} onChange={() => { setModal(""); load(); }} />
</Modal>
<Modal open={modal === "add"} title="Hinzufügen" onClose={() => setModal("")}>
<Modal open={modal === "add" && Boolean(target)} title={target ? `Hinzufügen in ${target.label}` : "Hinzufügen"} onClose={() => setModal("")}>
<TargetLine label={target?.label} chapters={target?.chapters} chapterId={activeChapter?.id || ""} />
<div className="choice">
<button type="button" onClick={() => setModal("note")}>Notiz</button>
<button type="button" onClick={() => setModal("file")}>Datei</button>
@@ -358,23 +427,33 @@ export function CaseDetail() {
<button type="button" onClick={() => setModal("mail")}>E-Mail</button>
</div>
</Modal>
<Modal open={modal === "note"} title="Notiz" onClose={() => setModal("")}>
<NoteForm context={context} placement={addPlacement} chapters={addChapters} onChange={() => { setModal(""); load(); }} />
<Modal open={modal === "note" && Boolean(target)} title="Notiz" onClose={() => setModal("")}>
<NoteForm context={context} placement={addPlacement} chapters={target?.chapters || []} initialChapter={activeChapter?.id || ""} targetLabel={target?.label || ""} onChange={() => { setModal(""); load(); }} />
</Modal>
<Modal open={modal === "file"} title="Datei" onClose={() => setModal("")}>
<FileForm context={context} placement={addPlacement} chapters={addChapters} onChange={() => { setModal(""); load(); }} />
<Modal open={modal === "file" && Boolean(target)} title="Datei" onClose={() => setModal("")}>
<FileForm context={context} placement={addPlacement} chapters={target?.chapters || []} initialChapter={activeChapter?.id || ""} targetLabel={target?.label || ""} onChange={() => { setModal(""); load(); }} />
</Modal>
<Modal open={modal === "paperless"} title="Aus Paperless" onClose={() => setModal("")}>
<PaperlessPicker context={context} placement={addPlacement} onDone={() => { setModal(""); load(); }} />
<Modal open={modal === "paperless" && Boolean(target)} title="Aus Paperless" onClose={() => setModal("")}>
<PaperlessPicker context={context} placement={addPlacement} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter?.title || ""} targetLabel={target?.label || ""} onDone={() => { setModal(""); load(); }} />
</Modal>
<Modal open={modal === "mail"} title="E-Mail verbinden" wide onClose={() => setModal("")}>
<MailPicker context={context} placement={addPlacement} onDone={() => { setModal(""); load(); }} />
<Modal open={modal === "mail" && Boolean(target)} title="E-Mail verbinden" wide onClose={() => setModal("")}>
<MailPicker context={context} placement={addPlacement} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter?.title || ""} targetLabel={target?.label || ""} onDone={() => { setModal(""); load(); }} />
</Modal>
<Modal open={modal === "subcase"} title="Unterakte anlegen" onClose={() => setModal("")}>
<NewSubcase parentId={id} onChange={() => { setModal(""); load(); }} />
</Modal>
<Modal open={modal === "chapter"} title={group ? "Kapitel im Vorgang" : "Kapitel anlegen"} onClose={() => setModal("")}>
<ChapterForm path={group ? `/api/v1/matters/${group.matter_id}/chapters?context_kind=case&context_id=${id}` : `/api/v1/cases/${id}/chapters`} onChange={() => { setModal(""); load(); }} />
<Modal open={modal === "chapter" && Boolean(target)} title={target ? `Kapitel in ${target.label} hinzufügen` : "Kapitel hinzufügen"} onClose={() => setModal("")}>
<ChapterForm
path={target?.chapterPath || ""}
onChange={(created) => {
setModal("");
if (created?.id && target) {
pendingChapter.current = created.id;
writeSelection(params, setParams, target.scope, created.id);
}
load();
}}
/>
</Modal>
<Modal open={modal === "share"} title="Teilen" onClose={() => setModal("")}>
<ShareBox path={`/api/v1/cases/${id}/grants`} grants={record.grants || []} onChange={load} />
@@ -523,18 +602,25 @@ function NewSubcase({ parentId, onChange }) {
export function ChapterForm({ path, onChange }) {
const [title, setTitle] = useState("");
const [error, setError] = useState("");
async function submit(event) {
event.preventDefault();
await api(path, { method: "POST", body: { title } });
setTitle("");
onChange();
setError("");
try {
const created = await api(path, { method: "POST", body: { title } });
setTitle("");
onChange(created);
} catch (err) {
setError(err.message);
}
}
return (
<form onSubmit={submit} className="inline">
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Kapitel" required />
<button type="submit">Kapitel</button>
<button type="submit">Hinzufügen</button>
<ErrorNote error={error} />
</form>
);
}
@@ -550,24 +636,30 @@ export function ContentForms({ context, placement, chapters, onChange }) {
}
function chapterSelect(chapters, value, setValue) {
if (!chapters?.length) return null;
return (
<select value={value} onChange={(event) => setValue(event.target.value)}>
<option value="">Ohne Kapitel</option>
{chapters.map((chapter) => (
<option key={chapter.id} value={chapter.id}>{chapter.title}</option>
))}
</select>
<label>
Kapitel
<select value={value} onChange={(event) => setValue(event.target.value)}>
<option value="">Ohne Kapitel</option>
{chapters.map((chapter) => (
<option key={chapter.id} value={chapter.id}>{chapter.title}</option>
))}
</select>
</label>
);
}
export function NoteForm({ context, placement, chapters, onChange }) {
export function NoteForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
const [title, setTitle] = useState("");
const [text, setText] = useState("");
const [documentOn, setDocumentOn] = useState("");
const [chapterId, setChapterId] = useState("");
const [chapterId, setChapterId] = useState(initialChapter);
const [error, setError] = useState("");
const [pending, setPending] = useState(false);
useEffect(() => { setChapterId(initialChapter || ""); }, [initialChapter]);
async function submit(event) {
event.preventDefault();
if (pending) return;
@@ -599,6 +691,7 @@ export function NoteForm({ context, placement, chapters, onChange }) {
return (
<form onSubmit={submit} className="stack compact">
<TargetLine label={targetLabel} chapters={chapters} chapterId={chapterId} />
<h3>Notiz</h3>
<label>Titel <input value={title} onChange={(event) => { setTitle(event.target.value); markDirty(true); }} required /></label>
<label>Gemeinsamer Text <textarea rows={4} value={text} onChange={(event) => { setText(event.target.value); markDirty(true); }} /></label>
@@ -610,15 +703,17 @@ export function NoteForm({ context, placement, chapters, onChange }) {
);
}
export function FileForm({ context, placement, chapters, onChange }) {
export function FileForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
const [title, setTitle] = useState("");
const [file, setFile] = useState(null);
const [chapterId, setChapterId] = useState("");
const [chapterId, setChapterId] = useState(initialChapter);
const [documentOn, setDocumentOn] = useState("");
const [sentOn, setSentOn] = useState("");
const [receivedOn, setReceivedOn] = useState("");
const [error, setError] = useState("");
useEffect(() => { setChapterId(initialChapter || ""); }, [initialChapter]);
async function submit(event) {
event.preventDefault();
if (!file) return;
@@ -649,6 +744,7 @@ export function FileForm({ context, placement, chapters, onChange }) {
return (
<form onSubmit={submit} className="stack compact">
<TargetLine label={targetLabel} chapters={chapters} chapterId={chapterId} />
<h3>Datei</h3>
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Titel des Schreibens" required />
<input type="file" accept="application/pdf,image/png,image/jpeg,image/webp" onChange={(event) => setFile(event.target.files?.[0] || null)} required />
@@ -662,16 +758,18 @@ export function FileForm({ context, placement, chapters, onChange }) {
);
}
function ExternalForm({ context, placement, chapters, onChange }) {
function ExternalForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
const [title, setTitle] = useState("");
const [externalId, setExternalId] = useState("");
const [source, setSource] = useState("paperless");
const [chapterId, setChapterId] = useState("");
const [chapterId, setChapterId] = useState(initialChapter);
const [documentOn, setDocumentOn] = useState("");
const [sentOn, setSentOn] = useState("");
const [receivedOn, setReceivedOn] = useState("");
const [error, setError] = useState("");
useEffect(() => { setChapterId(initialChapter || ""); }, [initialChapter]);
async function submit(event) {
event.preventDefault();
setError("");
@@ -702,6 +800,7 @@ function ExternalForm({ context, placement, chapters, onChange }) {
return (
<form onSubmit={submit} className="stack compact">
<TargetLine label={targetLabel} chapters={chapters} chapterId={chapterId} />
<h3>Paperless oder andere Referenz</h3>
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Anzeigetitel" required />
<select value={source} onChange={(event) => setSource(event.target.value)}>