refactor: split AdminHierarchyPage into modular components
Deploy Development / deploy (push) Successful in 35s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 2m0s

Split 1200+ line file into clean modular architecture:
- FocusAreaNode.jsx - Tree nodes with nested style directions + training types
- HierarchyTab.jsx - Tab 1 with tree view and detail panel
- CatalogsTab.jsx - Tab 2 with global catalogs (Target Groups, Skill Categories, Training Characters)
- AssignmentsTab.jsx - Tab 3 with M:N checkbox matrix (Style Directions ↔ Target Groups)
- DetailPanel.jsx - All edit forms (Focus Area, Style Direction, Training Type) + create forms

Fixes ESBuild parser error from large file size.
Implements full CRUD: create, edit, delete, reassign focus areas.
Responsive design with mobile/desktop layouts.
This commit is contained in:
Lars committed 2026-04-24 09:08:12 +02:00
1 parent 9ec1cf7781
commit 0e0b709768
6 files changed
+1112 -13

No files matched your search

@@ -0,0 +1,160 @@
import React, { useState } from 'react'
import { api } from '../../utils/api'
function AssignmentsTab({ styleDirections, targetGroups, assignments, loading, error, onUpdate }) {
const [saving, setSaving] = useState(false)
if (loading) {
return <div style={{ textAlign: 'center', padding: '40px' }}><div className="spinner"></div></div>
}
async function toggleAssignment(styleDirectionId, targetGroupId, currentlyAssigned) {
setSaving(true)
try {
if (currentlyAssigned) {
// Find and delete the assignment
const assignment = assignments.find(
a => a.style_direction_id === styleDirectionId && a.target_group_id === targetGroupId
)
if (assignment) {
await api.deleteStyleDirectionTargetGroup(assignment.id)
}
} else {
// Create new assignment
await api.createStyleDirectionTargetGroup({
style_direction_id: styleDirectionId,
target_group_id: targetGroupId,
is_primary: false
})
}
onUpdate()
} catch (e) {
alert('Fehler: ' + e.message)
} finally {
setSaving(false)
}
}
function isAssigned(styleDirectionId, targetGroupId) {
return assignments.some(
a => a.style_direction_id === styleDirectionId && a.target_group_id === targetGroupId
)
}
// Group style directions by focus area
const groupedStyles = styleDirections.reduce((acc, sd) => {
const key = sd.focus_area_name || 'Ohne Fokusbereich'
if (!acc[key]) acc[key] = []
acc[key].push(sd)
return acc
}, {})
return (
<div style={{ background: 'var(--surface)', borderRadius: '12px', padding: '20px' }}>
<h2 style={{ marginTop: 0 }}>Zuordnungen: Stilrichtungen ↔ Zielgruppen</h2>
{error && <div style={{ color: 'var(--danger)', padding: '16px', background: 'var(--surface2)', borderRadius: '8px', marginBottom: '16px' }}>{error}</div>}
{targetGroups.length === 0 && (
<div style={{ textAlign: 'center', color: 'var(--text3)', padding: '40px' }}>
Keine Zielgruppen vorhanden. Bitte erst im Tab "Kataloge" anlegen.
</div>
)}
{styleDirections.length === 0 && (
<div style={{ textAlign: 'center', color: 'var(--text3)', padding: '40px' }}>
Keine Stilrichtungen vorhanden. Bitte erst im Tab "Hierarchie" anlegen.
</div>
)}
{targetGroups.length > 0 && styleDirections.length > 0 && (
<div className="assignment-matrix-container">
<table className="assignment-matrix">
<thead>
<tr>
<th style={{ position: 'sticky', left: 0, background: 'var(--surface)', zIndex: 2 }}>Stilrichtung</th>
{targetGroups.map(tg => (
<th key={tg.id} style={{ textAlign: 'center', padding: '12px' }}>
{tg.name}
</th>
))}
</tr>
</thead>
<tbody>
{Object.entries(groupedStyles).map(([focusAreaName, styles]) => (
<React.Fragment key={focusAreaName}>
<tr className="focus-area-header">
<td colSpan={targetGroups.length + 1} style={{ background: 'var(--surface2)', padding: '8px 12px', fontWeight: 600, color: 'var(--text2)' }}>
{focusAreaName}
</td>
</tr>
{styles.map(sd => (
<tr key={sd.id}>
<td style={{ position: 'sticky', left: 0, background: 'var(--surface)', zIndex: 1, padding: '12px', fontWeight: 500 }}>
{sd.name}
</td>
{targetGroups.map(tg => {
const assigned = isAssigned(sd.id, tg.id)
return (
<td key={tg.id} style={{ textAlign: 'center', padding: '12px' }}>
<input
type="checkbox"
checked={assigned}
onChange={() => toggleAssignment(sd.id, tg.id, assigned)}
disabled={saving}
style={{ width: '20px', height: '20px', cursor: 'pointer' }}
/>
</td>
)
})}
</tr>
))}
</React.Fragment>
))}
</tbody>
</table>
</div>
)}
<style>{`
.assignment-matrix-container {
overflow-x: auto;
margin-top: 20px;
}
.assignment-matrix {
width: 100%;
border-collapse: collapse;
min-width: 600px;
}
.assignment-matrix th,
.assignment-matrix td {
border: 1px solid var(--border);
padding: 12px;
}
.assignment-matrix th {
background: var(--surface2);
font-weight: 600;
color: var(--text1);
}
.assignment-matrix tbody tr:hover {
background: var(--surface2);
}
@media (max-width: 768px) {
.assignment-matrix {
font-size: 14px;
}
.assignment-matrix th,
.assignment-matrix td {
padding: 8px;
}
}
`}</style>
</div>
)
}
export default AssignmentsTab