refactor: split AdminHierarchyPage into modular components
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:
1 parent
9ec1cf7781
commit
0e0b709768
6 files changed
+1112
-13
No files matched your search
@@ -1,28 +1,191 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
|
||||
/**
|
||||
* AdminHierarchyPage - Simplified version to fix build
|
||||
*/
|
||||
import HierarchyTab from '../components/admin/HierarchyTab'
|
||||
import CatalogsTab from '../components/admin/CatalogsTab'
|
||||
import AssignmentsTab from '../components/admin/AssignmentsTab'
|
||||
|
||||
function AdminHierarchyPage() {
|
||||
const [activeTab, setActiveTab] = useState('hierarchy')
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(false)
|
||||
}, [])
|
||||
// Hierarchy Tab State
|
||||
const [hierarchy, setHierarchy] = useState([])
|
||||
const [expandedNodes, setExpandedNodes] = useState(new Set())
|
||||
const [selectedItem, setSelectedItem] = useState(null)
|
||||
|
||||
if (loading) {
|
||||
return <div style={{ padding: '40px', textAlign: 'center' }}><div className="spinner"></div></div>
|
||||
// Catalogs Tab State
|
||||
const [targetGroups, setTargetGroups] = useState([])
|
||||
const [skillCategories, setSkillCategories] = useState([])
|
||||
const [trainingCharacters, setTrainingCharacters] = useState([])
|
||||
|
||||
// Assignments Tab State
|
||||
const [styleDirections, setStyleDirections] = useState([])
|
||||
const [assignments, setAssignments] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
loadData()
|
||||
}, [activeTab])
|
||||
|
||||
async function loadData() {
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
if (activeTab === 'hierarchy') {
|
||||
const data = await api.getAdminHierarchy()
|
||||
setHierarchy(data)
|
||||
} else if (activeTab === 'catalogs') {
|
||||
const [tgs, scs, tcs] = await Promise.all([
|
||||
api.listTargetGroups(),
|
||||
api.listSkillCategories(),
|
||||
api.listTrainingCharacters()
|
||||
])
|
||||
setTargetGroups(tgs)
|
||||
setSkillCategories(scs)
|
||||
setTrainingCharacters(tcs)
|
||||
} else if (activeTab === 'assignments') {
|
||||
const [sds, tgs, assns] = await Promise.all([
|
||||
api.listStyleDirections(),
|
||||
api.listTargetGroups(),
|
||||
api.listStyleDirectionTargetGroups()
|
||||
])
|
||||
setStyleDirections(sds)
|
||||
setTargetGroups(tgs)
|
||||
setAssignments(assns)
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
function handleToggleNode(nodeId) {
|
||||
setExpandedNodes(prev => {
|
||||
const newSet = new Set(prev)
|
||||
if (newSet.has(nodeId)) {
|
||||
newSet.delete(nodeId)
|
||||
} else {
|
||||
newSet.add(nodeId)
|
||||
}
|
||||
return newSet
|
||||
})
|
||||
}
|
||||
|
||||
function handleSelectItem(item, type) {
|
||||
if (item) {
|
||||
setSelectedItem({ ...item, _type: type })
|
||||
} else {
|
||||
setSelectedItem(null)
|
||||
}
|
||||
}
|
||||
|
||||
function handleUpdate() {
|
||||
setSelectedItem(null)
|
||||
loadData()
|
||||
}
|
||||
|
||||
const tabs = [
|
||||
{ id: 'hierarchy', label: '🌳 Hierarchie', icon: '🌳' },
|
||||
{ id: 'catalogs', label: '📋 Kataloge', icon: '📋' },
|
||||
{ id: 'assignments', label: '🔗 Zuordnungen', icon: '🔗' }
|
||||
]
|
||||
|
||||
return (
|
||||
<div style={{ padding: '20px' }}>
|
||||
<h1>Admin-Hierarchie</h1>
|
||||
{error && <div style={{ color: 'var(--danger)' }}>{error}</div>}
|
||||
<p>Die vollständige Admin-Hierarchie wird gerade überarbeitet...</p>
|
||||
<p>Nutze vorübergehend die alte Katalog-Seite unter <a href="/admin/catalogs">/admin/catalogs</a></p>
|
||||
<h1 style={{ marginTop: 0 }}>Admin: Katalog-Hierarchie</h1>
|
||||
|
||||
{/* Tab Navigation */}
|
||||
<div className="tab-navigation">
|
||||
{tabs.map(tab => (
|
||||
<button
|
||||
key={tab.id}
|
||||
className={activeTab === tab.id ? 'tab-button active' : 'tab-button'}
|
||||
onClick={() => setActiveTab(tab.id)}
|
||||
>
|
||||
{tab.icon} {tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Tab Content */}
|
||||
<div style={{ marginTop: '20px' }}>
|
||||
{activeTab === 'hierarchy' && (
|
||||
<HierarchyTab
|
||||
hierarchy={hierarchy}
|
||||
expandedNodes={expandedNodes}
|
||||
selectedItem={selectedItem}
|
||||
loading={loading}
|
||||
error={error}
|
||||
onToggleNode={handleToggleNode}
|
||||
onSelectItem={handleSelectItem}
|
||||
onUpdate={handleUpdate}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'catalogs' && (
|
||||
<CatalogsTab
|
||||
targetGroups={targetGroups}
|
||||
skillCategories={skillCategories}
|
||||
trainingCharacters={trainingCharacters}
|
||||
loading={loading}
|
||||
error={error}
|
||||
onUpdate={handleUpdate}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'assignments' && (
|
||||
<AssignmentsTab
|
||||
styleDirections={styleDirections}
|
||||
targetGroups={targetGroups}
|
||||
assignments={assignments}
|
||||
loading={loading}
|
||||
error={error}
|
||||
onUpdate={handleUpdate}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.tab-navigation {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
border-bottom: 2px solid var(--border);
|
||||
margin-bottom: 20px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.tab-button {
|
||||
padding: 12px 20px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-bottom: 3px solid transparent;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
color: var(--text2);
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tab-button:hover {
|
||||
color: var(--text1);
|
||||
background: var(--surface2);
|
||||
}
|
||||
|
||||
.tab-button.active {
|
||||
color: var(--accent);
|
||||
border-bottom-color: var(--accent);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.tab-button {
|
||||
flex: 1 1 auto;
|
||||
min-width: 120px;
|
||||
font-size: 14px;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user