feat: display_name + placeholder picker for prompts (Issue #28)
Migration 018:
- Add display_name column to ai_prompts
- Migrate existing prompts from hardcoded SLUG_LABELS
- Fallback: name if display_name is NULL
Backend:
- PromptCreate/Update models with display_name field
- create/update/duplicate endpoints handle display_name
- Fallback: use name if display_name not provided
Frontend:
- PromptEditModal: display_name input field
- Placeholder picker: button + dropdown with all placeholders
- Shows example values, inserts {{placeholder}} on click
- Analysis.jsx: use display_name instead of SLUG_LABELS
User-facing changes:
- Prompts now show custom display names (e.g. '🍽️ Ernährung')
- Admin can edit display names instead of hardcoded labels
- Template editor has 'Platzhalter einfügen' button
- No more hardcoded SLUG_LABELS in frontend
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
7a8a5aee98
commit
0c4264de44
5 files changed
+133
-11
No files matched your search
@@ -5,6 +5,7 @@ import PromptGenerator from './PromptGenerator'
|
||||
export default function PromptEditModal({ prompt, onSave, onClose }) {
|
||||
const [name, setName] = useState('')
|
||||
const [slug, setSlug] = useState('')
|
||||
const [displayName, setDisplayName] = useState('')
|
||||
const [description, setDescription] = useState('')
|
||||
const [category, setCategory] = useState('ganzheitlich')
|
||||
const [template, setTemplate] = useState('')
|
||||
@@ -13,6 +14,8 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
|
||||
const [preview, setPreview] = useState(null)
|
||||
const [unknownPlaceholders, setUnknownPlaceholders] = useState([])
|
||||
const [showGenerator, setShowGenerator] = useState(false)
|
||||
const [showPlaceholders, setShowPlaceholders] = useState(false)
|
||||
const [placeholders, setPlaceholders] = useState([])
|
||||
const [optimization, setOptimization] = useState(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [saving, setSaving] = useState(false)
|
||||
@@ -31,6 +34,7 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
|
||||
if (prompt) {
|
||||
setName(prompt.name || '')
|
||||
setSlug(prompt.slug || '')
|
||||
setDisplayName(prompt.display_name || '')
|
||||
setDescription(prompt.description || '')
|
||||
setCategory(prompt.category || 'ganzheitlich')
|
||||
setTemplate(prompt.template || '')
|
||||
@@ -92,6 +96,7 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
|
||||
// Update existing
|
||||
await api.updatePrompt(prompt.id, {
|
||||
name,
|
||||
display_name: displayName || null,
|
||||
description,
|
||||
category,
|
||||
template,
|
||||
@@ -106,6 +111,7 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
|
||||
await api.createPrompt({
|
||||
name,
|
||||
slug,
|
||||
display_name: displayName || null,
|
||||
description,
|
||||
category,
|
||||
template,
|
||||
@@ -137,6 +143,28 @@ 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)
|
||||
setShowPlaceholders(true)
|
||||
} catch (e) {
|
||||
alert('Fehler beim Laden der Platzhalter: ' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
const insertPlaceholder = (key) => {
|
||||
setTemplate(prev => prev + ` {{${key}}}`)
|
||||
setShowPlaceholders(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
position:'fixed', inset:0, background:'rgba(0,0,0,0.5)',
|
||||
@@ -208,6 +236,22 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label className="form-label" style={{display:'block', marginBottom:6}}>
|
||||
Anzeigename (in der Anwendung sichtbar)
|
||||
</label>
|
||||
<input
|
||||
className="form-input"
|
||||
value={displayName}
|
||||
onChange={e => setDisplayName(e.target.value)}
|
||||
placeholder="z.B. 🍽️ Protein-Analyse"
|
||||
style={{width:'100%', textAlign:'left'}}
|
||||
/>
|
||||
<div style={{fontSize:11, color:'var(--text3)', marginTop:4}}>
|
||||
Leer lassen = Titel wird verwendet
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="form-label" style={{display:'block', marginBottom:6}}>Beschreibung</label>
|
||||
<textarea
|
||||
@@ -244,9 +288,60 @@ export default function PromptEditModal({ prompt, onSave, onClose }) {
|
||||
placeholder="Du bist ein Ernährungsexperte. Analysiere folgende Daten: {{nutrition_summary}}"
|
||||
style={{width:'100%', textAlign:'left', fontFamily:'monospace', fontSize:12, resize:'vertical'}}
|
||||
/>
|
||||
<div style={{fontSize:11, color:'var(--text3)', marginTop:4}}>
|
||||
Nutze Platzhalter wie {`{{weight_aktuell}}`}, {`{{protein_avg}}`}, etc.
|
||||
<div style={{display:'flex', justifyContent:'space-between', alignItems:'center', marginTop:6}}>
|
||||
<div style={{fontSize:11, color:'var(--text3)'}}>
|
||||
Nutze Platzhalter wie {`{{weight_aktuell}}`}, {`{{protein_avg}}`}, etc.
|
||||
</div>
|
||||
<button
|
||||
className="btn"
|
||||
onClick={loadPlaceholders}
|
||||
type="button"
|
||||
style={{fontSize:12, padding:'4px 10px'}}
|
||||
>
|
||||
📋 Platzhalter einfügen
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Placeholders Dropdown */}
|
||||
{showPlaceholders && placeholders.length > 0 && (
|
||||
<div style={{
|
||||
marginTop:8, padding:12, background:'var(--surface)',
|
||||
border:'1px solid var(--border)', borderRadius:8,
|
||||
maxHeight:300, overflow:'auto'
|
||||
}}>
|
||||
<div style={{display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:8}}>
|
||||
<strong style={{fontSize:13}}>Verfügbare Platzhalter:</strong>
|
||||
<button
|
||||
onClick={() => setShowPlaceholders(false)}
|
||||
style={{
|
||||
background:'none', border:'none', cursor:'pointer',
|
||||
fontSize:18, color:'var(--text3)'
|
||||
}}
|
||||
>
|
||||
×
|
||||
</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}
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{display:'flex', alignItems:'center', gap:8}}>
|
||||
|
||||
Reference in new issue
Block a user