Schliesse das Ablegen an der Markierung ab und halte Anlagen und Belege getrennt, damit der Dialog erscheint und zugeordnete Unterlagen im Uebergabepaket nur beim Schreiben stehen.
Deploy Development / deploy (push) Successful in 27s
Test Suite / pytest-backend (push) Successful in 1m41s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 8s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-18 11:35:03 +02:00
1 parent be027a1025
commit 9f5327f3be
5 files changed
+457 -234

No files matched your search

+238 -137
View File
@@ -1,4 +1,4 @@
import { useMemo, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { Link } from "react-router-dom";
import { api } from "../api.js";
import { buildChapterSections, sectionCounts } from "./chapters.js";
@@ -113,6 +113,32 @@ function branchVisible(section, needle) {
return (section.children || []).some((child) => branchVisible(child, needle));
}
function PickBox({ checked, mixed = false, disabled = false, label, onChange }) {
const ref = useRef(null);
useEffect(() => {
if (ref.current) ref.current.indeterminate = mixed;
}, [mixed]);
return (
<input
ref={ref}
type="checkbox"
checked={checked}
disabled={disabled}
aria-checked={mixed ? "mixed" : checked}
aria-label={label}
onChange={onChange}
/>
);
}
function selectionState(ids, selected) {
if (!ids.length) return "off";
const count = ids.filter((id) => selected.has(id)).length;
if (count === 0) return "off";
if (count === ids.length) return "on";
return "mixed";
}
export function StructureAssignDialog({ host, bindings, chapters, scope, pending, onClose, onDone }) {
const tree = useMemo(() => buildChapterSections(chapters, bindings), [chapters, bindings]);
const [opened, setOpened] = useState(() => new Set(host.chapter_id ? ancestorIds(chapters, host.chapter_id) : ["loose"]));
@@ -252,34 +278,40 @@ export function StructureAssignDialog({ host, bindings, chapters, scope, pending
}
}
function renderRow(item, depth) {
function renderRow(item) {
const id = item.element.id;
const isHost = id === host.element.id;
const notes = [
formatDate(item.element.dates?.document_on),
isHost ? "dieses Schriftstück" : "",
taken.has(id) ? "Anlage" : "",
].filter(Boolean).join(" · ");
return (
<li key={item.id} className="pick-tree__row" style={{ "--depth": depth }}>
<label>
<input type="checkbox" checked={selected.has(id)} disabled={isHost} onChange={() => toggle(id)} />
<span>{item.element.title}</span>
<span className="muted">{formatDate(item.element.dates?.document_on)}</span>
{isHost ? <span className="muted">dieses Schriftstück</span> : null}
{taken.has(id) ? <span className="muted">Anlage</span> : null}
<li key={item.id}>
<label className="pick-tree__row">
<PickBox checked={selected.has(id)} disabled={isHost} label={item.element.title} onChange={() => toggle(id)} />
<span className="pick-tree__title">{item.element.title}</span>
<span className="pick-tree__kind">{notes}</span>
</label>
</li>
);
}
function renderSection(section, depth) {
function renderSection(section) {
if (!branchVisible(section, needle)) return null;
const expanded = Boolean(needle) || opened.has(section.id);
const counts = sectionCounts(section);
const total = counts.direct + counts.nested;
const ids = branchItems(section).map((item) => item.element.id).filter((id) => id !== host.element.id);
const state = selectionState(ids, selected);
return (
<li key={section.id}>
<div className="pick-tree__chapter" style={{ "--depth": depth }}>
<div className="pick-tree__row">
<button
type="button"
className="quiet"
className="pick-tree__twist"
aria-expanded={expanded}
aria-label={`${section.title} ${expanded ? "zuklappen" : "aufklappen"}`}
onClick={() => setOpened((current) => {
const next = new Set(current);
if (next.has(section.id)) next.delete(section.id);
@@ -287,15 +319,24 @@ export function StructureAssignDialog({ host, bindings, chapters, scope, pending
return next;
})}
>
{expanded ? "▾" : "▸"} {section.title}
<span className="muted">{total}</span>
{expanded ? "▾" : "▸"}
</button>
<button type="button" className="quiet" aria-label={`Alle in ${section.title} auswählen`} onClick={() => toggleChapter(section)}>alle</button>
<label>
<PickBox
checked={state === "on"}
mixed={state === "mixed"}
disabled={!ids.length}
label={`Alle in ${section.title}`}
onChange={() => toggleChapter(section)}
/>
<span className="pick-tree__title">{section.title}</span>
<span className="pick-tree__kind">{total}</span>
</label>
</div>
{expanded ? (
<ul className="pick-tree__items">
{(section.items || []).filter((item) => titleMatches(item, needle)).map((item) => renderRow(item, depth + 1))}
{(section.children || []).map((child) => renderSection(child, depth + 1))}
<ul>
{(section.items || []).filter((item) => titleMatches(item, needle)).map((item) => renderRow(item))}
{(section.children || []).map((child) => renderSection(child))}
</ul>
) : null}
</li>
@@ -305,24 +346,29 @@ export function StructureAssignDialog({ host, bindings, chapters, scope, pending
const loose = tree.loose.filter((item) => titleMatches(item, needle));
const roots = tree.roots.map((section) => renderSection(section, 0)).filter(Boolean);
const looseIds = loose.map((item) => item.element.id).filter((id) => id !== host.element.id);
const looseState = selectionState(looseIds, selected);
const looseOpen = Boolean(needle) || opened.has("loose");
return (
<div className="stack pick-tree">
<p>Zuordnen an <strong>{host.element.title}</strong>. Kapitel bleiben geschlossen, bis sie geöffnet werden.</p>
<label>
<div className="stack pick-tree-dialog">
<p className="pick-tree__lead">Zuordnen an {host.element.title}</p>
<label className="pick-tree__find">
Suchen
<input value={query} onChange={(event) => setQuery(event.target.value)} placeholder="Titel" />
</label>
{step === "pick" ? (
<>
<ul className="pick-tree__list">
<ul className="pick-tree">
{roots}
{loose.length ? (
<li>
<div className="pick-tree__chapter">
<div className="pick-tree__row">
<button
type="button"
className="quiet"
aria-expanded={Boolean(needle) || opened.has("loose")}
className="pick-tree__twist"
aria-expanded={looseOpen}
aria-label={`Ohne Kapitel ${looseOpen ? "zuklappen" : "aufklappen"}`}
onClick={() => setOpened((current) => {
const next = new Set(current);
if (next.has("loose")) next.delete("loose");
@@ -330,19 +376,28 @@ export function StructureAssignDialog({ host, bindings, chapters, scope, pending
return next;
})}
>
{needle || opened.has("loose") ? "▾" : "▸"} Ohne Kapitel
<span className="muted">{loose.length}</span>
{looseOpen ? "▾" : "▸"}
</button>
<button type="button" className="quiet" onClick={() => toggleIds(loose.map((item) => item.element.id).filter((id) => id !== host.element.id))}>alle</button>
<label>
<PickBox
checked={looseState === "on"}
mixed={looseState === "mixed"}
disabled={!looseIds.length}
label="Alle ohne Kapitel"
onChange={() => toggleIds(looseIds)}
/>
<span className="pick-tree__title">Ohne Kapitel</span>
<span className="pick-tree__kind">{loose.length}</span>
</label>
</div>
{needle || opened.has("loose") ? (
<ul className="pick-tree__items">
{loose.map((item) => renderRow(item, 1))}
{looseOpen ? (
<ul>
{loose.map((item) => renderRow(item))}
</ul>
) : null}
</li>
) : null}
{!roots.length && !loose.length ? <li className="muted">Nichts mit diesem Titel.</li> : null}
{!roots.length && !loose.length ? <li className="pick-tree__empty">Nichts mit diesem Titel.</li> : null}
</ul>
<div className="pick-tree__bar">
<span>{selected.size} ausgewählt</span>
@@ -645,16 +700,41 @@ export function ComparisonList({ comparisons = [], state, reason }) {
function chipDrag(enabled, payload, onCarryStart, onCarryEnd) {
return {
role: "button",
tabIndex: enabled ? 0 : undefined,
draggable: enabled,
onDragStart(event) {
if (event.target.closest("button, a")) {
event.preventDefault();
return;
}
event.stopPropagation();
payload.anchorX = event.clientX;
payload.anchorY = event.clientY;
event.currentTarget.dataset.dragged = "1";
writeAssign(event, payload);
onCarryStart?.(payload);
},
onDragEnd() {
onCarryEnd?.();
onDragEnd(event) {
onCarryEnd?.(event);
},
};
}
function openTitleProps(onOpen) {
return {
role: "link",
tabIndex: 0,
onClick(event) {
const row = event.currentTarget.closest(".use-chip");
if (row?.dataset.dragged === "1") {
delete row.dataset.dragged;
return;
}
onOpen();
},
onKeyDown(event) {
if (event.key !== "Enter" && event.key !== " ") return;
event.preventDefault();
onOpen();
},
};
}
@@ -670,113 +750,134 @@ export function UnitDetail({
onUnfold,
onCarryStart,
onCarryEnd,
children,
}) {
const pack = binding.correspondence || {};
const attachments = pack.attachments || [];
const dispatches = pack.dispatches || [];
const [open, setOpen] = useState(false);
if (!attachments.length && !dispatches.length) return null;
const summary = unitMarks(binding) || "Anlagen und Belege";
const [attachmentsOpen, setAttachmentsOpen] = useState(false);
const [receiptsOpen, setReceiptsOpen] = useState(false);
if (!attachments.length && !dispatches.length) {
return typeof children === "function" ? children(null, null) : null;
}
const evidenceCount = dispatches.reduce((sum, item) => sum + (item.evidence || []).length, 0);
const attachmentLabel = attachments.length === 1 ? "1 Anlage" : `${attachments.length} Anlagen`;
const receiptParts = [];
if (dispatches.length === 1) receiptParts.push("1 Versand");
else if (dispatches.length > 1) receiptParts.push(`${dispatches.length} Versände`);
if (evidenceCount === 1) receiptParts.push("1 Beleg");
else if (evidenceCount > 1) receiptParts.push(`${evidenceCount} Belege`);
const switches = (
<span className="unit-switches">
{attachments.length ? (
<button type="button" className="unit-switch" aria-expanded={attachmentsOpen} onClick={() => setAttachmentsOpen((value) => !value)}>
{attachmentLabel}
</button>
) : null}
{dispatches.length ? (
<button type="button" className="unit-switch" aria-expanded={receiptsOpen} onClick={() => setReceiptsOpen((value) => !value)}>
{receiptParts.join(" · ") || "Belege"}
</button>
) : null}
</span>
);
const lists = attachmentsOpen || receiptsOpen ? (
<div className="unit-detail unit-detail--slim">
{attachmentsOpen && attachments.length ? (
<section>
<h4>Anlagen</h4>
<ol>
{attachments.map((item, index) => (
<li
key={item.id}
className="use-chip"
data-carry={`attachment:${item.element_id}`}
{...(canEdit ? chipDrag(!pending, {
source: "attachment",
elementId: item.element_id,
hostElementId: binding.element.id,
bindingId: item.binding_id || "",
title: item.title,
}, onCarryStart, onCarryEnd) : {})}
>
{canEdit ? <span className="use-chip__grip" aria-hidden="true" /> : null}
<span className="use-chip__title" {...openTitleProps(() => onOpen(item.element_id))}>
{index + 1}. {item.title}
</span>
<span className="muted">{formatDate(item.document_on)}</span>
{canEdit ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onDetach(item.element_id)}>In die Liste</button>
) : null}
</li>
))}
</ol>
</section>
) : null}
{receiptsOpen ? dispatches.map((item) => (
<section key={item.id}>
<h4>
Versand {item.undated ? "undatiert" : formatDate(item.sent_on)} · {item.channel_label}
{item.counterpart ? ` · ${item.counterpart}` : ""}
</h4>
{item.evidence?.length ? (
<ul>
{item.evidence.map((proof) => (
<li
key={proof.id}
className="use-chip"
data-carry={`evidence:${proof.element_id}`}
{...(canEdit ? chipDrag(!pending, {
source: "evidence",
elementId: proof.element_id,
dispatchId: item.id,
hostElementId: binding.element.id,
version: item.version,
title: proof.title,
}, onCarryStart, onCarryEnd) : {})}
>
{canEdit ? <span className="use-chip__grip" aria-hidden="true" /> : null}
<span className="use-chip__title" {...openTitleProps(() => onOpen(proof.element_id))}>
{receiptRoleLabel(proof.role, proof.role_label)}: {proof.title}
</span>
<span className="muted">{formatDate(proof.document_on)}</span>
{proof.source_state === "gap" ? <span>Lücke: {proof.gap_reason}</span> : null}
{canEdit ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onDetachEvidence(proof, item)}>
In die Liste
</button>
) : null}
{canEdit && proof.listed_fold === "evidence" ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onUnfold(proof.element_id)}>
Zusätzlich in der Liste zeigen
</button>
) : null}
</li>
))}
</ul>
) : <p className="muted">Ohne Beleg</p>}
<details className="use-editions">
<summary>Gesicherte Fassung</summary>
<ol>
{item.items.map((part) => (
<li key={part.id}>
<span>{part.role === "host" ? "Schreiben" : "Anlage"}: {part.title}</span>
<span className="muted">{formatDate(part.document_on)}</span>
{part.source_state === "gap" ? <span>Lücke: {part.gap_reason}</span> : scope ? (
<a href={snapshotHref(item.id, part.id, scope)}>Öffnen</a>
) : <span>Gesichert</span>}
</li>
))}
</ol>
</details>
</section>
)) : null}
</div>
) : null;
if (typeof children === "function") return children(switches, lists);
return (
<div className="unit-fold">
<button type="button" className="quiet unit-toggle" aria-expanded={open} onClick={() => setOpen((value) => !value)}>
{open ? "Zuklappen" : summary}
</button>
{open ? (
<div className="unit-detail unit-detail--slim">
{attachments.length ? (
<section>
<h4>Anlagen</h4>
<ol>
{attachments.map((item, index) => (
<li key={item.id} className="use-chip">
{canEdit ? (
<span
className="use-chip__grip"
aria-label={`${item.title} aus den Anlagen ziehen`}
{...chipDrag(!pending, {
source: "attachment",
elementId: item.element_id,
hostElementId: binding.element.id,
bindingId: item.binding_id || "",
title: item.title,
}, onCarryStart, onCarryEnd)}
/>
) : null}
<span>{index + 1}. {item.title}</span>
<span className="muted">{formatDate(item.document_on)}</span>
{item.binding_id ? (
<button type="button" className="quiet" onClick={() => onOpen(item.element_id)}>Öffnen</button>
) : null}
{canEdit ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onDetach(item.element_id)}>In die Liste</button>
) : null}
</li>
))}
</ol>
</section>
) : null}
{dispatches.map((item) => (
<section key={item.id}>
<h4>
Versand {item.undated ? "undatiert" : formatDate(item.sent_on)} · {item.channel_label}
{item.counterpart ? ` · ${item.counterpart}` : ""}
</h4>
{item.evidence?.length ? (
<ul>
{item.evidence.map((proof) => (
<li key={proof.id} className="use-chip">
{canEdit ? (
<span
className="use-chip__grip"
aria-label={`${proof.title} aus den Belegen ziehen`}
{...chipDrag(!pending, {
source: "evidence",
elementId: proof.element_id,
dispatchId: item.id,
hostElementId: binding.element.id,
version: item.version,
title: proof.title,
}, onCarryStart, onCarryEnd)}
/>
) : null}
<button type="button" className="quiet" onClick={() => onOpen(proof.element_id)}>
{receiptRoleLabel(proof.role, proof.role_label)}: {proof.title}
</button>
<span className="muted">{formatDate(proof.document_on)}</span>
{proof.source_state === "gap" ? <span>Lücke: {proof.gap_reason}</span> : null}
{canEdit ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onDetachEvidence(proof, item)}>
In die Liste
</button>
) : null}
{canEdit && proof.listed_fold === "evidence" ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onUnfold(proof.element_id)}>
Zusätzlich in der Liste zeigen
</button>
) : null}
</li>
))}
</ul>
) : <p className="muted">Ohne Beleg</p>}
<details className="use-editions">
<summary>Gesicherte Fassung</summary>
<ol>
{item.items.map((part) => (
<li key={part.id}>
<span>{part.role === "host" ? "Schreiben" : "Anlage"}: {part.title}</span>
<span className="muted">{formatDate(part.document_on)}</span>
{part.source_state === "gap" ? <span>Lücke: {part.gap_reason}</span> : scope ? (
<a href={snapshotHref(item.id, part.id, scope)}>Öffnen</a>
) : <span>Gesichert</span>}
</li>
))}
</ol>
</details>
</section>
))}
</div>
) : null}
{switches}
{lists}
</div>
);
}