FEAT-3: Zuchtpaar-Übersicht tab (derive pairs from litters) + ?vater/&mutter pair prefill in Probeverpaarung
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,20 +16,34 @@ export default function GenetikPage() {
|
||||
const [father, setFather] = useState<ParentValue>(EMPTY_PARENT)
|
||||
const [mother, setMother] = useState<ParentValue>(EMPTY_PARENT)
|
||||
|
||||
// Pre-fill a parent when arriving from an animal's detail page (?parent=<id>).
|
||||
// Gender decides the side: female -> Mutter, otherwise Vater.
|
||||
// Pre-fill parents from query params:
|
||||
// ?parent=<id> single animal from its detail page (gender picks side)
|
||||
// ?vater=<id>&mutter=<id> a whole pair, e.g. from the Zuchtpaar overview
|
||||
const [searchParams] = useSearchParams()
|
||||
const parentId = searchParams.get('parent')
|
||||
const prefill = useApi(
|
||||
() => (parentId ? getGerbil(parentId) : Promise.resolve(null)),
|
||||
[parentId],
|
||||
)
|
||||
const [prefilledFor, setPrefilledFor] = useState<string | null>(null)
|
||||
if (prefill.data && prefilledFor !== prefill.data.id) {
|
||||
setPrefilledFor(prefill.data.id)
|
||||
const value: ParentValue = { genotype: prefill.data.genotype ?? '', animalName: prefill.data.name }
|
||||
if (prefill.data.gender === 'female') setMother(value)
|
||||
else setFather(value)
|
||||
const vaterId = searchParams.get('vater')
|
||||
const mutterId = searchParams.get('mutter')
|
||||
|
||||
const prefill = useApi(() => (parentId ? getGerbil(parentId) : Promise.resolve(null)), [parentId])
|
||||
const prefillVater = useApi(() => (vaterId ? getGerbil(vaterId) : Promise.resolve(null)), [vaterId])
|
||||
const prefillMutter = useApi(() => (mutterId ? getGerbil(mutterId) : Promise.resolve(null)), [mutterId])
|
||||
|
||||
const [prefilledKey, setPrefilledKey] = useState<string | null>(null)
|
||||
const prefillKey = `${parentId ?? ''}|${vaterId ?? ''}|${mutterId ?? ''}`
|
||||
const allReady =
|
||||
(!parentId || prefill.data) && (!vaterId || prefillVater.data) && (!mutterId || prefillMutter.data)
|
||||
if (prefillKey !== '||' && allReady && prefilledKey !== prefillKey) {
|
||||
setPrefilledKey(prefillKey)
|
||||
const toValue = (g: { genotype: string | null; name: string }): ParentValue => ({
|
||||
genotype: g.genotype ?? '',
|
||||
animalName: g.name,
|
||||
})
|
||||
if (prefillVater.data) setFather(toValue(prefillVater.data))
|
||||
if (prefillMutter.data) setMother(toValue(prefillMutter.data))
|
||||
if (prefill.data) {
|
||||
if (prefill.data.gender === 'female') setMother(toValue(prefill.data))
|
||||
else setFather(toValue(prefill.data))
|
||||
}
|
||||
}
|
||||
|
||||
const bothValid = isValidGenotype(father.genotype) && isValidGenotype(mother.genotype)
|
||||
|
||||
Reference in New Issue
Block a user