From 3ceab7ac0bdfdc125a9537478346329fcbf190bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=9E=97=E9=93=96?= Date: Sat, 1 Aug 2026 14:46:16 +0800 Subject: [PATCH] refactor: simplify review annotation controls --- .../WorkReviewAnnotationMarker.tsx | 10 +++- .../WorkReviewReviewerWorkspace.tsx | 54 ++++++++++++++----- .../work-review-reviewer-workspace.test.tsx | 16 ++++++ 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/components/work-review/WorkReviewAnnotationMarker.tsx b/components/work-review/WorkReviewAnnotationMarker.tsx index ca1792d7..e5dbc956 100644 --- a/components/work-review/WorkReviewAnnotationMarker.tsx +++ b/components/work-review/WorkReviewAnnotationMarker.tsx @@ -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 ( + )} {displayGroups.length > 1 ? (
@@ -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} /> ))}
@@ -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(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({ )} - {hasReferenceImages && !annotationMode && ( -
- - 左右滑动查看作品与参考 - -
- )}
@@ -679,12 +710,7 @@ export function WorkReviewReviewerWorkspace({
- ) : ( -
- 已标注 {totalDraftCount} 个修改点;点击“添加标注”后在作品上选择位置 - 两位评审均提交后,系统会通知发起人 -
- )} + ) : null} {error && (
diff --git a/lib/__tests__/work-review-reviewer-workspace.test.tsx b/lib/__tests__/work-review-reviewer-workspace.test.tsx index fb10442b..4615f9af 100644 --- a/lib/__tests__/work-review-reviewer-workspace.test.tsx +++ b/lib/__tests__/work-review-reviewer-workspace.test.tsx @@ -52,6 +52,11 @@ describe('WorkReviewReviewerWorkspace', () => { const onSubmitReview = jest.fn().mockResolvedValue(undefined) render() + 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))