feat(annotator): match task-specific Figma screens

This commit is contained in:
quanganh2k4 2026-10-31 00:05:28 +07:00
parent 9de99c833b
commit 9ed811369d
23 changed files with 94 additions and 119 deletions

View file

@ -2,16 +2,17 @@ import React from 'react'
import { Outlet } from 'react-router-dom'
import { Sidebar } from './components/Sidebar/Sidebar'
import { Header } from './components/Header/Header'
import { ANNOTATOR_COLORS } from '@/pages/annotator/annotatorTheme'
export const AnnotatorLayout: React.FC<{ children?: React.ReactNode }> = ({
children,
}) => {
return (
<div className="flex h-screen w-screen overflow-hidden bg-[#F8FAFC] text-slate-900">
<Sidebar />
<div className="flex-1 flex flex-col min-w-0 h-full overflow-hidden">
<Header />
<main className="flex-1 overflow-hidden">{children || <Outlet />}</main>
<div className="flex h-screen min-h-0 w-screen overflow-hidden text-slate-900" style={{ backgroundColor: ANNOTATOR_COLORS.canvas }}>
<Sidebar isProjectWorkspace />
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
<Header isProjectWorkspace />
<main className="min-h-0 flex-1 overflow-y-auto">{children || <Outlet />}</main>
</div>
</div>
)

View file

@ -11,6 +11,9 @@ export interface BreadcrumbProps {
}
const PROJECT_NAMES: Record<string, string> = {
urban_vehicles_v2: 'Phương tiện đô thị',
traffic_camera_v2: 'Giao thông đô thị',
street_masks_v1: 'Phân vùng đường phố',
'proj-1': 'Phương tiện đô thị',
'proj-2': 'Giao thông đô thị',
'proj-3': 'Phân vùng đường phố',
@ -18,6 +21,7 @@ const PROJECT_NAMES: Record<string, string> = {
export const Breadcrumb: React.FC<BreadcrumbProps> = ({ items }) => {
const location = useLocation()
const isProjectWorkspaceScreen = /^\/projects(?:\/[^/]+)?$/.test(location.pathname)
const resolvedItems: BreadcrumbItem[] = React.useMemo(() => {
if (items && items.length > 0) return items
@ -38,7 +42,7 @@ export const Breadcrumb: React.FC<BreadcrumbProps> = ({ items }) => {
const projName = PROJECT_NAMES[parts[1]] || 'Giao thông đô thị'
list.push({ label: projName, to: `/projects/${parts[1]}` })
if (parts[2] === 'annotate') {
list.push({ label: 'Gán nhãn' })
list.push({ label: 'Người gán nhãn' })
} else {
list.push({ label: 'Tổng quan' })
}
@ -53,10 +57,10 @@ export const Breadcrumb: React.FC<BreadcrumbProps> = ({ items }) => {
return (
<nav className="flex items-center gap-2 text-xs text-slate-500">
{location.pathname === '/projects' ? (
{isProjectWorkspaceScreen ? (
<img className="h-4 w-4 shrink-0" src="/assets/projects-ui/folder-open.svg" alt="" />
) : <svg
className={`h-4 w-4 shrink-0 ${location.pathname === '/projects' ? 'text-[#697386]' : 'text-slate-400'}`}
className="h-4 w-4 shrink-0 text-slate-400"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"

View file

@ -1,7 +1,6 @@
import React, { useEffect } from 'react'
import { useParams, useSearchParams } from 'react-router-dom'
import { useParams } from 'react-router-dom'
import toast from 'react-hot-toast'
import { TaskType } from '@/types'
import { useAnnotatorStore } from './annotatorStore'
import { AnnotatorHeader } from './components/header/AnnotatorHeader'
import { ImageInfo } from './components/header/ImageInfo'
@ -15,15 +14,13 @@ import { SegmentationPanel } from './components/sidebar-right/SegmentationPanel'
export const AnnotatorPage: React.FC = () => {
const { id } = useParams<{ id: string }>()
const [searchParams] = useSearchParams()
const taskParam = searchParams.get('task') as TaskType | null
const project = useAnnotatorStore((s) => s.project)
const initProject = useAnnotatorStore((s) => s.initProject)
useEffect(() => {
initProject(id ?? 'proj-1', taskParam ?? undefined)
}, [id, taskParam, initProject])
initProject(id ?? 'urban_vehicles_v2')
}, [id, initProject])
// Global keyboard shortcuts for fast annotation
useEffect(() => {
@ -131,16 +128,16 @@ export const AnnotatorPage: React.FC = () => {
}, [])
return (
<div className="space-y-2">
<div className="min-h-full space-y-4 p-6">
{/* Top Project Title & Action Buttons */}
<AnnotatorHeader />
{/* Main 2-Column Workspace */}
<div className="grid grid-cols-1 gap-4 lg:grid-cols-12 items-start">
<div className="grid grid-cols-1 items-start gap-4 xl:grid-cols-[minmax(0,2.92fr)_minmax(280px,1fr)]">
{/* Left Column: Image Info + Toolbar + Canvas + Navigator */}
<div className="overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-2xs lg:col-span-8 xl:col-span-9">
<div className="min-w-0 overflow-hidden rounded-xl border border-[#e4e7ef] bg-white shadow-none">
{/* File Name, Resolution & Image Counter Bar */}
<div className="flex items-center justify-between border-b border-slate-100 px-4 py-2.5">
<div className="flex h-[46px] items-center justify-between border-b border-[#e4e7ef] px-4">
<ImageInfo />
<ImageCounter />
</div>
@ -156,7 +153,7 @@ export const AnnotatorPage: React.FC = () => {
</div>
{/* Right Column: Task-Specific Panel */}
<div className="lg:col-span-4 xl:col-span-3">
<div className="min-w-0">
{project.taskType === 'classification' && <ClassificationPanel />}
{project.taskType === 'object_detection' && <ObjectListPanel />}
{project.taskType === 'segmentation' && <SegmentationPanel />}

View file

@ -10,6 +10,7 @@ import {
Project,
TaskType,
} from '@/types'
import { getAnnotatorImageUrl } from './annotatorTheme'
import { normalizeBBox } from '@/utils/canvas'
// Generate crisp SVG data URLs so the street scenes and objects align pixel-for-pixel with annotations
@ -195,9 +196,9 @@ export const DEFAULT_CLASSES: LabelClass[] = [
{ id: 'cls-truck', name: 'Xe tải', color: '#3B82F6', count: 0, shortcutKey: '4' },
]
export const ANNOTATOR_PROJECTS: Record<string, Project> = {
'proj-1': {
id: 'proj-1',
export const ANNOTATOR_PROJECTS_BY_ID: Record<string, Project> = {
urban_vehicles_v2: {
id: 'urban_vehicles_v2',
name: 'Phương tiện đô thị',
slug: 'urban_vehicles_v2',
description: 'Phân loại phương tiện giao thông đô thị trên đường phố Việt Nam.',
@ -218,8 +219,8 @@ export const ANNOTATOR_PROJECTS: Record<string, Project> = {
{ id: 'u-2', name: 'Thu Hà', initials: 'TH', color: '#6366F1', role: 'reviewer', assignedCount: 1200 },
],
},
'proj-2': {
id: 'proj-2',
traffic_camera_v2: {
id: 'traffic_camera_v2',
name: 'Giao thông đô thị',
slug: 'traffic_camera_v2',
description: 'Khoanh vùng hộp giới hạn các phương tiện giao thông từ camera giám sát.',
@ -241,8 +242,8 @@ export const ANNOTATOR_PROJECTS: Record<string, Project> = {
{ id: 'u-2', name: 'Thu Hà', initials: 'TH', color: '#6366F1', role: 'reviewer', assignedCount: 640 },
],
},
'proj-3': {
id: 'proj-3',
street_masks_v1: {
id: 'street_masks_v1',
name: 'Phân vùng đường phố',
slug: 'street_masks_v1',
description: 'Phân vùng đa giác chi tiết phương tiện giao thông phục vụ xe tự hành.',
@ -410,21 +411,18 @@ function getInitialSegmentationShapes(): AnnotationShape[] {
}
export function getImagesForProject(projectId: string, taskType: TaskType): ImageItem[] {
const sedanSvg = createClassificationSedanSvg('29A-888.88')
const trafficSvg1 = createTrafficBoulevardSvg(1)
const trafficSvg2 = createTrafficBoulevardSvg(2)
const truckSvg = createTruckStreetSvg()
const designImageNames = ['nh-d-li-u.jpg', 'nh.jpg', 'nh-2.jpg', 'nh.jpg', 'nh-3.jpg', 'nh-d-li-u.jpg']
const imageUrls = designImageNames.map((fileName) => getAnnotatorImageUrl(taskType, fileName))
if (taskType === 'classification') {
const baseNums = [124, 125, 126, 127, 128, 129]
const urls = [sedanSvg, trafficSvg1, sedanSvg, trafficSvg2, truckSvg, trafficSvg1]
const defaultLabels = ['cls-car', 'cls-bus', 'cls-car', 'cls-motorbike', 'cls-truck', 'cls-bus']
return baseNums.map((num, idx) => ({
id: `${projectId}-img-${num}`,
projectId,
fileName: `urban_00${num}.jpg`,
url: urls[idx] ?? sedanSvg,
thumbnailUrl: urls[idx] ?? sedanSvg,
url: imageUrls[idx]!,
thumbnailUrl: imageUrls[idx]!,
width: 1920,
height: 1080,
status: 'pending_review',
@ -444,7 +442,6 @@ export function getImagesForProject(projectId: string, taskType: TaskType): Imag
const prefix = taskType === 'object_detection' ? 'traffic' : 'street'
const baseNums = [321, 322, 323, 324, 325, 326]
const urls = [trafficSvg1, trafficSvg2, sedanSvg, trafficSvg1, truckSvg, trafficSvg2]
const defaultStatus: ImageAnnotationStatus =
taskType === 'object_detection' ? 'pending_review' : 'in_progress'
@ -452,8 +449,8 @@ export function getImagesForProject(projectId: string, taskType: TaskType): Imag
id: `${projectId}-img-${num}`,
projectId,
fileName: `${prefix}_00${num}.jpg`,
url: urls[idx] ?? trafficSvg1,
thumbnailUrl: urls[idx] ?? trafficSvg1,
url: imageUrls[idx]!,
thumbnailUrl: imageUrls[idx]!,
width: 1920,
height: 1080,
status: defaultStatus,
@ -499,8 +496,7 @@ export interface AnnotatorState {
historyFuture: HistorySnapshot[]
// Actions
initProject: (projectIdOrTask: string, taskOverride?: TaskType) => void
switchTaskMode: (taskType: TaskType) => void
initProject: (projectId: string) => void
selectImageByIndex: (index: number) => void
nextImage: () => void
prevImage: () => void
@ -547,7 +543,7 @@ function getCurrentTimeHHMM(): string {
return `${hh}:${mm}`
}
function buildInitialStoreData(project: Project) {
function createInitialAnnotationState(project: Project) {
const images = getImagesForProject(project.id, project.taskType)
const shapesByImageId: Record<string, AnnotationShape[]> = {}
const classificationByImageId: Record<string, string> = {}
@ -615,38 +611,12 @@ function buildInitialStoreData(project: Project) {
}
export const useAnnotatorStore = create<AnnotatorState>((set, get) => ({
...buildInitialStoreData(ANNOTATOR_PROJECTS['proj-1']!),
...createInitialAnnotationState(ANNOTATOR_PROJECTS_BY_ID.urban_vehicles_v2!),
initProject: (projectIdOrTask, taskOverride) => {
let matchedProject = ANNOTATOR_PROJECTS[projectIdOrTask]
if (!matchedProject) {
if (projectIdOrTask.includes('2') || taskOverride === 'object_detection') {
matchedProject = ANNOTATOR_PROJECTS['proj-2']
} else if (projectIdOrTask.includes('3') || taskOverride === 'segmentation') {
matchedProject = ANNOTATOR_PROJECTS['proj-3']
} else {
matchedProject = ANNOTATOR_PROJECTS['proj-1']
}
}
if (taskOverride && matchedProject && matchedProject.taskType !== taskOverride) {
if (taskOverride === 'classification') matchedProject = ANNOTATOR_PROJECTS['proj-1']
if (taskOverride === 'object_detection') matchedProject = ANNOTATOR_PROJECTS['proj-2']
if (taskOverride === 'segmentation') matchedProject = ANNOTATOR_PROJECTS['proj-3']
}
set(buildInitialStoreData(matchedProject ?? ANNOTATOR_PROJECTS['proj-1']!))
},
switchTaskMode: (taskType) => {
const targetProject =
taskType === 'classification'
? ANNOTATOR_PROJECTS['proj-1']!
: taskType === 'object_detection'
? ANNOTATOR_PROJECTS['proj-2']!
: ANNOTATOR_PROJECTS['proj-3']!
set(buildInitialStoreData(targetProject))
initProject: (projectId) => {
const selectedProject =
ANNOTATOR_PROJECTS_BY_ID[projectId] ?? ANNOTATOR_PROJECTS_BY_ID.urban_vehicles_v2!
set(createInitialAnnotationState(selectedProject))
},
selectImageByIndex: (index) => {

View file

@ -0,0 +1,22 @@
import { TaskType } from '@/types'
/** Colors used by the annotation workspace and its active controls. */
export const ANNOTATOR_COLORS = {
brand: '#c75c4a',
brandHover: '#b94f3e',
selection: '#5451d6',
selectionSoft: '#f5ded6',
border: '#e4e7ef',
canvas: '#f5f6fa',
} as const
/** Image folders copied from each matching Figma annotation screen. */
export const ANNOTATOR_IMAGE_DIRECTORIES: Record<TaskType, string> = {
classification: '/assets/annotators/classification',
object_detection: '/assets/annotators/object-detection',
segmentation: '/assets/annotators/segmentation',
}
export function getAnnotatorImageUrl(taskType: TaskType, fileName: string): string {
return `${ANNOTATOR_IMAGE_DIRECTORIES[taskType]}/${fileName}`
}

View file

@ -211,7 +211,7 @@ export const AnnotationCanvas: React.FC = () => {
<svg
ref={svgRef}
viewBox={`0 0 ${currentImage.width} ${currentImage.height}`}
className="block aspect-video w-full select-none"
className="block aspect-[1.925] w-full select-none"
style={{
cursor:
activeTool === 'bbox' || activeTool === 'polygon' || activeTool === 'point'

View file

@ -4,6 +4,7 @@ import { AnnotationTool } from '@/types'
import { useAnnotatorStore } from '../../annotatorStore'
import { UndoRedoButtons } from '../header/UndoRedoButtons'
import { ZoomControls } from './ZoomControls'
import { ANNOTATOR_COLORS } from '../../annotatorTheme'
export const ToolBar: React.FC = () => {
const taskType = useAnnotatorStore((s) => s.project.taskType)
@ -66,7 +67,7 @@ export const ToolBar: React.FC = () => {
]
return (
<div className="flex items-center justify-between border-b border-slate-100 px-4 py-2">
<div className="flex h-11 items-center justify-between border-b border-[#e4e7ef] bg-[#fafbfd] px-3">
<div className="flex items-center gap-1.5">
{tools.map((tool) => {
const isActive = activeTool === tool.id
@ -80,11 +81,12 @@ export const ToolBar: React.FC = () => {
className={clsx(
'inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors',
isActive
? 'bg-[#FDECE7] text-[#4F46E5] font-semibold'
? 'font-semibold'
: tool.enabled
? 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
: 'cursor-not-allowed text-slate-300'
)}
style={isActive ? { backgroundColor: ANNOTATOR_COLORS.selectionSoft, color: ANNOTATOR_COLORS.selection } : undefined}
>
{tool.icon}
<span>{tool.label}</span>

View file

@ -1,7 +1,5 @@
import React from 'react'
import { useNavigate } from 'react-router-dom'
import clsx from 'clsx'
import { TaskType } from '@/types'
import { TASK_TYPE_LABELS } from '@/app/constants'
import { formatNumber } from '@/utils/format'
import { useAnnotatorStore } from '../../annotatorStore'
@ -10,62 +8,32 @@ import { SaveAndNextButton } from './SaveAndNextButton'
export const AnnotatorHeader: React.FC = () => {
const navigate = useNavigate()
const project = useAnnotatorStore((s) => s.project)
const switchTaskMode = useAnnotatorStore((s) => s.switchTaskMode)
const taskOptions: { type: TaskType; label: string }[] = [
{ type: 'classification', label: 'Classification' },
{ type: 'object_detection', label: 'Object Detection' },
{ type: 'segmentation', label: 'Segmentation' },
]
const project = useAnnotatorStore((state) => state.project)
return (
<div className="flex flex-wrap items-center justify-between gap-4 pb-3">
<section className="flex flex-wrap items-center justify-between gap-4 pb-1">
<div>
<div className="flex items-center gap-3">
<h1 className="text-2xl font-bold tracking-tight text-slate-900">
{project.name}
</h1>
{/* Quick Task Switcher Pill Bar so user can test all 3 Annotator modes effortlessly */}
<div className="hidden items-center gap-1 rounded-xl border border-slate-200 bg-white p-0.5 shadow-2xs sm:inline-flex">
{taskOptions.map((opt) => {
const active = project.taskType === opt.type
return (
<button
key={opt.type}
type="button"
onClick={() => switchTaskMode(opt.type)}
className={clsx(
'rounded-lg px-2.5 py-1 text-xs font-medium transition-colors',
active
? 'bg-[#FDF4F1] text-[#C95C3C] font-semibold'
: 'text-slate-500 hover:text-slate-800'
)}
>
{opt.label}
</button>
)
})}
</div>
</div>
<p className="mt-0.5 text-xs text-slate-500">
<h1 className="text-[27px] font-medium tracking-[-1px] text-[#172033]">
{project.name}
</h1>
<p className="mt-1 text-xs text-[#697386]">
{TASK_TYPE_LABELS[project.taskType]} · {project.slug} ·{' '}
{formatNumber(project.stats.totalImages)} ảnh
</p>
</div>
<div className="flex items-center gap-2.5">
<div className="flex items-center gap-2">
<button
type="button"
onClick={() => navigate(`/projects/${project.id}`)}
className="inline-flex items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm font-medium text-slate-700 shadow-2xs transition-colors hover:bg-slate-50"
className="inline-flex h-10 items-center gap-2 rounded-lg border border-[#e4e7ef] bg-white px-4 text-[13px] font-semibold text-[#172033] transition-colors hover:bg-slate-50"
>
<span>←</span>
<span aria-hidden="true">←</span>
<span>Về tổng quan</span>
</button>
<SaveButton />
<SaveAndNextButton />
</div>
</div>
</section>
)
}

View file

@ -1,6 +1,7 @@
import React from 'react'
import toast from 'react-hot-toast'
import { useAnnotatorStore } from '../../annotatorStore'
import { ANNOTATOR_COLORS } from '../../annotatorTheme'
export const SaveAndNextButton: React.FC = () => {
const saveAndNext = useAnnotatorStore((s) => s.saveAndNext)
@ -16,7 +17,10 @@ export const SaveAndNextButton: React.FC = () => {
<button
type="button"
onClick={handleSaveAndNext}
className="inline-flex items-center gap-2 rounded-xl bg-[#C95C3C] px-4 py-2 text-sm font-medium text-white shadow-sm transition-colors hover:bg-[#B5492B] focus:outline-none focus:ring-2 focus:ring-[#C95C3C]/30"
className="inline-flex h-10 items-center gap-2 rounded-lg bg-[#c75c4a] px-4 text-[13px] font-semibold text-white transition-colors hover:bg-[#b94f3e] focus:outline-none focus:ring-2 focus:ring-[#c75c4a]/30"
style={{ backgroundColor: ANNOTATOR_COLORS.brand }}
onMouseEnter={(event) => { event.currentTarget.style.backgroundColor = ANNOTATOR_COLORS.brandHover }}
onMouseLeave={(event) => { event.currentTarget.style.backgroundColor = ANNOTATOR_COLORS.brand }}
>
<span>→</span>
<span>Lưu &amp; ảnh tiếp</span>

View file

@ -1,6 +1,7 @@
import React from 'react'
import toast from 'react-hot-toast'
import { useAnnotatorStore } from '../../annotatorStore'
import { ANNOTATOR_COLORS } from '../../annotatorTheme'
export const SaveButton: React.FC = () => {
const saveCurrentAnnotation = useAnnotatorStore((s) => s.saveCurrentAnnotation)
@ -15,7 +16,10 @@ export const SaveButton: React.FC = () => {
<button
type="button"
onClick={handleSave}
className="inline-flex items-center gap-2 rounded-xl bg-[#C95C3C] px-4 py-2 text-sm font-medium text-white shadow-sm transition-colors hover:bg-[#B5492B] focus:outline-none focus:ring-2 focus:ring-[#C95C3C]/30"
className="inline-flex h-10 items-center gap-2 rounded-lg bg-[#c75c4a] px-4 text-[13px] font-semibold text-white transition-colors hover:bg-[#b94f3e] focus:outline-none focus:ring-2 focus:ring-[#c75c4a]/30"
style={{ backgroundColor: ANNOTATOR_COLORS.brand }}
onMouseEnter={(event) => { event.currentTarget.style.backgroundColor = ANNOTATOR_COLORS.brandHover }}
onMouseLeave={(event) => { event.currentTarget.style.backgroundColor = ANNOTATOR_COLORS.brand }}
>
<svg
className="h-4 w-4 text-white/90"

View file

@ -1,6 +1,7 @@
import React from 'react'
import clsx from 'clsx'
import { useAnnotatorStore } from '../../annotatorStore'
import { ANNOTATOR_COLORS } from '../../annotatorTheme'
export const ThumbnailStrip: React.FC = () => {
const images = useAnnotatorStore((s) => s.images)
@ -25,9 +26,10 @@ export const ThumbnailStrip: React.FC = () => {
className={clsx(
'relative aspect-video w-full overflow-hidden rounded-lg border-2 transition-all',
isActive
? 'border-[#4F46E5] shadow-xs'
? 'shadow-xs'
: 'border-transparent opacity-85 hover:opacity-100'
)}
style={isActive ? { borderColor: ANNOTATOR_COLORS.selection } : undefined}
>
<img
src={img.thumbnailUrl}
@ -40,9 +42,10 @@ export const ThumbnailStrip: React.FC = () => {
className={clsx(
'font-mono text-[10px] transition-colors',
isActive
? 'font-semibold text-[#4F46E5]'
? 'font-semibold'
: 'text-slate-400 group-hover:text-slate-600'
)}
style={isActive ? { color: ANNOTATOR_COLORS.selection } : undefined}
>
{shortName}
</span>