Gib ein Uebergabepaket aus der bestaetigten Auswahl aus.
Die Dev-Umgebung soll die hierarchische Auswahl und das Paket pruefen koennen. Vorhandene Symbolaktionen der Inhaltszeilen bleiben im selben Stand. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7626c56f3d
commit
27cde035e8
21 files changed
+2427
-54
No files matched your search
@@ -0,0 +1,229 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { api, downloadPost } from "../api.js";
|
||||
|
||||
function leafIds(node, into = []) {
|
||||
if (!node) return into;
|
||||
if (node.kind === "binding" || node.kind === "annotation") 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.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 (
|
||||
<input
|
||||
ref={ref}
|
||||
type="checkbox"
|
||||
checked={state === "on"}
|
||||
disabled={disabled}
|
||||
aria-checked={state === "mixed" ? "mixed" : state === "on"}
|
||||
aria-label={label}
|
||||
onChange={onChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TreeRows({ node, depth, selected, onToggle }) {
|
||||
const state = checkState(node, selected);
|
||||
const ids = leafIds(node);
|
||||
return (
|
||||
<>
|
||||
<label className="export-tree__row" style={{ paddingLeft: `${depth * 16}px` }}>
|
||||
<CheckBox
|
||||
state={state}
|
||||
disabled={!ids.length}
|
||||
label={node.title}
|
||||
onChange={() => onToggle(node, state !== "on")}
|
||||
/>
|
||||
<span>
|
||||
<strong>{node.title}</strong>
|
||||
{node.label ? <span className="muted"> {node.label}</span> : null}
|
||||
{node.reason ? <span className="export-reason"> {node.reason}</span> : null}
|
||||
</span>
|
||||
</label>
|
||||
{(node.children || []).map((child) => (
|
||||
<TreeRows key={child.id} node={child} depth={depth + 1} selected={selected} onToggle={onToggle} />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<div className="stack export-package">
|
||||
<p className="muted">
|
||||
Die Auswahl gilt für diese Ausgabe. Ein bereits heruntergeladenes Paket verändert sich nicht,
|
||||
wenn danach Inhalte geändert oder ergänzt werden.
|
||||
</p>
|
||||
{error ? <p className="export-reason">{error}</p> : null}
|
||||
{!tree ? <p className="muted">Auswahl wird geladen …</p> : null}
|
||||
{tree && !review ? (
|
||||
<>
|
||||
<div className="export-tree" role="group" aria-label="Exportauswahl">
|
||||
<TreeRows node={tree} depth={0} selected={selected} onToggle={toggle} />
|
||||
</div>
|
||||
<div className="export-actions">
|
||||
<button type="button" onClick={examine} disabled={pending || selected.size === 0}>
|
||||
{pending ? "Prüfung läuft …" : "Auswahl prüfen"}
|
||||
</button>
|
||||
<button type="button" className="quiet" onClick={onClose}>Abbrechen</button>
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
{review ? (
|
||||
<>
|
||||
<div className="export-review">
|
||||
{review.issues?.length ? review.issues.map((issue) => (
|
||||
<p key={`${issue.node_id}-${issue.code}`} className="export-reason">
|
||||
{issue.title}: {issue.message}
|
||||
</p>
|
||||
)) : <p>Die Auswahl ist vollständig und kann ausgegeben werden.</p>}
|
||||
{review.notices?.map((notice) => (
|
||||
<p key={`${notice.node_id}-${notice.message}`} className="export-notice">{notice.message}</p>
|
||||
))}
|
||||
{ambiguous.map((issue) => (
|
||||
<label key={`${issue.node_id}-choice`}>
|
||||
Zugang für {issue.title}
|
||||
<select
|
||||
value={assignments[issue.node_id] || ""}
|
||||
onChange={(event) => {
|
||||
setAssignments((current) => ({ ...current, [issue.node_id]: event.target.value }));
|
||||
setReview(null);
|
||||
}}
|
||||
>
|
||||
<option value="">Zugang wählen</option>
|
||||
{issue.choices.map((choice) => (
|
||||
<option key={choice.id} value={choice.id}>{choice.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
))}
|
||||
<ul className="export-entries">
|
||||
{(review.entries || []).map((entry) => (
|
||||
<li key={entry.node_id}>
|
||||
{entry.kind_label}: {entry.title}
|
||||
{entry.path ? <span className="muted"> · {entry.path}</span> : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
{downloaded ? (
|
||||
<p className="muted">Das Paket wurde heruntergeladen. Es hält den Stand dieses Zeitpunkts fest.</p>
|
||||
) : null}
|
||||
<div className="export-actions">
|
||||
<button type="button" className="quiet" onClick={() => setReview(null)}>Zurück zur Auswahl</button>
|
||||
{review.ready ? (
|
||||
<button type="button" onClick={download} disabled={pending}>
|
||||
{pending ? "Paket wird erzeugt …" : "Paket herunterladen"}
|
||||
</button>
|
||||
) : (
|
||||
<button type="button" onClick={examine} disabled={pending}>Erneut prüfen</button>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user