feat: dynamic placeholder picker with categories and search (Issue #28)
Major improvements: 1. PlaceholderPicker component (new) - Loads placeholders dynamically from backend catalog - Grouped by categories: Profil, Körper, Ernährung, Training, etc. - Search/filter functionality - Shows live example values from user data - Popup modal with expand/collapse categories 2. Replaced hardcoded placeholder chips - 'Platzhalter einfügen' button opens picker - Works in both base templates and pipeline inline templates - Auto-closes after selection 3. Uses existing backend system - GET /api/prompts/placeholders - placeholder_resolver.py with PLACEHOLDER_MAP - Dynamic, module-based placeholder system - No manual updates needed when modules add new placeholders Benefits: - Scalable: New modules can add placeholders without frontend changes - User-friendly: Search and categorization - Context-aware: Shows real example values - Future-proof: Backend-driven catalog
This commit is contained in:
1 parent
b058b0fd6f
commit
8036c99883
2 files changed
+327
-49
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
import { X, Plus, Trash2, MoveUp, MoveDown } from 'lucide-react'
|
||||
import { X, Plus, Trash2, MoveUp, MoveDown, Code } from 'lucide-react'
|
||||
import PlaceholderPicker from './PlaceholderPicker'
|
||||
|
||||
/**
|
||||
* Unified Prompt Editor Modal (Issue #28 Phase 3)
|
||||
@@ -36,6 +37,8 @@ export default function UnifiedPromptModal({ prompt, onSave, onClose }) {
|
||||
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
const [showPlaceholderPicker, setShowPlaceholderPicker] = useState(false)
|
||||
const [pickerTarget, setPickerTarget] = useState(null) // 'base' or {stage, promptIdx}
|
||||
|
||||
useEffect(() => {
|
||||
loadAvailablePrompts()
|
||||
@@ -390,31 +393,23 @@ export default function UnifiedPromptModal({ prompt, onSave, onClose }) {
|
||||
style={{ width: '100%', textAlign: 'left', resize: 'vertical', fontFamily: 'monospace', fontSize: 12 }}
|
||||
/>
|
||||
<div style={{ fontSize: 11, color: 'var(--text3)', marginTop: 4 }}>
|
||||
<div style={{ marginBottom: 4 }}>
|
||||
Verwende {'{{'} und {'}}'} für Platzhalter:
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 4 }}>
|
||||
{['weight_data', 'nutrition_data', 'activity_data', 'sleep_data', 'vitals_baseline', 'blood_pressure', 'profile_id', 'today'].map(ph => (
|
||||
<code
|
||||
key={ph}
|
||||
onClick={() => {
|
||||
const placeholder = `{{${ph}}}`
|
||||
setTemplate(template + placeholder)
|
||||
}}
|
||||
style={{
|
||||
padding: '2px 6px',
|
||||
background: 'var(--surface2)',
|
||||
borderRadius: 4,
|
||||
fontSize: 10,
|
||||
cursor: 'pointer',
|
||||
border: '1px solid var(--border)'
|
||||
}}
|
||||
title="Klicken zum Einfügen"
|
||||
>
|
||||
{'{{'}{ph}{'}}'}
|
||||
</code>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
className="btn"
|
||||
onClick={() => {
|
||||
setPickerTarget('base')
|
||||
setShowPlaceholderPicker(true)
|
||||
}}
|
||||
style={{
|
||||
fontSize: 12,
|
||||
padding: '6px 12px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 6
|
||||
}}
|
||||
>
|
||||
<Code size={14} />
|
||||
Platzhalter einfügen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -536,29 +531,23 @@ export default function UnifiedPromptModal({ prompt, onSave, onClose }) {
|
||||
style={{ width: '100%', fontSize: 12, textAlign: 'left', resize: 'vertical', fontFamily: 'monospace' }}
|
||||
/>
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 4 }}>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 4, marginTop: 4 }}>
|
||||
{['weight_data', 'nutrition_data', 'activity_data', 'sleep_data', 'vitals_baseline', 'blood_pressure', 'profile_id', 'today'].map(ph => (
|
||||
<code
|
||||
key={ph}
|
||||
onClick={() => {
|
||||
const placeholder = `{{${ph}}}`
|
||||
const currentValue = p.template || ''
|
||||
updateStagePrompt(stage.stage, pIdx, 'template', currentValue + placeholder)
|
||||
}}
|
||||
style={{
|
||||
padding: '2px 4px',
|
||||
background: 'var(--surface2)',
|
||||
borderRadius: 4,
|
||||
fontSize: 9,
|
||||
cursor: 'pointer',
|
||||
border: '1px solid var(--border)'
|
||||
}}
|
||||
title="Klicken zum Einfügen"
|
||||
>
|
||||
{'{{'}{ph}{'}}'}
|
||||
</code>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
className="btn"
|
||||
onClick={() => {
|
||||
setPickerTarget({ stage: stage.stage, promptIdx: pIdx })
|
||||
setShowPlaceholderPicker(true)
|
||||
}}
|
||||
style={{
|
||||
fontSize: 11,
|
||||
padding: '4px 8px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 4
|
||||
}}
|
||||
>
|
||||
<Code size={12} />
|
||||
Platzhalter
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -595,6 +584,37 @@ export default function UnifiedPromptModal({ prompt, onSave, onClose }) {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Placeholder Picker */}
|
||||
{showPlaceholderPicker && (
|
||||
<PlaceholderPicker
|
||||
onSelect={(placeholder) => {
|
||||
if (pickerTarget === 'base') {
|
||||
// Insert into base template
|
||||
setTemplate(template + placeholder)
|
||||
} else if (pickerTarget && typeof pickerTarget === 'object') {
|
||||
// Insert into pipeline stage template
|
||||
const { stage: stageNum, promptIdx } = pickerTarget
|
||||
setStages(stages.map(s => {
|
||||
if (s.stage === stageNum) {
|
||||
const newPrompts = [...s.prompts]
|
||||
const currentTemplate = newPrompts[promptIdx].template || ''
|
||||
newPrompts[promptIdx] = {
|
||||
...newPrompts[promptIdx],
|
||||
template: currentTemplate + placeholder
|
||||
}
|
||||
return { ...s, prompts: newPrompts }
|
||||
}
|
||||
return s
|
||||
}))
|
||||
}
|
||||
}}
|
||||
onClose={() => {
|
||||
setShowPlaceholderPicker(false)
|
||||
setPickerTarget(null)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user