fix: placeholder picker improvements + insight display names (Issue #28)
Deploy Development / deploy (push) Successful in 49s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s

Backend:
- get_placeholder_catalog(): grouped placeholders with descriptions
- Returns {category: [{key, description, example}]} format
- Categories: Profil, Körper, Ernährung, Training, Schlaf, Vitalwerte, Zeitraum

Frontend - Placeholder Picker:
- Grouped by category with visual separation
- Search/filter across keys and descriptions
- Hover effects for better UX
- Insert at cursor position (not at end)
- Shows: key + description + example value
- 'Keine Platzhalter gefunden' message when filtered

Frontend - Insight Display Names:
- InsightCard receives prompts array
- Finds matching prompt by scope/slug
- Shows prompt.display_name instead of hardcoded SLUG_LABELS
- History tab also shows display_name in group headers
- Fallback chain: display_name → SLUG_LABELS → scope

User-facing improvements:
✓ Platzhalter zeigen echte Daten statt Zahlen
✓ Durchsuchbar + filterbar
✓ Einfügen an Cursor-Position
✓ Insights zeigen custom Namen (z.B. '🍽️ Meine Ernährung')

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 4.6 committed 2026-03-25 06:44:22 +01:00
1 parent 0c4264de44
commit 5e7ef718e0
4 files changed
+208 -43

No files matched your search

+116 -34
View File
@@ -15,7 +15,9 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
const [unknownPlaceholders, setUnknownPlaceholders] = useState([])
const [showGenerator, setShowGenerator] = useState(false)
const [showPlaceholders, setShowPlaceholders] = useState(false)
const [placeholders, setPlaceholders] = useState([])
const [placeholders, setPlaceholders] = useState({})
const [placeholderFilter, setPlaceholderFilter] = useState('')
const [templateRef, setTemplateRef] = useState(null)
const [optimization, setOptimization] = useState(null)
const [loading, setLoading] = useState(false)
const [saving, setSaving] = useState(false)
@@ -146,22 +148,36 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
const loadPlaceholders = async () => {
try {
const data = await api.listPlaceholders()
// Flatten nested structure into simple list
const flatList = []
Object.entries(data).forEach(([category, items]) => {
Object.entries(items).forEach(([key, value]) => {
flatList.push({ key, value, category })
})
})
setPlaceholders(flatList)
setPlaceholders(data)
setShowPlaceholders(true)
setPlaceholderFilter('')
} catch (e) {
alert('Fehler beim Laden der Platzhalter: ' + e.message)
}
}
const insertPlaceholder = (key) => {
setTemplate(prev => prev + ` {{${key}}}`)
if (!templateRef) {
// Fallback: append at end
setTemplate(prev => prev + ` {{${key}}}`)
} else {
// Insert at cursor position
const start = templateRef.selectionStart
const end = templateRef.selectionEnd
const text = template
const before = text.substring(0, start)
const after = text.substring(end)
const inserted = `{{${key}}}`
setTemplate(before + inserted + after)
// Set cursor position after inserted placeholder
setTimeout(() => {
templateRef.selectionStart = templateRef.selectionEnd = start + inserted.length
templateRef.focus()
}, 0)
}
setShowPlaceholders(false)
}
@@ -281,6 +297,7 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
<div>
<label className="form-label" style={{display:'block', marginBottom:6}}>Template *</label>
<textarea
ref={el => setTemplateRef(el)}
className="form-input"
value={template}
onChange={e => setTemplate(e.target.value)}
@@ -303,43 +320,108 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
</div>
{/* Placeholders Dropdown */}
{showPlaceholders && placeholders.length > 0 && (
{showPlaceholders && Object.keys(placeholders).length > 0 && (
<div style={{
marginTop:8, padding:12, background:'var(--surface)',
marginTop:8, padding:16, background:'var(--surface)',
border:'1px solid var(--border)', borderRadius:8,
maxHeight:300, overflow:'auto'
maxHeight:400, overflow:'auto'
}}>
<div style={{display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:8}}>
<strong style={{fontSize:13}}>Verfügbare Platzhalter:</strong>
<div style={{display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:12}}>
<strong style={{fontSize:14}}>Platzhalter einfügen</strong>
<button
onClick={() => setShowPlaceholders(false)}
style={{
background:'none', border:'none', cursor:'pointer',
fontSize:18, color:'var(--text3)'
fontSize:20, color:'var(--text3)', padding:0
}}
>
×
</button>
</div>
<div style={{display:'grid', gap:6}}>
{placeholders.map((p, i) => (
<button
key={i}
onClick={() => insertPlaceholder(p.key)}
style={{
textAlign:'left', padding:'6px 10px',
background:'var(--surface2)', border:'1px solid var(--border)',
borderRadius:6, cursor:'pointer', fontSize:12,
fontFamily:'monospace'
}}
>
<div style={{fontWeight:600, color:'var(--accent)'}}>{`{{${p.key}}}`}</div>
<div style={{fontSize:11, color:'var(--text3)', marginTop:2}}>
Beispiel: {p.value}
{/* Search Filter */}
<input
type="text"
placeholder="Suchen..."
value={placeholderFilter}
onChange={e => setPlaceholderFilter(e.target.value)}
style={{
width:'100%', padding:'6px 10px', marginBottom:12,
background:'var(--surface2)', border:'1px solid var(--border)',
borderRadius:6, fontSize:12
}}
/>
{/* Grouped Placeholders */}
{Object.entries(placeholders).map(([category, items]) => {
// Filter items
const filteredItems = items.filter(p =>
placeholderFilter === '' ||
p.key.toLowerCase().includes(placeholderFilter.toLowerCase()) ||
p.description.toLowerCase().includes(placeholderFilter.toLowerCase())
)
if (filteredItems.length === 0) return null
return (
<div key={category} style={{marginBottom:16}}>
<div style={{
fontSize:11, fontWeight:600, color:'var(--text3)',
textTransform:'uppercase', letterSpacing:'0.5px',
marginBottom:6
}}>
{category}
</div>
</button>
))}
</div>
<div style={{display:'grid', gap:6}}>
{filteredItems.map((p, i) => (
<button
key={i}
onClick={() => insertPlaceholder(p.key)}
style={{
textAlign:'left', padding:'8px 10px',
background:'var(--surface2)', border:'1px solid var(--border)',
borderRadius:6, cursor:'pointer',
transition:'all 0.15s'
}}
onMouseEnter={e => {
e.currentTarget.style.background = 'var(--accent-light)'
e.currentTarget.style.borderColor = 'var(--accent)'
}}
onMouseLeave={e => {
e.currentTarget.style.background = 'var(--surface2)'
e.currentTarget.style.borderColor = 'var(--border)'
}}
>
<div style={{
fontWeight:600, fontSize:12, fontFamily:'monospace',
color:'var(--accent)', marginBottom:2
}}>
{`{{${p.key}}}`}
</div>
<div style={{fontSize:11, color:'var(--text2)', marginBottom:2}}>
{p.description}
</div>
<div style={{fontSize:10, color:'var(--text3)', fontStyle:'italic'}}>
Beispiel: {p.example}
</div>
</button>
))}
</div>
</div>
)
})}
{/* No results */}
{placeholderFilter && Object.values(placeholders).every(items =>
items.filter(p =>
p.key.toLowerCase().includes(placeholderFilter.toLowerCase()) ||
p.description.toLowerCase().includes(placeholderFilter.toLowerCase())
).length === 0
) && (
<div style={{textAlign:'center', padding:20, color:'var(--text3)', fontSize:12}}>
Keine Platzhalter gefunden für "{placeholderFilter}"
</div>
)}
</div>
)}
</div>