feat: Pipeline-System Frontend - Admin UI (Issue #28, Phase 2 Part 1)
Implementiert Admin-UI für Pipeline-Konfigurationen: - Pipeline-Config Dialog mit Module-Auswahl - Stage-Konfiguration (Stage 1/2/3 Prompts) - Admin-UI: Zwei Tabs (Prompts + Pipeline-Configs) - CRUD-Operationen für Pipeline-Configs - API-Integration: Pipeline-Config Endpoints **Frontend:** - components/PipelineConfigModal.jsx (neu): Dialog für Pipeline-Konfiguration - Module-Auswahl mit Zeiträumen (7 Module) - Stage 1: Multi-Select für parallele Prompts - Stage 2: Synthese-Prompt Auswahl - Stage 3: Optional (Goals) - Validierung (mind. 1 Modul, mind. 1 Stage-1-Prompt, Stage-2 erforderlich) - pages/AdminPromptsPage.jsx (erweitert): Tab-Navigation - Tab 1: Prompts (bestehend) - Tab 2: Pipeline-Konfigurationen (neu) - Liste aller Configs mit Status (Aktiv, Standard) - Aktionen: Bearbeiten, Löschen, Als Standard setzen - Icons: Star, Edit, Trash2 - utils/api.js (erweitert): - listPipelineConfigs, createPipelineConfig, updatePipelineConfig - deletePipelineConfig, setDefaultPipelineConfig - executePipeline, resetPromptToDefault **Nächste Schritte:** - Pipeline-Auswahl in AnalysisPage (User-Seite) - Mobile-Responsive Design Issue #28 Progress: Frontend 2/3 (67%) | Design 0/3 | Testing 0/1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
053a9e18cf
commit
b23e361791
3 files changed
+605
-6
No files matched your search
@@ -0,0 +1,386 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
import { X } from 'lucide-react'
|
||||
|
||||
const MODULES = [
|
||||
{ id: 'körper', label: 'Körper', defaultDays: 30 },
|
||||
{ id: 'ernährung', label: 'Ernährung', defaultDays: 30 },
|
||||
{ id: 'training', label: 'Training', defaultDays: 14 },
|
||||
{ id: 'schlaf', label: 'Schlaf', defaultDays: 14 },
|
||||
{ id: 'vitalwerte', label: 'Vitalwerte', defaultDays: 7 },
|
||||
{ id: 'mentales', label: 'Mentales', defaultDays: 7 },
|
||||
{ id: 'ziele', label: 'Ziele', defaultDays: null }, // No timeframe for goals
|
||||
]
|
||||
|
||||
export default function PipelineConfigModal({ config, onSave, onClose }) {
|
||||
const [name, setName] = useState('')
|
||||
const [description, setDescription] = useState('')
|
||||
const [isDefault, setIsDefault] = useState(false)
|
||||
const [active, setActive] = useState(true)
|
||||
|
||||
// Modules state: {körper: true, ernährung: false, ...}
|
||||
const [modules, setModules] = useState({})
|
||||
|
||||
// Timeframes state: {körper: 30, ernährung: 30, ...}
|
||||
const [timeframes, setTimeframes] = useState({})
|
||||
|
||||
// Stage prompts
|
||||
const [stage1Prompts, setStage1Prompts] = useState([])
|
||||
const [stage2Prompt, setStage2Prompt] = useState('')
|
||||
const [stage3Prompt, setStage3Prompt] = useState('')
|
||||
|
||||
// Available prompts (for dropdowns)
|
||||
const [availablePrompts, setAvailablePrompts] = useState([])
|
||||
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
loadAvailablePrompts()
|
||||
|
||||
if (config) {
|
||||
// Edit mode
|
||||
setName(config.name || '')
|
||||
setDescription(config.description || '')
|
||||
setIsDefault(config.is_default || false)
|
||||
setActive(config.active ?? true)
|
||||
setModules(config.modules || {})
|
||||
setTimeframes(config.timeframes || {})
|
||||
setStage1Prompts(config.stage1_prompts || [])
|
||||
setStage2Prompt(config.stage2_prompt || '')
|
||||
setStage3Prompt(config.stage3_prompt || '')
|
||||
} else {
|
||||
// New mode - set defaults
|
||||
const defaultModules = {}
|
||||
const defaultTimeframes = {}
|
||||
MODULES.forEach(m => {
|
||||
defaultModules[m.id] = false
|
||||
if (m.defaultDays) defaultTimeframes[m.id] = m.defaultDays
|
||||
})
|
||||
setModules(defaultModules)
|
||||
setTimeframes(defaultTimeframes)
|
||||
}
|
||||
}, [config])
|
||||
|
||||
const loadAvailablePrompts = async () => {
|
||||
try {
|
||||
const prompts = await api.listAdminPrompts()
|
||||
setAvailablePrompts(prompts)
|
||||
} catch (e) {
|
||||
setError('Fehler beim Laden der Prompts: ' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const toggleModule = (moduleId) => {
|
||||
setModules(prev => ({ ...prev, [moduleId]: !prev[moduleId] }))
|
||||
}
|
||||
|
||||
const updateTimeframe = (moduleId, days) => {
|
||||
setTimeframes(prev => ({ ...prev, [moduleId]: parseInt(days) || 0 }))
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
// Validation
|
||||
if (!name.trim()) {
|
||||
setError('Bitte Namen eingeben')
|
||||
return
|
||||
}
|
||||
|
||||
const activeModules = Object.entries(modules).filter(([_, active]) => active).map(([id]) => id)
|
||||
if (activeModules.length === 0) {
|
||||
setError('Mindestens ein Modul muss aktiviert sein')
|
||||
return
|
||||
}
|
||||
|
||||
if (stage1Prompts.length === 0) {
|
||||
setError('Mindestens ein Stage-1-Prompt erforderlich')
|
||||
return
|
||||
}
|
||||
|
||||
if (!stage2Prompt) {
|
||||
setError('Stage-2-Prompt (Synthese) erforderlich')
|
||||
return
|
||||
}
|
||||
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
|
||||
try {
|
||||
const data = {
|
||||
name,
|
||||
description,
|
||||
is_default: isDefault,
|
||||
active,
|
||||
modules,
|
||||
timeframes,
|
||||
stage1_prompts: stage1Prompts,
|
||||
stage2_prompt: stage2Prompt,
|
||||
stage3_prompt: stage3Prompt || null
|
||||
}
|
||||
|
||||
if (config?.id) {
|
||||
await api.updatePipelineConfig(config.id, data)
|
||||
} else {
|
||||
await api.createPipelineConfig(data)
|
||||
}
|
||||
|
||||
onSave()
|
||||
} catch (e) {
|
||||
setError(e.message)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const addStage1Prompt = (slug) => {
|
||||
if (slug && !stage1Prompts.includes(slug)) {
|
||||
setStage1Prompts(prev => [...prev, slug])
|
||||
}
|
||||
}
|
||||
|
||||
const removeStage1Prompt = (slug) => {
|
||||
setStage1Prompts(prev => prev.filter(s => s !== slug))
|
||||
}
|
||||
|
||||
// Filter prompts: only pipeline-type prompts
|
||||
const pipelinePrompts = availablePrompts.filter(p =>
|
||||
p.slug && p.slug.startsWith('pipeline_') && p.slug !== 'pipeline_synthesis' && p.slug !== 'pipeline_goals'
|
||||
)
|
||||
|
||||
const synthesisPrompts = availablePrompts.filter(p =>
|
||||
p.slug && (p.slug === 'pipeline_synthesis' || p.slug.includes('synthesis'))
|
||||
)
|
||||
|
||||
const goalsPrompts = availablePrompts.filter(p =>
|
||||
p.slug && (p.slug === 'pipeline_goals' || p.slug.includes('goals') || p.slug.includes('ziele'))
|
||||
)
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
position:'fixed', inset:0, background:'rgba(0,0,0,0.5)',
|
||||
display:'flex', alignItems:'center', justifyContent:'center',
|
||||
zIndex:1000, padding:20, overflow:'auto'
|
||||
}}>
|
||||
<div style={{
|
||||
background:'var(--bg)', borderRadius:12, maxWidth:900, width:'100%',
|
||||
maxHeight:'90vh', overflow:'auto', padding:24
|
||||
}}>
|
||||
<div style={{display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:24}}>
|
||||
<h2 style={{margin:0, fontSize:20, fontWeight:600}}>
|
||||
{config ? 'Pipeline-Konfiguration bearbeiten' : 'Neue Pipeline-Konfiguration'}
|
||||
</h2>
|
||||
<button
|
||||
onClick={onClose}
|
||||
style={{background:'none', border:'none', cursor:'pointer', padding:4}}
|
||||
>
|
||||
<X size={24} color="var(--text3)" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div style={{
|
||||
padding:12, background:'#fee', color:'#c00', borderRadius:8, marginBottom:16, fontSize:13
|
||||
}}>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Basic Info */}
|
||||
<div style={{display:'grid', gap:16, marginBottom:24}}>
|
||||
<div>
|
||||
<label className="form-label" style={{display:'block', marginBottom:6}}>Name *</label>
|
||||
<input
|
||||
className="form-input"
|
||||
value={name}
|
||||
onChange={e => setName(e.target.value)}
|
||||
placeholder="z.B. Alltags-Check"
|
||||
style={{width:'100%', textAlign:'left'}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="form-label" style={{display:'block', marginBottom:6}}>Beschreibung</label>
|
||||
<textarea
|
||||
className="form-input"
|
||||
value={description}
|
||||
onChange={e => setDescription(e.target.value)}
|
||||
rows={2}
|
||||
placeholder="Kurze Beschreibung der Pipeline"
|
||||
style={{width:'100%', textAlign:'left', resize:'vertical'}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{display:'flex', gap:16, alignItems:'center'}}>
|
||||
<label style={{display:'flex', alignItems:'center', gap:6, cursor:'pointer'}}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={active}
|
||||
onChange={e => setActive(e.target.checked)}
|
||||
/>
|
||||
<span style={{fontSize:13}}>Aktiv</span>
|
||||
</label>
|
||||
|
||||
<label style={{display:'flex', alignItems:'center', gap:6, cursor:'pointer'}}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={isDefault}
|
||||
onChange={e => setIsDefault(e.target.checked)}
|
||||
/>
|
||||
<span style={{fontSize:13}}>Als Standard-Pipeline markieren</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Module Selection */}
|
||||
<div style={{marginBottom:24}}>
|
||||
<h3 style={{fontSize:16, fontWeight:600, marginBottom:12}}>Module & Zeiträume</h3>
|
||||
<div style={{
|
||||
background:'var(--surface)', padding:16, borderRadius:8,
|
||||
border:'1px solid var(--border)'
|
||||
}}>
|
||||
{MODULES.map(module => (
|
||||
<div key={module.id} style={{
|
||||
display:'flex', alignItems:'center', gap:12,
|
||||
padding:'8px 0', borderBottom:'1px solid var(--border)'
|
||||
}}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={modules[module.id] || false}
|
||||
onChange={() => toggleModule(module.id)}
|
||||
id={`module-${module.id}`}
|
||||
/>
|
||||
<label htmlFor={`module-${module.id}`} style={{flex:1, fontSize:13, cursor:'pointer'}}>
|
||||
{module.label}
|
||||
</label>
|
||||
|
||||
{module.defaultDays && (
|
||||
<div style={{display:'flex', alignItems:'center', gap:6}}>
|
||||
<input
|
||||
type="number"
|
||||
value={timeframes[module.id] || module.defaultDays}
|
||||
onChange={e => updateTimeframe(module.id, e.target.value)}
|
||||
disabled={!modules[module.id]}
|
||||
min="1"
|
||||
max="365"
|
||||
style={{
|
||||
width:60, padding:'4px 8px', fontSize:12,
|
||||
opacity: modules[module.id] ? 1 : 0.5
|
||||
}}
|
||||
/>
|
||||
<span style={{fontSize:11, color:'var(--text3)'}}>Tage</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Stage Configuration */}
|
||||
<div style={{marginBottom:24}}>
|
||||
<h3 style={{fontSize:16, fontWeight:600, marginBottom:12}}>Pipeline-Stufen</h3>
|
||||
|
||||
{/* Stage 1 */}
|
||||
<div style={{marginBottom:16}}>
|
||||
<label className="form-label" style={{display:'block', marginBottom:6}}>
|
||||
Stage 1: Parallel-Analysen *
|
||||
</label>
|
||||
<div style={{fontSize:11, color:'var(--text3)', marginBottom:8}}>
|
||||
Diese Prompts laufen parallel und liefern JSON-Summaries für Stage 2
|
||||
</div>
|
||||
|
||||
<select
|
||||
className="form-select"
|
||||
onChange={e => { addStage1Prompt(e.target.value); e.target.value = '' }}
|
||||
style={{width:'100%', marginBottom:8}}
|
||||
>
|
||||
<option value="">+ Prompt hinzufügen</option>
|
||||
{pipelinePrompts.map(p => (
|
||||
<option key={p.slug} value={p.slug} disabled={stage1Prompts.includes(p.slug)}>
|
||||
{p.display_name || p.name} ({p.slug})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
{stage1Prompts.length > 0 && (
|
||||
<div style={{display:'flex', flexWrap:'wrap', gap:6}}>
|
||||
{stage1Prompts.map(slug => (
|
||||
<div key={slug} style={{
|
||||
padding:'4px 8px', background:'var(--surface2)', borderRadius:6,
|
||||
fontSize:11, display:'flex', alignItems:'center', gap:6
|
||||
}}>
|
||||
<span>{slug}</span>
|
||||
<X
|
||||
size={14}
|
||||
onClick={() => removeStage1Prompt(slug)}
|
||||
style={{cursor:'pointer', color:'var(--danger)'}}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Stage 2 */}
|
||||
<div style={{marginBottom:16}}>
|
||||
<label className="form-label" style={{display:'block', marginBottom:6}}>
|
||||
Stage 2: Synthese *
|
||||
</label>
|
||||
<div style={{fontSize:11, color:'var(--text3)', marginBottom:8}}>
|
||||
Kombiniert alle Stage-1-Ergebnisse zu einer narrativen Analyse
|
||||
</div>
|
||||
<select
|
||||
className="form-select"
|
||||
value={stage2Prompt}
|
||||
onChange={e => setStage2Prompt(e.target.value)}
|
||||
style={{width:'100%'}}
|
||||
>
|
||||
<option value="">-- Bitte wählen --</option>
|
||||
{synthesisPrompts.map(p => (
|
||||
<option key={p.slug} value={p.slug}>
|
||||
{p.display_name || p.name} ({p.slug})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Stage 3 */}
|
||||
<div>
|
||||
<label className="form-label" style={{display:'block', marginBottom:6}}>
|
||||
Stage 3: Optional (z.B. Zielabgleich)
|
||||
</label>
|
||||
<div style={{fontSize:11, color:'var(--text3)', marginBottom:8}}>
|
||||
Optional: Zusätzliche Auswertung basierend auf Synthese
|
||||
</div>
|
||||
<select
|
||||
className="form-select"
|
||||
value={stage3Prompt}
|
||||
onChange={e => setStage3Prompt(e.target.value)}
|
||||
style={{width:'100%'}}
|
||||
>
|
||||
<option value="">-- Keine --</option>
|
||||
{goalsPrompts.map(p => (
|
||||
<option key={p.slug} value={p.slug}>
|
||||
{p.display_name || p.name} ({p.slug})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div style={{display:'flex', gap:12, justifyContent:'flex-end', paddingTop:16, borderTop:'1px solid var(--border)'}}>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Abbrechen
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={handleSave}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Speichern...' : 'Speichern'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user