refactor: simplify review annotation controls

This commit is contained in:
江林铖 2026-08-01 14:46:16 +08:00
parent 40fc7a4a37
commit 3ceab7ac0b
3 changed files with 64 additions and 16 deletions

View File

@ -19,9 +19,11 @@ function markerTone(item: WorkReviewDisplayAnnotation) {
export function WorkReviewAnnotationMarker({
item,
onClick,
showComment = true,
}: {
item: WorkReviewDisplayAnnotation
onClick?: () => void
showComment?: boolean
}) {
const { annotation } = item
const alignRight = annotation.x > 0.62
@ -32,6 +34,7 @@ export function WorkReviewAnnotationMarker({
: '评审人'
const summary = annotation.comment.trim() || '待填写修改意见'
const label = `${roleLabel}标注 ${item.markerNumber}${item.reviewerName ? `,${item.reviewerName}` : ''}:${summary}`
const visualTitle = showComment ? label : `${roleLabel}标注 ${item.markerNumber}`
return (
<button
@ -42,7 +45,7 @@ export function WorkReviewAnnotationMarker({
}}
onPointerDown={(event) => event.stopPropagation()}
aria-label={label}
title={label}
title={visualTitle}
className="group absolute z-20 h-11 w-11 -translate-x-1/2 -translate-y-1/2 outline-none"
style={{ left: `${annotation.x * 100}%`, top: `${annotation.y * 100}%` }}
>
@ -50,9 +53,12 @@ export function WorkReviewAnnotationMarker({
{item.markerNumber}
</span>
<span
className={`pointer-events-none absolute top-1/2 hidden max-w-[220px] -translate-y-1/2 truncate rounded-full bg-[#101828]/90 px-3 py-1.5 text-[11px] font-semibold text-white shadow-[0_4px_14px_rgba(15,23,42,0.24)] sm:block ${
className={`pointer-events-none absolute top-1/2 max-w-[140px] -translate-y-1/2 truncate rounded-full bg-[#101828]/90 px-3 py-1.5 text-[11px] font-semibold text-white shadow-[0_4px_14px_rgba(15,23,42,0.24)] sm:max-w-[220px] ${
showComment ? 'block' : 'hidden'
} ${
alignRight ? 'right-9' : 'left-9'
}`}
aria-hidden={!showComment}
>
{summary}
</span>

View File

@ -78,7 +78,10 @@ function LongImagePane({
annotations = [],
annotationEnabled = false,
annotationMode = false,
annotationCount,
showAnnotationComments = true,
onToggleAnnotationMode,
onToggleAnnotationComments,
onAddAnnotation,
onSelectDraftAnnotation,
}: {
@ -91,7 +94,10 @@ function LongImagePane({
annotations?: WorkReviewDisplayAnnotation[]
annotationEnabled?: boolean
annotationMode?: boolean
annotationCount?: number
showAnnotationComments?: boolean
onToggleAnnotationMode?: () => void
onToggleAnnotationComments?: () => void
onAddAnnotation?: (x: number, y: number) => void
onSelectDraftAnnotation?: (annotationId: string) => void
}) {
@ -127,7 +133,7 @@ function LongImagePane({
return (
<section className="flex h-full min-h-0 flex-col bg-white" aria-label={label}>
<div className="flex min-h-12 shrink-0 items-center justify-between gap-2 border-b border-[#e4e7ec] px-3 py-1.5 sm:px-4">
<div className="flex min-w-0 items-center gap-2">
<div className="flex min-w-0 flex-1 items-center gap-2 overflow-x-auto whitespace-nowrap [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
<h2 className="shrink-0 text-[13px] font-bold text-[#101828]">{label}</h2>
{annotationEnabled && (
<button
@ -143,6 +149,23 @@ function LongImagePane({
{annotationMode ? '取消标注' : '+ 添加标注'}
</button>
)}
{annotationCount != null && (
<span className="shrink-0 text-[11px] font-semibold text-[#667085]">
已标注 {annotationCount} 个修改点
</span>
)}
{onToggleAnnotationComments && (
<button
type="button"
onClick={onToggleAnnotationComments}
disabled={!annotationCount}
aria-pressed={showAnnotationComments}
aria-label={`${showAnnotationComments ? '隐藏' : '显示'}标注点备注文字`}
className="min-h-8 shrink-0 rounded border border-[#d3dae5] bg-white px-2.5 text-[11px] font-bold text-[#344054] hover:border-[#8ab9ff] disabled:cursor-not-allowed disabled:text-[#98a2b3]"
>
{showAnnotationComments ? '隐藏备注' : '显示备注'}
</button>
)}
</div>
{displayGroups.length > 1 ? (
<div className="flex max-w-[52%] gap-1 overflow-x-auto py-1" aria-label={`${label}选择`}>
@ -228,6 +251,7 @@ function LongImagePane({
key={`${item.draft ? 'draft' : item.reviewerRole}-${item.annotation.id}`}
item={item}
onClick={item.draft ? () => onSelectDraftAnnotation?.(item.annotation.id) : undefined}
showComment={showAnnotationComments}
/>
))}
</div>
@ -270,6 +294,7 @@ export function WorkReviewReviewerWorkspace({
))
const [selectedAnnotation, setSelectedAnnotation] = useState<{ imageIndex: number; id: string } | null>(null)
const [annotationMode, setAnnotationMode] = useState(false)
const [showAnnotationComments, setShowAnnotationComments] = useState(true)
const [busyAction, setBusyAction] = useState<'approved' | 'revision_required' | null>(null)
const [error, setError] = useState<string | null>(null)
const [liveMessage, setLiveMessage] = useState('')
@ -294,6 +319,7 @@ export function WorkReviewReviewerWorkspace({
setDraftAnnotations(Array.from({ length: workImageCount }, () => []))
setSelectedAnnotation(null)
setAnnotationMode(false)
setShowAnnotationComments(true)
setError(null)
}, [selectedVersion?.id, workImageCount])
@ -314,6 +340,12 @@ export function WorkReviewReviewerWorkspace({
? draftAnnotations[selectedAnnotation.imageIndex]?.find((item) => item.id === selectedAnnotation.id)
: undefined
const totalDraftCount = draftAnnotations.reduce((sum, annotations) => sum + annotations.length, 0)
const totalSubmittedAnnotationCount = selectedVersion.reviews.reduce((reviewSum, review) => (
reviewSum + (review.imageComments || []).reduce((imageSum, imageComment) => (
imageSum + (imageComment.annotations?.length || 0)
), 0)
), 0)
const totalAnnotationCount = totalSubmittedAnnotationCount + totalDraftCount
const submittedAnnotations: WorkReviewDisplayAnnotation[] = selectedVersion.reviews.flatMap((review) => {
const imageComment = (review.imageComments || []).find((item) => item.imageIndex === activeWorkImageIndex)
return (imageComment?.annotations || []).map((annotation, index) => ({
@ -506,11 +538,14 @@ export function WorkReviewReviewerWorkspace({
annotations={visibleAnnotations}
annotationEnabled={Boolean(pendingRole)}
annotationMode={annotationMode}
annotationCount={totalAnnotationCount}
showAnnotationComments={showAnnotationComments}
onToggleAnnotationMode={() => {
setAnnotationMode((current) => !current)
setSelectedAnnotation(null)
setError(null)
}}
onToggleAnnotationComments={() => setShowAnnotationComments((current) => !current)}
onAddAnnotation={addAnnotation}
onSelectDraftAnnotation={(id) => {
setSelectedAnnotation({ imageIndex: activeWorkImageIndex, id })
@ -606,11 +641,14 @@ export function WorkReviewReviewerWorkspace({
annotations={visibleAnnotations}
annotationEnabled={Boolean(pendingRole)}
annotationMode={annotationMode}
annotationCount={totalAnnotationCount}
showAnnotationComments={showAnnotationComments}
onToggleAnnotationMode={() => {
setAnnotationMode((current) => !current)
setSelectedAnnotation(null)
setError(null)
}}
onToggleAnnotationComments={() => setShowAnnotationComments((current) => !current)}
onAddAnnotation={addAnnotation}
onSelectDraftAnnotation={(id) => {
setSelectedAnnotation({ imageIndex: activeWorkImageIndex, id })
@ -632,13 +670,6 @@ export function WorkReviewReviewerWorkspace({
)}
</div>
{hasReferenceImages && !annotationMode && (
<div className="pointer-events-none absolute inset-x-0 bottom-3 z-20 flex justify-center md:hidden">
<span className="rounded-full bg-[#101828]/85 px-3 py-1.5 text-[11px] font-semibold text-white">
左右滑动查看作品与参考
</span>
</div>
)}
</div>
<div className="shrink-0 border-t border-[#dfe5ee] bg-white px-3 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] sm:px-4" aria-busy={Boolean(busyAction)}>
@ -679,12 +710,7 @@ export function WorkReviewReviewerWorkspace({
</button>
</div>
</div>
) : (
<div className="mb-3 flex min-h-8 flex-wrap items-center justify-between gap-2 text-[11px] font-semibold text-[#667085]">
<span>已标注 {totalDraftCount} 个修改点;点击“添加标注”后在作品上选择位置</span>
<span>两位评审均提交后,系统会通知发起人</span>
</div>
)}
) : null}
{error && (
<div className="mb-3 rounded border border-[#f0b8b8] bg-[#fff5f5] px-3 py-2 text-[12px] font-semibold text-[#b42318]" role="alert">

View File

@ -52,6 +52,11 @@ describe('WorkReviewReviewerWorkspace', () => {
const onSubmitReview = jest.fn().mockResolvedValue(undefined)
render(<WorkReviewReviewerWorkspace project={project} onSubmitReview={onSubmitReview} />)
expect(screen.getAllByText('已标注 0 个修改点')).toHaveLength(2)
expect(screen.queryByText(/已标注 0 个修改点;点击/)).not.toBeInTheDocument()
expect(screen.queryByText('两位评审均提交后,系统会通知发起人')).not.toBeInTheDocument()
expect(screen.queryByText('左右滑动查看作品与参考')).not.toBeInTheDocument()
await user.click(screen.getAllByRole('button', { name: '+ 添加标注' })[0])
const canvas = screen.getAllByRole('group', { name: /作品长图,可添加位置批注/ })[0]
jest.spyOn(canvas, 'getBoundingClientRect').mockReturnValue({
@ -71,6 +76,17 @@ describe('WorkReviewReviewerWorkspace', () => {
const comment = screen.getByRole('textbox', { name: /图 1 · 标注 1 修改意见/ })
await user.type(comment, '人物位置向左移动')
await user.click(screen.getByRole('button', { name: '完成' }))
expect(screen.getAllByText('已标注 1 个修改点')).toHaveLength(2)
const commentLabels = screen.getAllByText('人物位置向左移动')
expect(commentLabels).toHaveLength(2)
await user.click(screen.getAllByRole('button', { name: '隐藏标注点备注文字' })[0])
expect(screen.getAllByRole('button', { name: '显示标注点备注文字' })).toHaveLength(2)
commentLabels.forEach((label) => expect(label).toHaveClass('hidden'))
await user.click(screen.getAllByRole('button', { name: '显示标注点备注文字' })[0])
expect(screen.getAllByRole('button', { name: '隐藏标注点备注文字' })).toHaveLength(2)
commentLabels.forEach((label) => expect(label).not.toHaveClass('hidden'))
await user.click(screen.getByRole('button', { name: '提交给修改人' }))
await waitFor(() => expect(onSubmitReview).toHaveBeenCalledTimes(1))