From 0128a050f7fdc2aabaed968315f1d56e08ed54ca Mon Sep 17 00:00:00 2001 From: lashman Date: Sun, 22 Mar 2026 07:01:13 +0200 Subject: [PATCH] render description fields dynamically from post data instead of hardcoded constants --- packages/web/src/pages/PostDetail.tsx | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/web/src/pages/PostDetail.tsx b/packages/web/src/pages/PostDetail.tsx index 37b807f..56e6550 100644 --- a/packages/web/src/pages/PostDetail.tsx +++ b/packages/web/src/pages/PostDetail.tsx @@ -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): { 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)} />
- {fields.map((f) => ( + {allFields.map((f) => (