import { useEffect, useRef, useState } from "react"; import { api, downloadPost } from "../api.js"; import { symbolUrl } from "../content-symbol.mjs"; function leafIds(node, into = []) { if (!node) return into; if (node.kind === "binding" || node.kind === "annotation" || node.kind === "attachment" || node.kind === "dispatch_item" || node.kind === "evidence") into.push(node.id); (node.children || []).forEach((child) => leafIds(child, into)); return into; } function checkState(node, selected) { const ids = leafIds(node); 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"; } function withNode(node, selected, on) { const next = new Set(selected); leafIds(node).forEach((id) => { if (on) next.add(id); else next.delete(id); }); return next; } function initialSelection(node) { const next = new Set(); function visit(current) { if ((current.kind === "binding" || current.kind === "annotation" || current.kind === "attachment" || current.kind === "dispatch_item" || current.kind === "evidence") && current.exportable) { next.add(current.id); } (current.children || []).forEach(visit); } visit(node); return next; } function CheckBox({ state, disabled, onChange, label }) { const ref = useRef(null); useEffect(() => { if (ref.current) ref.current.indeterminate = state === "mixed"; }, [state]); return ( ); } function ContentMark({ name }) { return ( ); } function symbolFor(node) { if (node.kind === "chapter") return "chapter"; if (node.kind === "matter") return node.label === "Teilvorgang" ? "submatter" : "matter"; if (node.kind === "annotation" || node.content_kind === "note") return "note"; if (node.content_kind === "email") return "email"; if (node.content_kind === "paperless") return "source-archive"; if (node.content_kind === "url") return "link"; return "file"; } function TreeBranch({ node, selected, onToggle }) { const state = checkState(node, selected); const ids = leafIds(node); const branch = node.kind === "matter" || node.kind === "chapter"; return (
  • {node.children?.length ? ( ) : null}
  • ); } export function ExportPackage({ matterId, context, onClose }) { const [tree, setTree] = useState(null); const [selected, setSelected] = useState(() => new Set()); const [review, setReview] = useState(null); const [assignments, setAssignments] = useState({}); const [error, setError] = useState(""); const [pending, setPending] = useState(false); const [downloaded, setDownloaded] = useState(false); const query = context?.kind && context?.id ? `?context_kind=${context.kind}&context_id=${context.id}` : ""; useEffect(() => { let alive = true; api(`/api/v1/matters/${matterId}/export-tree${query}`).then((payload) => { if (!alive) return; setTree(payload.tree); setSelected(initialSelection(payload.tree)); }).catch((err) => { if (alive) setError(err.message); }); return () => { alive = false; }; }, [matterId, query]); function toggle(node, on) { setSelected((current) => withNode(node, current, on)); setReview(null); setDownloaded(false); } async function examine() { setError(""); setPending(true); setDownloaded(false); try { const payload = await api(`/api/v1/matters/${matterId}/export/review`, { method: "POST", body: { context: context || null, selected: [...selected], assignments, }, }); setReview(payload); } catch (err) { setError(err.message); } finally { setPending(false); } } async function download() { setError(""); setPending(true); try { await downloadPost(`/api/v1/matters/${matterId}/export`, { context: context || null, selected: [...selected], assignments, }, "uebergabe.zip"); setDownloaded(true); } catch (err) { setError(err.message); } finally { setPending(false); } } const ambiguous = (review?.issues || []).filter((issue) => issue.choices?.length); return (

    Die Auswahl gilt für diese Ausgabe. Ein bereits heruntergeladenes Paket verändert sich nicht, wenn danach Inhalte geändert oder ergänzt werden.

    {error ?

    {error}

    : null} {!tree ?

    Auswahl wird geladen …

    : null} {tree && !review ? ( <>
    ) : null} {review ? ( <>
    {review.issues?.length ? review.issues.map((issue) => (

    {issue.title}: {issue.message}

    )) :

    Die Auswahl ist vollständig und kann ausgegeben werden.

    } {review.notices?.map((notice) => (

    {notice.message}

    ))} {ambiguous.map((issue) => ( ))}
    {downloaded ? (

    Das Paket wurde heruntergeladen. Es hält den Stand dieses Zeitpunkts fest.

    ) : null}
    {review.ready ? ( ) : ( )}
    ) : null}
    ); }