feat(rennmausakte): Datenherkunft/Nachverfolgung pro Rennmaus

Neuer „Datenherkunft"-Button in der Rennmausakte öffnet einen Dialog, der zeigt,
aus welchen Quellen der Eintrag erzeugt wurde: Quelldateien (Stammbäume +
Wurfchronik), Anzahl zusammengeführter Datensätze, Eltern-Herleitung
(Methode/Konfidenz) und Hinweise (z. B. „per manueller Entscheidung zugeordnet",
„Konflikt gelöst", „aus N Datensätzen zusammengeführt").

Import: build_provenance() in merge_and_resolve.py sammelt die Herkunft über alle
deduplizierten Datensätze und schreibt sie als Provenance-JSON je Tier in
resolved_import.json. Backend: Gerbil.Provenance (nullable text) + Migration
AddGerbilProvenance, gemappt im Ingest und im GerbilDto zurückgegeben. Frontend:
ProvenanceDialog + Typen + Strings.

Tests: Ingest-Round-trip (vorhanden/abwesend), e2e provenance.spec.ts.
dotnet(212)/vitest(129)/playwright/tsc/eslint grün.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 15:45:15 +02:00
parent b9e5b031c4
commit 9c98c37d2a
16 changed files with 2126 additions and 6 deletions

View File

@@ -0,0 +1,157 @@
/**
* NACHVERFOLGUNG: "Nachverfolgungsinformationen" — read-only modal showing the
* data provenance of an imported gerbil (which source files contributed, how many
* raw records were merged, how the parents were derived, and human-readable notes).
*
* The provenance arrives as a JSON string on the Gerbil DTO (produced by the Python
* merge step). We parse it here defensively; anything unparseable / absent is shown
* as "Keine Herkunftsdaten vorhanden." Mirrors the ReportErrorDialog modal pattern.
*/
import { useEffect } from 'react'
import { de } from '../strings/de'
import type { GerbilProvenance } from '../api/types'
import './provenanceDialog.css'
interface ProvenanceDialogProps {
open: boolean
onClose: () => void
/** Raw provenance JSON string from Gerbil.provenance (null = no import data). */
provenance?: string | null
}
/** Parse the JSON provenance string defensively; null on absence / parse error. */
function parseProvenance(raw?: string | null): GerbilProvenance | null {
if (!raw || !raw.trim()) return null
try {
const p = JSON.parse(raw) as Partial<GerbilProvenance>
return {
sourceFiles: Array.isArray(p.sourceFiles) ? p.sourceFiles : [],
mergedRecordCount: typeof p.mergedRecordCount === 'number' ? p.mergedRecordCount : 0,
fromWurfchronik: Boolean(p.fromWurfchronik),
parentMethod: p.parentMethod,
parentConfidence: p.parentConfidence,
notes: Array.isArray(p.notes) ? p.notes : [],
}
} catch {
return null
}
}
export default function ProvenanceDialog({ open, onClose, provenance }: ProvenanceDialogProps) {
// Close on Escape (only while mounted).
useEffect(() => {
if (!open) return
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose()
}
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [open, onClose])
if (!open) return null
const t = de.provenance
const p = parseProvenance(provenance)
const method = p?.parentMethod ? (t.methods[p.parentMethod] ?? p.parentMethod) : null
const confidence = p?.parentConfidence
? (t.confidences[p.parentConfidence] ?? p.parentConfidence)
: null
return (
<div className="provenance__backdrop" onClick={onClose} role="presentation">
<div
className="provenance__dialog"
role="dialog"
aria-modal="true"
aria-labelledby="provenance-title"
onClick={(e) => e.stopPropagation()}
>
<div className="provenance__header">
<h2 id="provenance-title" className="provenance__title">
{t.dialogTitle}
</h2>
<button
type="button"
className="provenance__close"
onClick={onClose}
aria-label={t.close}
>
</button>
</div>
{!p ? (
<p className="provenance__empty">{t.empty}</p>
) : (
<>
<p className="provenance__intro">{t.intro}</p>
<section className="provenance__section">
<div className="provenance__section-title">
{t.mergedTitle}
</div>
<p className="provenance__merged">{t.mergedCount(p.mergedRecordCount)}</p>
{p.fromWurfchronik && (
<p className="provenance__wurfchronik">📖 {t.fromWurfchronik}</p>
)}
</section>
<section className="provenance__section">
<div className="provenance__section-title">
{t.sourceFilesTitle} {t.sourceFilesCount(p.sourceFiles.length)}
</div>
{p.sourceFiles.length === 0 ? (
<p className="provenance__empty">{t.empty}</p>
) : (
<ul className="provenance__files">
{p.sourceFiles.map((f) => (
<li key={f} className="provenance__file">
{f}
</li>
))}
</ul>
)}
</section>
{(method || confidence) && (
<section className="provenance__section">
<div className="provenance__section-title">{t.parentsTitle}</div>
<dl className="provenance__kvlist">
{method && (
<div className="provenance__kv">
<dt>{t.parentMethodLabel}</dt>
<dd>{method}</dd>
</div>
)}
{confidence && (
<div className="provenance__kv">
<dt>{t.parentConfidenceLabel}</dt>
<dd>{confidence}</dd>
</div>
)}
</dl>
</section>
)}
{p.notes.length > 0 && (
<section className="provenance__section">
<div className="provenance__section-title">{t.notesTitle}</div>
<ul className="provenance__notes">
{p.notes.map((n) => (
<li key={n}>{n}</li>
))}
</ul>
</section>
)}
</>
)}
<div className="provenance__actions">
<button type="button" className="btn btn--primary" onClick={onClose}>
{t.close}
</button>
</div>
</div>
</div>
)
}

View File

@@ -0,0 +1,157 @@
/* NACHVERFOLGUNG: "Nachverfolgungsinformationen" modal dialog. Mirrors the
reportErrorDialog modal pattern. */
.provenance__backdrop {
position: fixed;
inset: 0;
z-index: 200;
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
background: rgba(43, 33, 25, 0.45);
}
.provenance__dialog {
width: 100%;
max-width: 32rem;
max-height: calc(100vh - 2rem);
overflow-y: auto;
background: var(--color-bg, #fff);
color: var(--color-text);
border-radius: 14px;
box-shadow: 0 12px 40px rgba(43, 33, 25, 0.32);
padding: 1.25rem;
animation: provenanceIn 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes provenanceIn {
from {
opacity: 0;
transform: translateY(12px);
}
to {
opacity: 1;
transform: none;
}
}
.provenance__header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
margin-bottom: 0.5rem;
}
.provenance__title {
margin: 0;
font-size: 1.15rem;
}
.provenance__close {
background: none;
border: none;
font: inherit;
font-size: 1.1rem;
line-height: 1;
cursor: pointer;
color: var(--color-text-muted, #666);
padding: 0.25rem 0.4rem;
border-radius: 6px;
}
.provenance__close:hover {
background: var(--color-border, #eee);
}
.provenance__intro {
margin: 0 0 0.85rem;
font-size: 0.9rem;
color: var(--color-text-muted, #666);
}
.provenance__empty {
margin: 0.4rem 0;
font-size: 0.9rem;
color: var(--color-text-muted, #888);
font-style: italic;
}
.provenance__section {
margin-top: 0.9rem;
padding: 0.6rem 0.75rem;
border: 1px solid var(--color-border, #e5e5e5);
border-radius: 8px;
background: var(--color-surface-2, rgba(0, 0, 0, 0.03));
}
.provenance__section-title {
font-size: 0.78rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.03em;
color: var(--color-text-muted, #888);
margin-bottom: 0.4rem;
}
.provenance__merged {
margin: 0;
font-size: 0.9rem;
}
.provenance__wurfchronik {
margin: 0.4rem 0 0;
font-size: 0.85rem;
color: var(--color-text-muted, #666);
}
.provenance__files {
margin: 0;
padding-left: 1.1rem;
display: grid;
gap: 0.2rem;
}
.provenance__file {
font-size: 0.85rem;
word-break: break-word;
}
.provenance__kvlist {
margin: 0;
display: grid;
gap: 0.25rem;
}
.provenance__kv {
display: flex;
gap: 0.5rem;
font-size: 0.85rem;
}
.provenance__kv dt {
flex: 0 0 6rem;
font-weight: 600;
color: var(--color-text-muted, #777);
}
.provenance__kv dd {
margin: 0;
min-width: 0;
word-break: break-word;
}
.provenance__notes {
margin: 0;
padding-left: 1.1rem;
display: grid;
gap: 0.2rem;
font-size: 0.85rem;
}
.provenance__actions {
display: flex;
justify-content: flex-end;
gap: 0.5rem;
margin-top: 1.1rem;
}