| 1 |
import React from 'react' |
| 2 |
import { TextControl, TextareaControl } from '@wordpress/components' |
| 3 |
import { __ } from '@wordpress/i18n' |
| 4 |
import { DuplicateReports } from './DuplicateReports' |
| 5 |
import type { DuplicateReport, FeedbackDraft, FeedbackType } from '../../types/Feedback' |
| 6 |
|
| 7 |
/** What the description asks for, and an example answer, for each kind of report. */ |
| 8 |
const DESCRIPTION_COPY: Record<FeedbackType, { label: string, placeholder: string }> = { |
| 9 |
bug: { |
| 10 |
label: __('What went wrong?', 'code-snippets'), |
| 11 |
placeholder: __('The editor stopped highlighting PHP and the Save button did nothing.', 'code-snippets') |
| 12 |
}, |
| 13 |
feature: { |
| 14 |
label: __('What would you like Code Snippets to do?', 'code-snippets'), |
| 15 |
placeholder: __('Let me tag snippets so I can filter large libraries by project.', 'code-snippets') |
| 16 |
}, |
| 17 |
feedback: { |
| 18 |
label: __('What is on your mind?', 'code-snippets'), |
| 19 |
placeholder: __('The new Conditions tab is much clearer, but the icons are hard to tell apart.', 'code-snippets') |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
export interface ReportSummaryFieldsProps { |
| 24 |
type: FeedbackType |
| 25 |
draft: FeedbackDraft |
| 26 |
duplicates: DuplicateReport[] |
| 27 |
updateDraft: (changes: Partial<FeedbackDraft>) => void |
| 28 |
} |
| 29 |
|
| 30 |
export const ReportSummaryFields: React.FC<ReportSummaryFieldsProps> = ({ |
| 31 |
type, |
| 32 |
draft, |
| 33 |
duplicates, |
| 34 |
updateDraft |
| 35 |
}) => |
| 36 |
<> |
| 37 |
<div className="code-snippets-feedback-field"> |
| 38 |
<TextControl |
| 39 |
label={__('Title', 'code-snippets')} |
| 40 |
help={__('A one-line summary. This becomes the issue title.', 'code-snippets')} |
| 41 |
maxLength={120} |
| 42 |
value={draft.title} |
| 43 |
placeholder={__('Syntax highlighting stops after switching editor tabs', 'code-snippets')} |
| 44 |
onChange={title => updateDraft({ title })} |
| 45 |
/> |
| 46 |
</div> |
| 47 |
|
| 48 |
<DuplicateReports reports={duplicates} /> |
| 49 |
|
| 50 |
<div className="code-snippets-feedback-field"> |
| 51 |
<TextareaControl |
| 52 |
label={DESCRIPTION_COPY[type].label} |
| 53 |
rows={4} |
| 54 |
value={draft.description} |
| 55 |
placeholder={DESCRIPTION_COPY[type].placeholder} |
| 56 |
onChange={description => updateDraft({ description })} |
| 57 |
/> |
| 58 |
</div> |
| 59 |
</> |
| 60 |
|