feat: Visual Profile Builder integrated into Training Types page (#15)
MAJOR UX IMPROVEMENT - No more JSON editing required! New Component: ProfileBuilder.jsx - Visual form for configuring training type profiles - Parameter dropdown (dynamically loaded from API) - Operator dropdown (>=, <=, >, <, =, ≠, between) - Value input (type-aware, between shows min/max) - Weight slider (1-10) - Add/remove rules visually - Pass strategy selection - Optional checkbox per rule - Expandable sections Integration: AdminTrainingTypesPage.jsx - Added ProfileBuilder component - ⚙️ Settings icon per training type - Opens visual form when clicked - ✓ Profil badge shows configured types - Loads 16 parameters from API - Save directly to training type User Experience: 1. Go to /admin/training-types 2. Click ⚙️ icon on any type 3. Visual form opens 4. Add rules via dropdowns 5. Save → Profile configured! NO JSON EDITING NEEDED! 🎉 Next: Add visual builders for other dimensions (Zones, Effects, etc.) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
2abaac22cf
commit
6fa15f7f57
2 files changed
+470
-3
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Pencil, Trash2, Plus, Save, X, ArrowLeft } from 'lucide-react'
|
||||
import { Pencil, Trash2, Plus, Save, X, ArrowLeft, Settings } from 'lucide-react'
|
||||
import { api } from '../utils/api'
|
||||
import ProfileBuilder from '../components/ProfileBuilder'
|
||||
|
||||
/**
|
||||
* AdminTrainingTypesPage - CRUD for training types
|
||||
@@ -16,6 +17,8 @@ export default function AdminTrainingTypesPage() {
|
||||
const [formData, setFormData] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [editingProfileId, setEditingProfileId] = useState(null)
|
||||
const [parameters, setParameters] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
load()
|
||||
@@ -25,10 +28,12 @@ export default function AdminTrainingTypesPage() {
|
||||
setLoading(true)
|
||||
Promise.all([
|
||||
api.adminListTrainingTypes(),
|
||||
api.getTrainingCategories()
|
||||
]).then(([typesData, catsData]) => {
|
||||
api.getTrainingCategories(),
|
||||
api.getTrainingParameters()
|
||||
]).then(([typesData, catsData, paramsData]) => {
|
||||
setTypes(typesData)
|
||||
setCategories(catsData)
|
||||
setParameters(paramsData.parameters || [])
|
||||
setLoading(false)
|
||||
}).catch(err => {
|
||||
console.error('Failed to load training types:', err)
|
||||
@@ -109,6 +114,28 @@ export default function AdminTrainingTypesPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const startEditProfile = (typeId) => {
|
||||
setEditingProfileId(typeId)
|
||||
setEditingId(null) // Close type editor if open
|
||||
setFormData(null)
|
||||
}
|
||||
|
||||
const cancelEditProfile = () => {
|
||||
setEditingProfileId(null)
|
||||
}
|
||||
|
||||
const handleSaveProfile = async (profile) => {
|
||||
try {
|
||||
await api.adminUpdateTrainingType(editingProfileId, { profile })
|
||||
await load()
|
||||
setEditingProfileId(null)
|
||||
alert('✓ Profil gespeichert!')
|
||||
} catch (err) {
|
||||
alert('Speichern fehlgeschlagen: ' + err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Group by category
|
||||
const grouped = {}
|
||||
types.forEach(type => {
|
||||
@@ -162,6 +189,18 @@ export default function AdminTrainingTypesPage() {
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Profile Builder */}
|
||||
{editingProfileId && (
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<ProfileBuilder
|
||||
trainingType={types.find(t => t.id === editingProfileId)}
|
||||
parameters={parameters}
|
||||
onSave={handleSaveProfile}
|
||||
onCancel={cancelEditProfile}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Edit form */}
|
||||
{editingId && formData && (
|
||||
<div className="card" style={{ padding: 16, marginBottom: 16 }}>
|
||||
@@ -336,6 +375,18 @@ export default function AdminTrainingTypesPage() {
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontSize: 13, fontWeight: 500 }}>
|
||||
{type.name_de} <span style={{ color: 'var(--text3)' }}>/ {type.name_en}</span>
|
||||
{type.profile && (
|
||||
<span style={{
|
||||
marginLeft: 8,
|
||||
padding: '2px 6px',
|
||||
background: 'var(--accent)',
|
||||
color: 'white',
|
||||
borderRadius: 4,
|
||||
fontSize: 10
|
||||
}}>
|
||||
✓ Profil
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{type.subcategory && (
|
||||
<div style={{ fontSize: 11, color: 'var(--text3)' }}>
|
||||
@@ -343,6 +394,19 @@ export default function AdminTrainingTypesPage() {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={() => startEditProfile(type.id)}
|
||||
style={{
|
||||
background: 'none',
|
||||
border: 'none',
|
||||
cursor: 'pointer',
|
||||
padding: 6,
|
||||
color: 'var(--accent)'
|
||||
}}
|
||||
title="Profil konfigurieren"
|
||||
>
|
||||
<Settings size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => startEdit(type)}
|
||||
style={{
|
||||
|
||||
Reference in new issue
Block a user