import React, { useCallback, useEffect, useState } from 'react' import api from '../../utils/api' const TIER_LABEL = { focus: 'Nur Fokusbereich', focus_style: 'Fokus + Stilrichtung', focus_training: 'Fokus + Trainingsstil', focus_style_type: 'Fokus + Stilrichtung + Trainingsstil' } function tierFromRow(row) { const hs = row.style_direction_id != null const ht = row.training_type_id != null if (!hs && !ht) return 'focus' if (hs && !ht) return 'focus_style' if (!hs && ht) return 'focus_training' return 'focus_style_type' } export default function MaturityModelBindingsAdmin() { const [bindings, setBindings] = useState([]) const [models, setModels] = useState([]) const [focusAreas, setFocusAreas] = useState([]) const [styleDirections, setStyleDirections] = useState([]) const [trainingTypes, setTrainingTypes] = useState([]) const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) const [error, setError] = useState('') const [tier, setTier] = useState('focus') const [formModelId, setFormModelId] = useState('') const [formFocusId, setFormFocusId] = useState('') const [formStyleId, setFormStyleId] = useState('') const [formTypeId, setFormTypeId] = useState('') const load = useCallback(async () => { setError('') try { const [b, m, fa, sd, tt] = await Promise.all([ api.listMaturityModelContextBindings(), api.listMaturityModels({}), api.listFocusAreas({}), api.listStyleDirections({}), api.listTrainingTypes({}) ]) setBindings(b) setModels(m) setFocusAreas(fa) setStyleDirections(sd) setTrainingTypes(tt) } catch (e) { setError(e.message || String(e)) } }, []) useEffect(() => { let cancelled = false ;(async () => { setLoading(true) await load() if (!cancelled) setLoading(false) })() return () => { cancelled = true } }, [load]) useEffect(() => { if (tier === 'focus') { setFormStyleId('') setFormTypeId('') } else if (tier === 'focus_style') { setFormTypeId('') } else if (tier === 'focus_training') { setFormStyleId('') } }, [tier]) async function handleSubmit(e) { e.preventDefault() if (!formModelId || !formFocusId) { setError('Modell und Fokusbereich sind Pflichtfelder.') return } const payload = { maturity_model_id: parseInt(formModelId, 10), focus_area_id: parseInt(formFocusId, 10) } if (tier === 'focus_style' || tier === 'focus_style_type') { if (!formStyleId) { setError('Stilrichtung auswählen.') return } payload.style_direction_id = parseInt(formStyleId, 10) } if (tier === 'focus_training' || tier === 'focus_style_type') { if (!formTypeId) { setError('Trainingsstil auswählen.') return } payload.training_type_id = parseInt(formTypeId, 10) } setSaving(true) setError('') try { await api.upsertMaturityModelContextBinding(payload) await load() } catch (err) { setError(err.message || String(err)) } finally { setSaving(false) } } async function handleDelete(id) { if (!window.confirm('Diese Zuordnung wirklich entfernen?')) return setError('') try { await api.deleteMaturityModelContextBinding(id) await load() } catch (err) { setError(err.message || String(err)) } } if (loading) { return

Lade Kontext-Zuordnungen…

} return (

Zusammenführung: Zu einem Fokus können mehrere Zeilen existieren (nur Fokus, Fokus + Stilrichtung, Fokus + Trainingsstil ohne Stil, oder alle drei). Beim Aufruf von{' '} /maturity-models/resolve werden alle zur Anfrage passenden Zeilen ermittelt, nach Spezifität sortiert (weniger zuerst) und zu einer Matrix verbunden: spezifischere Zuordnungen überschreiben Zelltexte gleicher Fähigkeit und Stufe. Stufen (Spalten) stammen vom{' '} ersten (am wenigsten spezifischen) Modell in dieser Kette.

{error ? (
{error}
) : null}

Zuordnung anlegen oder ersetzen

{(tier === 'focus_style' || tier === 'focus_style_type') && (
)} {(tier === 'focus_training' || tier === 'focus_style_type') && (
)}

Aktive Zuordnungen

{bindings.length === 0 ? ( ) : ( bindings.map((row) => ( )) )}
Ebene Fokus Stilrichtung Trainingsstil Modell
Noch keine Einträge. Sobald hier Zeilen existieren und ein passender Kontext an{' '} /maturity-models/resolve übergeben wird, werden diese Zuordnungen statt der reinen Legacy-Suche verwendet.
{TIER_LABEL[tierFromRow(row)]} {row.focus_area_name} {row.style_direction_name || '—'} {row.training_type_name || '—'} {row.maturity_model_name} ({row.model_status})
) }