render description fields dynamically from post data instead of hardcoded constants

This commit is contained in:
2026-03-22 07:01:13 +02:00
parent 5311f5d1ee
commit 0128a050f7

View File

@@ -57,20 +57,20 @@ interface TimelineResponse {
isCurrentAdmin: boolean
}
const BUG_FIELDS: { key: string; label: string }[] = [
{ key: 'stepsToReproduce', label: 'Steps to reproduce' },
{ key: 'expectedBehavior', label: 'Expected behavior' },
{ key: 'actualBehavior', label: 'Actual behavior' },
{ key: 'environment', label: 'Environment' },
{ key: 'additionalContext', label: 'Additional context' },
]
function keyToLabel(key: string): string {
return key
.replace(/([a-z])([A-Z])/g, '$1 $2')
.replace(/[_-]+/g, ' ')
.split(' ')
.map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
.join(' ')
}
const FEATURE_FIELDS: { key: string; label: string }[] = [
{ key: 'useCase', label: 'Use case' },
{ key: 'proposedSolution', label: 'Proposed solution' },
{ key: 'alternativesConsidered', label: 'Alternatives considered' },
{ key: 'additionalContext', label: 'Additional context' },
]
function getDescriptionFields(description: Record<string, string>): { key: string; label: string }[] {
return Object.keys(description)
.filter(k => description[k] && description[k].trim() && description[k].trim() !== '-')
.map(k => ({ key: k, label: keyToLabel(k) }))
}
function ImportanceBar({
counts,
@@ -430,7 +430,8 @@ export default function PostDetail() {
}
const typeLabel = post.type === 'BUG_REPORT' ? 'Bug' : 'Feature'
const fields = post.type === 'BUG_REPORT' ? BUG_FIELDS : FEATURE_FIELDS
const fields = getDescriptionFields(post.description)
const allFields = Object.keys(post.description).map(k => ({ key: k, label: keyToLabel(k) }))
const canEdit = auth.user && (post.author?.id === auth.user.id || admin.isAdmin) && !post.isEditLocked
return (
@@ -569,7 +570,7 @@ export default function PostDetail() {
onChange={(e) => setEditTitle(e.target.value)}
/>
<div className="flex flex-col gap-4 mb-4">
{fields.map((f) => (
{allFields.map((f) => (
<div key={f.key}>
<label
className="font-medium block mb-1.5"