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