feat: scaffold complete danable frontend architecture with all pages, layouts, stores, and 3 annotator modes
This commit is contained in:
commit
78848dd7d1
173 changed files with 18649 additions and 0 deletions
167
src/pages/annotator/AnnotatorPage.tsx
Normal file
167
src/pages/annotator/AnnotatorPage.tsx
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
import React, { useEffect } from 'react'
|
||||
import { useParams, useSearchParams } 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'
|
||||
import { ToolBar } from './components/canvas/ToolBar'
|
||||
import { AnnotationCanvas } from './components/canvas/AnnotationCanvas'
|
||||
import { ImageCounter } from './components/navigator/ImageCounter'
|
||||
import { ImageNavigator } from './components/navigator/ImageNavigator'
|
||||
import { ClassificationPanel } from './components/sidebar-right/ClassificationPanel'
|
||||
import { ObjectListPanel } from './components/sidebar-right/ObjectListPanel'
|
||||
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])
|
||||
|
||||
// Global keyboard shortcuts for fast annotation
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
const target = e.target as HTMLElement | null
|
||||
if (
|
||||
target &&
|
||||
(target.tagName === 'INPUT' ||
|
||||
target.tagName === 'TEXTAREA' ||
|
||||
target.tagName === 'SELECT')
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const state = useAnnotatorStore.getState()
|
||||
|
||||
// Undo / Redo
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'z') {
|
||||
e.preventDefault()
|
||||
if (e.shiftKey) {
|
||||
state.redo()
|
||||
} else {
|
||||
state.undo()
|
||||
}
|
||||
return
|
||||
}
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'y') {
|
||||
e.preventDefault()
|
||||
state.redo()
|
||||
return
|
||||
}
|
||||
|
||||
// 1-4 class selection
|
||||
if (['1', '2', '3', '4'].includes(e.key)) {
|
||||
const idx = Number(e.key) - 1
|
||||
const cls = state.project.classes[idx]
|
||||
if (cls) {
|
||||
if (state.project.taskType === 'classification') {
|
||||
state.setClassificationLabel(cls.id)
|
||||
} else {
|
||||
state.updateSelectedShapeClass(cls.id)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Tool shortcuts
|
||||
const keyLower = e.key.toLowerCase()
|
||||
if (keyLower === 'v') {
|
||||
state.setActiveTool('select')
|
||||
return
|
||||
}
|
||||
if (keyLower === 'b' && state.project.taskType === 'object_detection') {
|
||||
state.setActiveTool('bbox')
|
||||
return
|
||||
}
|
||||
if (keyLower === 'p' && state.project.taskType === 'segmentation') {
|
||||
state.setActiveTool('polygon')
|
||||
return
|
||||
}
|
||||
|
||||
// Enter: close draft polygon or approve classification
|
||||
if (e.key === 'Enter') {
|
||||
if (
|
||||
state.project.taskType === 'segmentation' &&
|
||||
state.draftPolygonPoints.length >= 3
|
||||
) {
|
||||
e.preventDefault()
|
||||
state.closeDraftPolygon()
|
||||
} else if (state.project.taskType === 'classification') {
|
||||
e.preventDefault()
|
||||
state.updateImageStatus('completed')
|
||||
toast.success('Đã duyệt nhãn ảnh hiện tại')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Escape: cancel draft polygon
|
||||
if (e.key === 'Escape' && state.draftPolygonPoints.length > 0) {
|
||||
state.cancelDraftPolygon()
|
||||
return
|
||||
}
|
||||
|
||||
// Delete / Backspace: remove selected shape
|
||||
if (
|
||||
(e.key === 'Delete' || e.key === 'Backspace') &&
|
||||
state.selectedShapeId &&
|
||||
state.project.taskType !== 'classification'
|
||||
) {
|
||||
e.preventDefault()
|
||||
state.deleteShape(state.selectedShapeId)
|
||||
return
|
||||
}
|
||||
|
||||
// Left / Right arrow keys: navigate images
|
||||
if (e.key === 'ArrowLeft') {
|
||||
state.prevImage()
|
||||
} else if (e.key === 'ArrowRight') {
|
||||
state.nextImage()
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('keydown', handleKeyDown)
|
||||
return () => window.removeEventListener('keydown', handleKeyDown)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{/* Top Project Title & Action Buttons */}
|
||||
<AnnotatorHeader />
|
||||
|
||||
{/* Main 2-Column Workspace */}
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-12 items-start">
|
||||
{/* 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">
|
||||
{/* File Name, Resolution & Image Counter Bar */}
|
||||
<div className="flex items-center justify-between border-b border-slate-100 px-4 py-2.5">
|
||||
<ImageInfo />
|
||||
<ImageCounter />
|
||||
</div>
|
||||
|
||||
{/* Annotation Tools & Zoom Controls */}
|
||||
<ToolBar />
|
||||
|
||||
{/* Interactive SVG + Image Canvas */}
|
||||
<AnnotationCanvas />
|
||||
|
||||
{/* Bottom Hint, Thumbnail Strip & Save/Export Status */}
|
||||
<ImageNavigator />
|
||||
</div>
|
||||
|
||||
{/* Right Column: Task-Specific Panel */}
|
||||
<div className="lg:col-span-4 xl:col-span-3">
|
||||
{project.taskType === 'classification' && <ClassificationPanel />}
|
||||
{project.taskType === 'object_detection' && <ObjectListPanel />}
|
||||
{project.taskType === 'segmentation' && <SegmentationPanel />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
1174
src/pages/annotator/annotatorStore.ts
Normal file
1174
src/pages/annotator/annotatorStore.ts
Normal file
File diff suppressed because it is too large
Load diff
303
src/pages/annotator/components/canvas/AnnotationCanvas.tsx
Normal file
303
src/pages/annotator/components/canvas/AnnotationCanvas.tsx
Normal file
|
|
@ -0,0 +1,303 @@
|
|||
import React, { useRef, useState } from 'react'
|
||||
import { AnnotationShape, BoundingBox, Point2D } from '@/types'
|
||||
import { normalizeBBox } from '@/utils/canvas'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { ImageViewer } from './ImageViewer'
|
||||
import { BoundingBoxTool, ResizeHandleCorner } from './BoundingBoxTool'
|
||||
import { PolygonTool } from './PolygonTool'
|
||||
import { PointTool } from './PointTool'
|
||||
import { SelectTool } from './SelectTool'
|
||||
import { CanvasOverlay } from './CanvasOverlay'
|
||||
|
||||
type DragInteraction =
|
||||
| { type: 'draw-bbox'; start: Point2D; current: Point2D }
|
||||
| { type: 'move-bbox'; shapeId: string; startMouse: Point2D; initialBox: BoundingBox }
|
||||
| {
|
||||
type: 'resize-bbox'
|
||||
shapeId: string
|
||||
corner: ResizeHandleCorner
|
||||
startMouse: Point2D
|
||||
initialBox: BoundingBox
|
||||
}
|
||||
| { type: 'drag-vertex'; shapeId: string; vertexIndex: number }
|
||||
|
||||
export const AnnotationCanvas: React.FC = () => {
|
||||
const svgRef = useRef<SVGSVGElement | null>(null)
|
||||
|
||||
const project = useAnnotatorStore((s) => s.project)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const activeTool = useAnnotatorStore((s) => s.activeTool)
|
||||
const selectedClassId = useAnnotatorStore((s) => s.selectedClassId)
|
||||
const selectedShapeId = useAnnotatorStore((s) => s.selectedShapeId)
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const showBoxes = useAnnotatorStore((s) => s.showBoxes)
|
||||
const showMasks = useAnnotatorStore((s) => s.showMasks)
|
||||
const maskOpacity = useAnnotatorStore((s) => s.maskOpacity)
|
||||
const vertexEditEnabled = useAnnotatorStore((s) => s.vertexEditEnabled)
|
||||
const zoom = useAnnotatorStore((s) => s.zoom)
|
||||
const draftPolygonPoints = useAnnotatorStore((s) => s.draftPolygonPoints)
|
||||
|
||||
const setSelectedShapeId = useAnnotatorStore((s) => s.setSelectedShapeId)
|
||||
const addBoundingBox = useAnnotatorStore((s) => s.addBoundingBox)
|
||||
const updateBoundingBox = useAnnotatorStore((s) => s.updateBoundingBox)
|
||||
const addDraftPolygonPoint = useAnnotatorStore((s) => s.addDraftPolygonPoint)
|
||||
const closeDraftPolygon = useAnnotatorStore((s) => s.closeDraftPolygon)
|
||||
const updatePolygonVertex = useAnnotatorStore((s) => s.updatePolygonVertex)
|
||||
const insertPolygonVertex = useAnnotatorStore((s) => s.insertPolygonVertex)
|
||||
const addPointShape = useAnnotatorStore((s) => s.addPointShape)
|
||||
|
||||
const [interaction, setInteraction] = useState<DragInteraction | null>(null)
|
||||
const [cursorPoint, setCursorPoint] = useState<Point2D | null>(null)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const shapes = shapesByImageId[currentImage.id] ?? []
|
||||
const selectedShape = shapes.find((s) => s.id === selectedShapeId)
|
||||
const activeClass =
|
||||
project.classes.find((c) => c.id === selectedClassId) ?? project.classes[0]!
|
||||
|
||||
// Convert client mouse position to 1920x1080 SVG coordinate space
|
||||
const getSvgPoint = (e: React.MouseEvent): Point2D => {
|
||||
const svg = svgRef.current
|
||||
if (!svg) return { x: 0, y: 0 }
|
||||
const rect = svg.getBoundingClientRect()
|
||||
if (rect.width === 0 || rect.height === 0) return { x: 0, y: 0 }
|
||||
const scaleX = currentImage.width / rect.width
|
||||
const scaleY = currentImage.height / rect.height
|
||||
return {
|
||||
x: Math.max(0, Math.min(currentImage.width, (e.clientX - rect.left) * scaleX)),
|
||||
y: Math.max(0, Math.min(currentImage.height, (e.clientY - rect.top) * scaleY)),
|
||||
}
|
||||
}
|
||||
|
||||
const handleCanvasMouseDown = (e: React.MouseEvent) => {
|
||||
if (e.button !== 0) return
|
||||
const pt = getSvgPoint(e)
|
||||
|
||||
if (project.taskType === 'object_detection' && activeTool === 'bbox') {
|
||||
setInteraction({ type: 'draw-bbox', start: pt, current: pt })
|
||||
return
|
||||
}
|
||||
|
||||
if (project.taskType === 'segmentation' && activeTool === 'polygon') {
|
||||
addDraftPolygonPoint(pt)
|
||||
return
|
||||
}
|
||||
|
||||
if (activeTool === 'point' && project.taskType !== 'classification') {
|
||||
addPointShape(pt)
|
||||
return
|
||||
}
|
||||
|
||||
if (activeTool === 'select') {
|
||||
setSelectedShapeId(null)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCanvasMouseMove = (e: React.MouseEvent) => {
|
||||
const pt = getSvgPoint(e)
|
||||
if (draftPolygonPoints.length > 0) {
|
||||
setCursorPoint(pt)
|
||||
}
|
||||
|
||||
if (!interaction) return
|
||||
|
||||
if (interaction.type === 'draw-bbox') {
|
||||
setInteraction({ ...interaction, current: pt })
|
||||
return
|
||||
}
|
||||
|
||||
if (interaction.type === 'move-bbox') {
|
||||
const dx = pt.x - interaction.startMouse.x
|
||||
const dy = pt.y - interaction.startMouse.y
|
||||
updateBoundingBox(interaction.shapeId, {
|
||||
x: interaction.initialBox.x + dx,
|
||||
y: interaction.initialBox.y + dy,
|
||||
width: interaction.initialBox.width,
|
||||
height: interaction.initialBox.height,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (interaction.type === 'resize-bbox') {
|
||||
const { initialBox, corner, startMouse } = interaction
|
||||
const dx = pt.x - startMouse.x
|
||||
const dy = pt.y - startMouse.y
|
||||
|
||||
let newBox: BoundingBox = { ...initialBox }
|
||||
if (corner === 'nw') {
|
||||
newBox = {
|
||||
x: initialBox.x + dx,
|
||||
y: initialBox.y + dy,
|
||||
width: initialBox.width - dx,
|
||||
height: initialBox.height - dy,
|
||||
}
|
||||
} else if (corner === 'ne') {
|
||||
newBox = {
|
||||
x: initialBox.x,
|
||||
y: initialBox.y + dy,
|
||||
width: initialBox.width + dx,
|
||||
height: initialBox.height - dy,
|
||||
}
|
||||
} else if (corner === 'sw') {
|
||||
newBox = {
|
||||
x: initialBox.x + dx,
|
||||
y: initialBox.y,
|
||||
width: initialBox.width - dx,
|
||||
height: initialBox.height + dy,
|
||||
}
|
||||
} else if (corner === 'se') {
|
||||
newBox = {
|
||||
x: initialBox.x,
|
||||
y: initialBox.y,
|
||||
width: initialBox.width + dx,
|
||||
height: initialBox.height + dy,
|
||||
}
|
||||
}
|
||||
updateBoundingBox(interaction.shapeId, newBox)
|
||||
return
|
||||
}
|
||||
|
||||
if (interaction.type === 'drag-vertex') {
|
||||
updatePolygonVertex(interaction.shapeId, interaction.vertexIndex, pt)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCanvasMouseUp = () => {
|
||||
if (!interaction) return
|
||||
if (interaction.type === 'draw-bbox') {
|
||||
const rawBox: BoundingBox = {
|
||||
x: interaction.start.x,
|
||||
y: interaction.start.y,
|
||||
width: interaction.current.x - interaction.start.x,
|
||||
height: interaction.current.y - interaction.start.y,
|
||||
}
|
||||
addBoundingBox(rawBox)
|
||||
}
|
||||
setInteraction(null)
|
||||
}
|
||||
|
||||
const handleDoubleClick = () => {
|
||||
if (project.taskType === 'segmentation' && draftPolygonPoints.length >= 3) {
|
||||
closeDraftPolygon()
|
||||
}
|
||||
}
|
||||
|
||||
const draftBox =
|
||||
interaction?.type === 'draw-bbox'
|
||||
? normalizeBBox(
|
||||
{
|
||||
x: interaction.start.x,
|
||||
y: interaction.start.y,
|
||||
width: interaction.current.x - interaction.start.x,
|
||||
height: interaction.current.y - interaction.start.y,
|
||||
},
|
||||
currentImage.width,
|
||||
currentImage.height
|
||||
)
|
||||
: null
|
||||
|
||||
const scaleFactor = zoom / 75
|
||||
|
||||
return (
|
||||
<div className="px-4 py-3">
|
||||
<div className="relative overflow-hidden rounded-xl border border-slate-200/80 bg-slate-900">
|
||||
<div
|
||||
className="w-full origin-center transition-transform duration-150"
|
||||
style={{
|
||||
transform: scaleFactor !== 1 ? `scale(${scaleFactor})` : undefined,
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
ref={svgRef}
|
||||
viewBox={`0 0 ${currentImage.width} ${currentImage.height}`}
|
||||
className="block aspect-video w-full select-none"
|
||||
style={{
|
||||
cursor:
|
||||
activeTool === 'bbox' || activeTool === 'polygon' || activeTool === 'point'
|
||||
? 'crosshair'
|
||||
: 'default',
|
||||
}}
|
||||
onMouseDown={handleCanvasMouseDown}
|
||||
onMouseMove={handleCanvasMouseMove}
|
||||
onMouseUp={handleCanvasMouseUp}
|
||||
onDoubleClick={handleDoubleClick}
|
||||
>
|
||||
<ImageViewer
|
||||
url={currentImage.url}
|
||||
width={currentImage.width}
|
||||
height={currentImage.height}
|
||||
/>
|
||||
|
||||
{project.taskType === 'object_detection' && (
|
||||
<BoundingBoxTool
|
||||
shapes={shapes}
|
||||
selectedShapeId={selectedShapeId}
|
||||
showBoxes={showBoxes}
|
||||
draftBox={draftBox}
|
||||
activeClassColor={activeClass.color}
|
||||
activeClassName={activeClass.name}
|
||||
onSelectShape={setSelectedShapeId}
|
||||
onStartMoveBox={(e, shape) => {
|
||||
if (!shape.bbox) return
|
||||
setInteraction({
|
||||
type: 'move-bbox',
|
||||
shapeId: shape.id,
|
||||
startMouse: getSvgPoint(e),
|
||||
initialBox: { ...shape.bbox },
|
||||
})
|
||||
}}
|
||||
onStartResizeBox={(e, shape, corner) => {
|
||||
if (!shape.bbox) return
|
||||
setInteraction({
|
||||
type: 'resize-bbox',
|
||||
shapeId: shape.id,
|
||||
corner,
|
||||
startMouse: getSvgPoint(e),
|
||||
initialBox: { ...shape.bbox },
|
||||
})
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{project.taskType === 'segmentation' && (
|
||||
<PolygonTool
|
||||
shapes={shapes}
|
||||
selectedShapeId={selectedShapeId}
|
||||
showMasks={showMasks}
|
||||
maskOpacity={maskOpacity}
|
||||
vertexEditEnabled={vertexEditEnabled}
|
||||
draftPolygonPoints={draftPolygonPoints}
|
||||
cursorPoint={cursorPoint}
|
||||
activeClassColor={activeClass.color}
|
||||
onSelectShape={setSelectedShapeId}
|
||||
onStartDragVertex={(_e, shapeId, vertexIndex) => {
|
||||
setInteraction({
|
||||
type: 'drag-vertex',
|
||||
shapeId,
|
||||
vertexIndex,
|
||||
})
|
||||
}}
|
||||
onInsertVertexOnEdge={(shapeId, afterIndex, pt) => {
|
||||
insertPolygonVertex(shapeId, afterIndex, pt)
|
||||
}}
|
||||
onCloseDraftPolygon={closeDraftPolygon}
|
||||
/>
|
||||
)}
|
||||
|
||||
<PointTool
|
||||
shapes={shapes}
|
||||
selectedShapeId={selectedShapeId}
|
||||
onSelectShape={setSelectedShapeId}
|
||||
/>
|
||||
|
||||
<SelectTool selectedShape={selectedShape} />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
{/* Bottom-left dark translucent pill overlay */}
|
||||
<CanvasOverlay />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
163
src/pages/annotator/components/canvas/BoundingBoxTool.tsx
Normal file
163
src/pages/annotator/components/canvas/BoundingBoxTool.tsx
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
import React from 'react'
|
||||
import { AnnotationShape, BoundingBox } from '@/types'
|
||||
|
||||
export type ResizeHandleCorner = 'nw' | 'ne' | 'sw' | 'se'
|
||||
|
||||
export interface BoundingBoxToolProps {
|
||||
shapes: AnnotationShape[]
|
||||
selectedShapeId: string | null
|
||||
showBoxes: boolean
|
||||
draftBox: BoundingBox | null
|
||||
activeClassColor: string
|
||||
activeClassName: string
|
||||
onSelectShape: (shapeId: string) => void
|
||||
onStartMoveBox: (e: React.MouseEvent, shape: AnnotationShape) => void
|
||||
onStartResizeBox: (
|
||||
e: React.MouseEvent,
|
||||
shape: AnnotationShape,
|
||||
corner: ResizeHandleCorner
|
||||
) => void
|
||||
}
|
||||
|
||||
export const BoundingBoxTool: React.FC<BoundingBoxToolProps> = ({
|
||||
shapes,
|
||||
selectedShapeId,
|
||||
showBoxes,
|
||||
draftBox,
|
||||
activeClassColor,
|
||||
activeClassName,
|
||||
onSelectShape,
|
||||
onStartMoveBox,
|
||||
onStartResizeBox,
|
||||
}) => {
|
||||
if (!showBoxes) return null
|
||||
|
||||
const bboxShapes = shapes.filter((s) => s.type === 'bbox' && s.visible && s.bbox)
|
||||
|
||||
return (
|
||||
<g>
|
||||
{bboxShapes.map((shape) => {
|
||||
const box = shape.bbox!
|
||||
const isSelected = shape.id === selectedShapeId
|
||||
const pillWidth = Math.max(82, shape.labelName.length * 14 + 24)
|
||||
const pillY = Math.max(4, box.y - 38)
|
||||
const isLightTag = shape.color === '#F59E0B' || shape.color === '#06B6D4'
|
||||
|
||||
const corners: { id: ResizeHandleCorner; cx: number; cy: number; cursor: string }[] = [
|
||||
{ id: 'nw', cx: box.x, cy: box.y, cursor: 'nwse-resize' },
|
||||
{ id: 'ne', cx: box.x + box.width, cy: box.y, cursor: 'nesw-resize' },
|
||||
{ id: 'sw', cx: box.x, cy: box.y + box.height, cursor: 'nesw-resize' },
|
||||
{ id: 'se', cx: box.x + box.width, cy: box.y + box.height, cursor: 'nwse-resize' },
|
||||
]
|
||||
|
||||
return (
|
||||
<g key={shape.id}>
|
||||
{/* Main Bounding Box Rectangle */}
|
||||
<rect
|
||||
x={box.x}
|
||||
y={box.y}
|
||||
width={box.width}
|
||||
height={box.height}
|
||||
fill={shape.color}
|
||||
fillOpacity={isSelected ? 0.14 : 0.05}
|
||||
stroke={shape.color}
|
||||
strokeWidth={isSelected ? 4 : 3}
|
||||
className="cursor-move"
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
onSelectShape(shape.id)
|
||||
onStartMoveBox(e, shape)
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Top-left Label Pill matching wireframe */}
|
||||
<g
|
||||
className="cursor-pointer"
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
onSelectShape(shape.id)
|
||||
}}
|
||||
>
|
||||
<rect
|
||||
x={box.x}
|
||||
y={pillY}
|
||||
width={pillWidth}
|
||||
height={32}
|
||||
rx={8}
|
||||
fill={shape.color}
|
||||
fillOpacity={0.92}
|
||||
/>
|
||||
<text
|
||||
x={box.x + pillWidth / 2}
|
||||
y={pillY + 21}
|
||||
fill={isLightTag ? '#0F172A' : '#FFFFFF'}
|
||||
fontSize={17}
|
||||
fontWeight="bold"
|
||||
textAnchor="middle"
|
||||
className="select-none"
|
||||
>
|
||||
{shape.labelName}
|
||||
</text>
|
||||
</g>
|
||||
|
||||
{/* Corner Resize Handles when Selected */}
|
||||
{isSelected &&
|
||||
corners.map((corner) => (
|
||||
<rect
|
||||
key={corner.id}
|
||||
x={corner.cx - 8}
|
||||
y={corner.cy - 8}
|
||||
width={16}
|
||||
height={16}
|
||||
rx={3}
|
||||
fill="#FFFFFF"
|
||||
stroke={shape.color}
|
||||
strokeWidth={3.5}
|
||||
style={{ cursor: corner.cursor }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
onStartResizeBox(e, shape, corner.id)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Active Draft Bounding Box while user drags */}
|
||||
{draftBox && draftBox.width > 4 && draftBox.height > 4 && (
|
||||
<g className="pointer-events-none">
|
||||
<rect
|
||||
x={draftBox.x}
|
||||
y={draftBox.y}
|
||||
width={draftBox.width}
|
||||
height={draftBox.height}
|
||||
fill={activeClassColor}
|
||||
fillOpacity={0.18}
|
||||
stroke={activeClassColor}
|
||||
strokeWidth={3.5}
|
||||
strokeDasharray="8 6"
|
||||
/>
|
||||
<rect
|
||||
x={draftBox.x}
|
||||
y={Math.max(4, draftBox.y - 34)}
|
||||
width={110}
|
||||
height={28}
|
||||
rx={6}
|
||||
fill={activeClassColor}
|
||||
/>
|
||||
<text
|
||||
x={draftBox.x + 55}
|
||||
y={Math.max(4, draftBox.y - 34) + 19}
|
||||
fill="#FFFFFF"
|
||||
fontSize={15}
|
||||
fontWeight="bold"
|
||||
textAnchor="middle"
|
||||
>
|
||||
{activeClassName}
|
||||
</text>
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
}
|
||||
54
src/pages/annotator/components/canvas/CanvasOverlay.tsx
Normal file
54
src/pages/annotator/components/canvas/CanvasOverlay.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const CanvasOverlay: React.FC = () => {
|
||||
const project = useAnnotatorStore((s) => s.project)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const classificationByImageId = useAnnotatorStore((s) => s.classificationByImageId)
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const selectedShapeId = useAnnotatorStore((s) => s.selectedShapeId)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const shapes = shapesByImageId[currentImage.id] ?? []
|
||||
const selectedShape = shapes.find((s) => s.id === selectedShapeId) ?? shapes[1] ?? shapes[0]
|
||||
|
||||
if (project.taskType === 'classification') {
|
||||
const classId = classificationByImageId[currentImage.id] ?? 'cls-car'
|
||||
const cls = project.classes.find((c) => c.id === classId) ?? project.classes[0]
|
||||
return (
|
||||
<div className="pointer-events-none absolute bottom-3 left-3 z-10 inline-flex items-center gap-2 rounded-lg bg-slate-900/80 px-3 py-1.5 text-xs font-medium text-white backdrop-blur-xs">
|
||||
<svg className="h-3.5 w-3.5 text-slate-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z" />
|
||||
<line x1="7" y1="7" x2="7.01" y2="7" />
|
||||
</svg>
|
||||
<span>Nhãn ảnh: {cls?.name ?? 'Ô tô'}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (project.taskType === 'object_detection') {
|
||||
return (
|
||||
<div className="pointer-events-none absolute bottom-3 left-3 z-10 inline-flex items-center gap-2 rounded-lg bg-slate-900/80 px-3 py-1.5 text-xs font-medium text-white backdrop-blur-xs">
|
||||
<svg className="h-3.5 w-3.5 text-slate-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
<span>{shapes.length} hộp giới hạn · Gán nhãn thủ công</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const vertexCount = selectedShape?.points?.length ?? 13
|
||||
const labelName = selectedShape?.labelName ?? 'Xe buýt'
|
||||
|
||||
return (
|
||||
<div className="pointer-events-none absolute bottom-3 left-3 z-10 inline-flex items-center gap-2 rounded-lg bg-slate-900/80 px-3 py-1.5 text-xs font-medium text-white backdrop-blur-xs">
|
||||
<svg className="h-3.5 w-3.5 text-slate-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polygon points="12 2 22 8.5 18 21 6 21 2 8.5 12 2" />
|
||||
</svg>
|
||||
<span>
|
||||
Polygon · {labelName} · {vertexCount} đỉnh
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
21
src/pages/annotator/components/canvas/ImageViewer.tsx
Normal file
21
src/pages/annotator/components/canvas/ImageViewer.tsx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import React from 'react'
|
||||
|
||||
export interface ImageViewerProps {
|
||||
url: string
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
|
||||
export const ImageViewer: React.FC<ImageViewerProps> = ({ url, width, height }) => {
|
||||
return (
|
||||
<image
|
||||
href={url}
|
||||
x={0}
|
||||
y={0}
|
||||
width={width}
|
||||
height={height}
|
||||
preserveAspectRatio="none"
|
||||
className="select-none pointer-events-none"
|
||||
/>
|
||||
)
|
||||
}
|
||||
64
src/pages/annotator/components/canvas/PointTool.tsx
Normal file
64
src/pages/annotator/components/canvas/PointTool.tsx
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import React from 'react'
|
||||
import { AnnotationShape } from '@/types'
|
||||
|
||||
export interface PointToolProps {
|
||||
shapes: AnnotationShape[]
|
||||
selectedShapeId: string | null
|
||||
onSelectShape: (shapeId: string) => void
|
||||
}
|
||||
|
||||
export const PointTool: React.FC<PointToolProps> = ({
|
||||
shapes,
|
||||
selectedShapeId,
|
||||
onSelectShape,
|
||||
}) => {
|
||||
const pointShapes = shapes.filter((s) => s.type === 'point' && s.visible && s.point)
|
||||
|
||||
return (
|
||||
<g>
|
||||
{pointShapes.map((shape) => {
|
||||
const pt = shape.point!
|
||||
const isSelected = shape.id === selectedShapeId
|
||||
return (
|
||||
<g
|
||||
key={shape.id}
|
||||
className="cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onSelectShape(shape.id)
|
||||
}}
|
||||
>
|
||||
<circle
|
||||
cx={pt.x}
|
||||
cy={pt.y}
|
||||
r={isSelected ? 12 : 9}
|
||||
fill={shape.color}
|
||||
fillOpacity={0.35}
|
||||
stroke="#FFFFFF"
|
||||
strokeWidth={3}
|
||||
/>
|
||||
<circle cx={pt.x} cy={pt.y} r={5} fill={shape.color} />
|
||||
<rect
|
||||
x={pt.x - 36}
|
||||
y={pt.y - 38}
|
||||
width={72}
|
||||
height={24}
|
||||
rx={6}
|
||||
fill={shape.color}
|
||||
/>
|
||||
<text
|
||||
x={pt.x}
|
||||
y={pt.y - 22}
|
||||
fill="#FFFFFF"
|
||||
fontSize={14}
|
||||
fontWeight="bold"
|
||||
textAnchor="middle"
|
||||
>
|
||||
{shape.labelName}
|
||||
</text>
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
</g>
|
||||
)
|
||||
}
|
||||
201
src/pages/annotator/components/canvas/PolygonTool.tsx
Normal file
201
src/pages/annotator/components/canvas/PolygonTool.tsx
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
import React from 'react'
|
||||
import { AnnotationShape, Point2D } from '@/types'
|
||||
|
||||
export interface PolygonToolProps {
|
||||
shapes: AnnotationShape[]
|
||||
selectedShapeId: string | null
|
||||
showMasks: boolean
|
||||
maskOpacity: number
|
||||
vertexEditEnabled: boolean
|
||||
draftPolygonPoints: Point2D[]
|
||||
cursorPoint: Point2D | null
|
||||
activeClassColor: string
|
||||
onSelectShape: (shapeId: string) => void
|
||||
onStartDragVertex: (
|
||||
e: React.MouseEvent,
|
||||
shapeId: string,
|
||||
vertexIndex: number
|
||||
) => void
|
||||
onInsertVertexOnEdge: (
|
||||
shapeId: string,
|
||||
afterIndex: number,
|
||||
pt: Point2D
|
||||
) => void
|
||||
onCloseDraftPolygon: () => void
|
||||
}
|
||||
|
||||
export const PolygonTool: React.FC<PolygonToolProps> = ({
|
||||
shapes,
|
||||
selectedShapeId,
|
||||
showMasks,
|
||||
maskOpacity,
|
||||
vertexEditEnabled,
|
||||
draftPolygonPoints,
|
||||
cursorPoint,
|
||||
activeClassColor,
|
||||
onSelectShape,
|
||||
onStartDragVertex,
|
||||
onInsertVertexOnEdge,
|
||||
onCloseDraftPolygon,
|
||||
}) => {
|
||||
if (!showMasks) return null
|
||||
|
||||
const polygonShapes = shapes.filter(
|
||||
(s) => s.type === 'polygon' && s.visible && s.points && s.points.length >= 3
|
||||
)
|
||||
|
||||
return (
|
||||
<g>
|
||||
{polygonShapes.map((shape) => {
|
||||
const pts = shape.points!
|
||||
const isSelected = shape.id === selectedShapeId
|
||||
const pointsAttr = pts.map((p) => `${p.x},${p.y}`).join(' ')
|
||||
|
||||
// Find top-most vertex to place the label tag cleanly above the shape
|
||||
const topPoint = pts.reduce(
|
||||
(minPt, p) => (p.y < minPt.y ? p : minPt),
|
||||
pts[0]!
|
||||
)
|
||||
const tagText =
|
||||
shape.groupId !== undefined
|
||||
? `${shape.labelName} · group ${shape.groupId}`
|
||||
: shape.labelName
|
||||
const tagWidth = Math.max(135, tagText.length * 11 + 26)
|
||||
const tagX = topPoint.x - 20
|
||||
const tagY = Math.max(8, topPoint.y - 46)
|
||||
|
||||
return (
|
||||
<g key={shape.id}>
|
||||
{/* Polygon Filled Mask */}
|
||||
<polygon
|
||||
points={pointsAttr}
|
||||
fill={shape.color}
|
||||
fillOpacity={maskOpacity / 100}
|
||||
stroke={shape.color}
|
||||
strokeWidth={isSelected ? 4 : 3}
|
||||
strokeLinejoin="round"
|
||||
className="cursor-pointer transition-opacity"
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
onSelectShape(shape.id)
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Clickable/Double-clickable Edges for inserting a new vertex */}
|
||||
{isSelected &&
|
||||
vertexEditEnabled &&
|
||||
pts.map((pt, idx) => {
|
||||
const nextPt = pts[(idx + 1) % pts.length]!
|
||||
return (
|
||||
<line
|
||||
key={`edge-${idx}`}
|
||||
x1={pt.x}
|
||||
y1={pt.y}
|
||||
x2={nextPt.x}
|
||||
y2={nextPt.y}
|
||||
stroke="transparent"
|
||||
strokeWidth={14}
|
||||
className="cursor-copy"
|
||||
onDoubleClick={(e) => {
|
||||
e.stopPropagation()
|
||||
const midX = (pt.x + nextPt.x) / 2
|
||||
const midY = (pt.y + nextPt.y) / 2
|
||||
onInsertVertexOnEdge(shape.id, idx, { x: midX, y: midY })
|
||||
}}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Label Pill above Selected Polygon (e.g., "Xe buýt · group 2") */}
|
||||
{isSelected && (
|
||||
<g className="pointer-events-none">
|
||||
<rect
|
||||
x={tagX}
|
||||
y={tagY}
|
||||
width={tagWidth}
|
||||
height={34}
|
||||
rx={8}
|
||||
fill={shape.color}
|
||||
fillOpacity={0.88}
|
||||
/>
|
||||
<text
|
||||
x={tagX + tagWidth / 2}
|
||||
y={tagY + 22}
|
||||
fill="#0F172A"
|
||||
fontSize={16}
|
||||
fontWeight="bold"
|
||||
textAnchor="middle"
|
||||
className="select-none"
|
||||
>
|
||||
{tagText}
|
||||
</text>
|
||||
</g>
|
||||
)}
|
||||
|
||||
{/* Draggable Vertex Handles on Selected Polygon */}
|
||||
{isSelected &&
|
||||
pts.map((pt, idx) => (
|
||||
<circle
|
||||
key={`vertex-${idx}`}
|
||||
cx={pt.x}
|
||||
cy={pt.y}
|
||||
r={vertexEditEnabled ? 7.5 : 5.5}
|
||||
fill="#FFFFFF"
|
||||
stroke={shape.color}
|
||||
strokeWidth={3.5}
|
||||
className={
|
||||
vertexEditEnabled ? 'cursor-grab active:cursor-grabbing' : 'cursor-pointer'
|
||||
}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
if (vertexEditEnabled) {
|
||||
onStartDragVertex(e, shape.id, idx)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* In-progress Draft Polygon while clicking points */}
|
||||
{draftPolygonPoints.length > 0 && (
|
||||
<g>
|
||||
<polyline
|
||||
points={[
|
||||
...draftPolygonPoints.map((p) => `${p.x},${p.y}`),
|
||||
...(cursorPoint ? [`${cursorPoint.x},${cursorPoint.y}`] : []),
|
||||
].join(' ')}
|
||||
fill={activeClassColor}
|
||||
fillOpacity={0.18}
|
||||
stroke={activeClassColor}
|
||||
strokeWidth={3.5}
|
||||
strokeDasharray="8 5"
|
||||
className="pointer-events-none"
|
||||
/>
|
||||
{draftPolygonPoints.map((pt, idx) => {
|
||||
const isFirst = idx === 0
|
||||
return (
|
||||
<circle
|
||||
key={`draft-pt-${idx}`}
|
||||
cx={pt.x}
|
||||
cy={pt.y}
|
||||
r={isFirst ? 10 : 7}
|
||||
fill={isFirst ? activeClassColor : '#FFFFFF'}
|
||||
stroke="#FFFFFF"
|
||||
strokeWidth={3}
|
||||
className="cursor-pointer"
|
||||
onClick={(e) => {
|
||||
if (isFirst && draftPolygonPoints.length >= 3) {
|
||||
e.stopPropagation()
|
||||
onCloseDraftPolygon()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
}
|
||||
11
src/pages/annotator/components/canvas/SelectTool.tsx
Normal file
11
src/pages/annotator/components/canvas/SelectTool.tsx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import React from 'react'
|
||||
import { AnnotationShape } from '@/types'
|
||||
|
||||
export interface SelectToolProps {
|
||||
selectedShape: AnnotationShape | undefined
|
||||
}
|
||||
|
||||
export const SelectTool: React.FC<SelectToolProps> = ({ selectedShape }) => {
|
||||
if (!selectedShape || !selectedShape.visible) return null
|
||||
return null
|
||||
}
|
||||
102
src/pages/annotator/components/canvas/ToolBar.tsx
Normal file
102
src/pages/annotator/components/canvas/ToolBar.tsx
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { AnnotationTool } from '@/types'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { UndoRedoButtons } from '../header/UndoRedoButtons'
|
||||
import { ZoomControls } from './ZoomControls'
|
||||
|
||||
export const ToolBar: React.FC = () => {
|
||||
const taskType = useAnnotatorStore((s) => s.project.taskType)
|
||||
const activeTool = useAnnotatorStore((s) => s.activeTool)
|
||||
const setActiveTool = useAnnotatorStore((s) => s.setActiveTool)
|
||||
|
||||
const tools: {
|
||||
id: AnnotationTool
|
||||
label: string
|
||||
shortcut: string
|
||||
enabled: boolean
|
||||
icon: React.ReactNode
|
||||
}[] = [
|
||||
{
|
||||
id: 'select',
|
||||
label: 'Chọn',
|
||||
shortcut: 'V',
|
||||
enabled: true,
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="m3 3 7.07 16.97 2.51-7.39 7.39-2.51L3 3z" />
|
||||
<path d="m13 13 6 6" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'bbox',
|
||||
label: 'Hộp',
|
||||
shortcut: 'B',
|
||||
enabled: taskType === 'object_detection',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeDasharray="3 2">
|
||||
<rect x="3" y="3" width="18" height="18" rx="2" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'polygon',
|
||||
label: 'Polygon',
|
||||
shortcut: 'P',
|
||||
enabled: taskType === 'segmentation',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polygon points="12 2 22 8.5 18 21 6 21 2 8.5 12 2" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'point',
|
||||
label: 'Điểm',
|
||||
shortcut: 'K',
|
||||
enabled: taskType !== 'classification',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z" />
|
||||
<circle cx="12" cy="10" r="3" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between border-b border-slate-100 px-4 py-2">
|
||||
<div className="flex items-center gap-1.5">
|
||||
{tools.map((tool) => {
|
||||
const isActive = activeTool === tool.id
|
||||
return (
|
||||
<button
|
||||
key={tool.id}
|
||||
type="button"
|
||||
disabled={!tool.enabled}
|
||||
onClick={() => tool.enabled && setActiveTool(tool.id)}
|
||||
title={`${tool.label} (${tool.shortcut})`}
|
||||
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'
|
||||
: tool.enabled
|
||||
? 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
||||
: 'cursor-not-allowed text-slate-300'
|
||||
)}
|
||||
>
|
||||
{tool.icon}
|
||||
<span>{tool.label}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
|
||||
<div className="mx-1.5 h-4 w-px bg-slate-200" />
|
||||
<UndoRedoButtons />
|
||||
</div>
|
||||
|
||||
<ZoomControls />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
55
src/pages/annotator/components/canvas/ZoomControls.tsx
Normal file
55
src/pages/annotator/components/canvas/ZoomControls.tsx
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ZoomControls: React.FC = () => {
|
||||
const zoom = useAnnotatorStore((s) => s.zoom)
|
||||
const zoomIn = useAnnotatorStore((s) => s.zoomIn)
|
||||
const zoomOut = useAnnotatorStore((s) => s.zoomOut)
|
||||
const resetZoom = useAnnotatorStore((s) => s.resetZoom)
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-1.5 text-slate-600">
|
||||
<button
|
||||
type="button"
|
||||
onClick={zoomOut}
|
||||
title="Thu nhỏ"
|
||||
className="inline-flex h-7 w-7 items-center justify-center rounded-lg transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
||||
<line x1="8" y1="11" x2="14" y2="11" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<span className="min-w-[38px] text-center font-mono text-xs font-medium text-slate-600">
|
||||
{zoom}%
|
||||
</span>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={zoomIn}
|
||||
title="Phóng to"
|
||||
className="inline-flex h-7 w-7 items-center justify-center rounded-lg transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
||||
<line x1="11" y1="8" x2="11" y2="14" />
|
||||
<line x1="8" y1="11" x2="14" y2="11" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={resetZoom}
|
||||
title="Khớp khung hình (75%)"
|
||||
className="inline-flex h-7 w-7 items-center justify-center rounded-lg transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
71
src/pages/annotator/components/header/AnnotatorHeader.tsx
Normal file
71
src/pages/annotator/components/header/AnnotatorHeader.tsx
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
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'
|
||||
import { SaveButton } from './SaveButton'
|
||||
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' },
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 pb-3">
|
||||
<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">
|
||||
{TASK_TYPE_LABELS[project.taskType]} · {project.slug} ·{' '}
|
||||
{formatNumber(project.stats.totalImages)} ảnh
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2.5">
|
||||
<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"
|
||||
>
|
||||
<span>←</span>
|
||||
<span>Về tổng quan</span>
|
||||
</button>
|
||||
<SaveButton />
|
||||
<SaveAndNextButton />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
19
src/pages/annotator/components/header/ImageInfo.tsx
Normal file
19
src/pages/annotator/components/header/ImageInfo.tsx
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ImageInfo: React.FC = () => {
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2.5">
|
||||
<span className="font-mono text-xs font-semibold text-slate-800">
|
||||
{currentImage.fileName}
|
||||
</span>
|
||||
<span className="text-xs text-slate-400">
|
||||
{currentImage.width} × {currentImage.height} px
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
25
src/pages/annotator/components/header/SaveAndNextButton.tsx
Normal file
25
src/pages/annotator/components/header/SaveAndNextButton.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import React from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const SaveAndNextButton: React.FC = () => {
|
||||
const saveAndNext = useAnnotatorStore((s) => s.saveAndNext)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
|
||||
const handleSaveAndNext = () => {
|
||||
const fileName = currentImage?.fileName ?? 'ảnh'
|
||||
saveAndNext()
|
||||
toast.success(`Đã lưu ${fileName} và chuyển sang ảnh tiếp theo`)
|
||||
}
|
||||
|
||||
return (
|
||||
<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"
|
||||
>
|
||||
<span>→</span>
|
||||
<span>Lưu & ảnh tiếp</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
36
src/pages/annotator/components/header/SaveButton.tsx
Normal file
36
src/pages/annotator/components/header/SaveButton.tsx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import React from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const SaveButton: React.FC = () => {
|
||||
const saveCurrentAnnotation = useAnnotatorStore((s) => s.saveCurrentAnnotation)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
|
||||
const handleSave = () => {
|
||||
saveCurrentAnnotation()
|
||||
toast.success(`Đã lưu nhãn cho ${currentImage?.fileName ?? 'ảnh hiện tại'}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<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"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4 text-white/90"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z" />
|
||||
<polyline points="17 21 17 13 7 13 7 21" />
|
||||
<polyline points="7 3 7 8 15 8" />
|
||||
</svg>
|
||||
<span>Lưu</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
54
src/pages/annotator/components/header/UndoRedoButtons.tsx
Normal file
54
src/pages/annotator/components/header/UndoRedoButtons.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const UndoRedoButtons: React.FC = () => {
|
||||
const undo = useAnnotatorStore((s) => s.undo)
|
||||
const redo = useAnnotatorStore((s) => s.redo)
|
||||
const canUndo = useAnnotatorStore((s) => s.historyPast.length > 0)
|
||||
const canRedo = useAnnotatorStore((s) => s.historyFuture.length > 0)
|
||||
|
||||
return (
|
||||
<div className="inline-flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={undo}
|
||||
disabled={!canUndo}
|
||||
title="Hoàn tác (Ctrl+Z)"
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-lg text-slate-600 transition-colors hover:bg-slate-100 hover:text-slate-900 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M3 7v6h6" />
|
||||
<path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13" />
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={redo}
|
||||
disabled={!canRedo}
|
||||
title="Làm lại (Ctrl+Y)"
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-lg text-slate-600 transition-colors hover:bg-slate-100 hover:text-slate-900 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M21 7v6h-6" />
|
||||
<path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
40
src/pages/annotator/components/navigator/ImageCounter.tsx
Normal file
40
src/pages/annotator/components/navigator/ImageCounter.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import React from 'react'
|
||||
import { formatNumber } from '@/utils/format'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ImageCounter: React.FC = () => {
|
||||
const displayImageCounter = useAnnotatorStore((s) => s.displayImageCounter)
|
||||
const totalImages = useAnnotatorStore((s) => s.project.stats.totalImages)
|
||||
const prevImage = useAnnotatorStore((s) => s.prevImage)
|
||||
const nextImage = useAnnotatorStore((s) => s.nextImage)
|
||||
|
||||
return (
|
||||
<div className="inline-flex items-center gap-3 text-xs font-medium text-slate-600">
|
||||
<button
|
||||
type="button"
|
||||
onClick={prevImage}
|
||||
title="Ảnh trước"
|
||||
className="inline-flex h-6 w-6 items-center justify-center rounded-md text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="15 18 9 12 15 6" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<span className="font-mono text-xs text-slate-600">
|
||||
{displayImageCounter} / {formatNumber(totalImages)}
|
||||
</span>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={nextImage}
|
||||
title="Ảnh tiếp theo"
|
||||
className="inline-flex h-6 w-6 items-center justify-center rounded-md text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="9 18 15 12 9 6" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
38
src/pages/annotator/components/navigator/ImageNavigator.tsx
Normal file
38
src/pages/annotator/components/navigator/ImageNavigator.tsx
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { ThumbnailStrip } from './ThumbnailStrip'
|
||||
import { SaveStatus } from './SaveStatus'
|
||||
|
||||
export const ImageNavigator: React.FC = () => {
|
||||
const taskType = useAnnotatorStore((s) => s.project.taskType)
|
||||
|
||||
const leftHint =
|
||||
taskType === 'classification'
|
||||
? 'Chọn lớp ở bảng bên phải · Không tạo shape'
|
||||
: taskType === 'object_detection'
|
||||
? 'Kéo để tạo box · Kéo góc để chỉnh kích thước'
|
||||
: 'Click để thêm đỉnh · Enter để đóng polygon'
|
||||
|
||||
const rightShortcut =
|
||||
taskType === 'classification'
|
||||
? 'Chọn [V]'
|
||||
: taskType === 'object_detection'
|
||||
? 'Hộp [B]'
|
||||
: 'Polygon [P]'
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Hint Bar above Thumbnail Strip */}
|
||||
<div className="flex items-center justify-between border-t border-slate-100 px-4 py-2 text-[11px] text-slate-500">
|
||||
<span>{leftHint}</span>
|
||||
<span className="font-mono text-slate-400">{rightShortcut}</span>
|
||||
</div>
|
||||
|
||||
{/* 6 Image Thumbnails */}
|
||||
<ThumbnailStrip />
|
||||
|
||||
{/* Bottom Save & Export Status Bar */}
|
||||
<SaveStatus />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
63
src/pages/annotator/components/navigator/SaveStatus.tsx
Normal file
63
src/pages/annotator/components/navigator/SaveStatus.tsx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import React from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { exportToLabelMeJSON } from '@/utils/labelme'
|
||||
import { exportSegmentationMaskPNG } from '@/utils/mask'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const SaveStatus: React.FC = () => {
|
||||
const project = useAnnotatorStore((s) => s.project)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const lastSavedAt = useAnnotatorStore((s) => s.lastSavedAt)
|
||||
|
||||
const shapes = currentImage ? shapesByImageId[currentImage.id] ?? [] : []
|
||||
|
||||
const handleExportLabelMe = () => {
|
||||
if (!currentImage) return
|
||||
exportToLabelMeJSON(currentImage, shapes, true)
|
||||
toast.success(`Đã xuất ${currentImage.fileName.replace(/\.[^/.]+$/, '')}_labelme.json`)
|
||||
}
|
||||
|
||||
const handleExportMask = () => {
|
||||
if (!currentImage) return
|
||||
exportSegmentationMaskPNG(currentImage, shapes, true)
|
||||
toast.success(`Đã xuất ${currentImage.fileName.replace(/\.[^/.]+$/, '')}_mask.png`)
|
||||
}
|
||||
|
||||
const rightStatusSummary =
|
||||
project.taskType === 'classification'
|
||||
? `Chờ duyệt · ${project.stats.pendingReview} ảnh`
|
||||
: project.taskType === 'object_detection'
|
||||
? `Chờ duyệt · ${project.stats.pendingReview} ảnh`
|
||||
: `Đang làm · ${project.stats.inProgress} ảnh`
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between border-t border-slate-100 px-4 py-2.5 text-xs">
|
||||
<div className="flex items-center gap-1.5 font-medium text-[#15803D]">
|
||||
<span>✓</span>
|
||||
<span>Đã lưu lúc {lastSavedAt}</span>
|
||||
</div>
|
||||
|
||||
{project.taskType === 'segmentation' && (
|
||||
<div className="flex items-center gap-5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleExportLabelMe}
|
||||
className="font-semibold text-[#4F46E5] transition-colors hover:text-[#3730A3] hover:underline"
|
||||
>
|
||||
Xuất LabelMe JSON ↓
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleExportMask}
|
||||
className="font-semibold text-[#4F46E5] transition-colors hover:text-[#3730A3] hover:underline"
|
||||
>
|
||||
Xuất mask PNG ↓
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="text-slate-500">{rightStatusSummary}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
54
src/pages/annotator/components/navigator/ThumbnailStrip.tsx
Normal file
54
src/pages/annotator/components/navigator/ThumbnailStrip.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ThumbnailStrip: React.FC = () => {
|
||||
const images = useAnnotatorStore((s) => s.images)
|
||||
const currentImageIndex = useAnnotatorStore((s) => s.currentImageIndex)
|
||||
const selectImageByIndex = useAnnotatorStore((s) => s.selectImageByIndex)
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-6 gap-2.5 px-4 py-2.5">
|
||||
{images.map((img, index) => {
|
||||
const isActive = index === currentImageIndex
|
||||
// Shorten "urban_00124.jpg" -> "..00124.jpg" matching wireframe
|
||||
const shortName = img.fileName.replace(/^[a-z]+_/, '..')
|
||||
|
||||
return (
|
||||
<button
|
||||
key={img.id}
|
||||
type="button"
|
||||
onClick={() => selectImageByIndex(index)}
|
||||
className="group flex flex-col items-center gap-1 focus:outline-none"
|
||||
>
|
||||
<div
|
||||
className={clsx(
|
||||
'relative aspect-video w-full overflow-hidden rounded-lg border-2 transition-all',
|
||||
isActive
|
||||
? 'border-[#4F46E5] shadow-xs'
|
||||
: 'border-transparent opacity-85 hover:opacity-100'
|
||||
)}
|
||||
>
|
||||
<img
|
||||
src={img.thumbnailUrl}
|
||||
alt={img.fileName}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<span
|
||||
className={clsx(
|
||||
'font-mono text-[10px] transition-colors',
|
||||
isActive
|
||||
? 'font-semibold text-[#4F46E5]'
|
||||
: 'text-slate-400 group-hover:text-slate-600'
|
||||
)}
|
||||
>
|
||||
{shortName}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { StatusBadge } from './StatusBadge'
|
||||
import { ImageFlagCheckboxes } from './ImageFlagCheckboxes'
|
||||
import { ReviewActions } from './ReviewActions'
|
||||
|
||||
export const ClassificationPanel: React.FC = () => {
|
||||
const classes = useAnnotatorStore((s) => s.project.classes)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const classificationByImageId = useAnnotatorStore((s) => s.classificationByImageId)
|
||||
const statusByImageId = useAnnotatorStore((s) => s.statusByImageId)
|
||||
const setClassificationLabel = useAnnotatorStore((s) => s.setClassificationLabel)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const activeClassId = classificationByImageId[currentImage.id] ?? 'cls-car'
|
||||
const activeClass = classes.find((c) => c.id === activeClassId) ?? classes[0]
|
||||
const currentStatus = statusByImageId[currentImage.id] ?? 'pending_review'
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-3.5 rounded-2xl border border-slate-200/80 bg-white p-5 shadow-2xs">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-bold text-slate-900">Nhãn cấp ảnh</h3>
|
||||
<span className="text-xs font-medium text-[#4F46E5]">1 nhãn / ảnh</span>
|
||||
</div>
|
||||
|
||||
{/* Status Badge */}
|
||||
<div>
|
||||
<StatusBadge status={currentStatus} />
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-slate-500">Chọn một lớp cho toàn bộ ảnh.</p>
|
||||
|
||||
{/* Class Radio Cards */}
|
||||
<div className="space-y-2.5">
|
||||
{classes.map((cls, index) => {
|
||||
const isSelected = cls.id === activeClassId
|
||||
return (
|
||||
<button
|
||||
key={cls.id}
|
||||
type="button"
|
||||
onClick={() => setClassificationLabel(cls.id)}
|
||||
className={clsx(
|
||||
'flex w-full items-center justify-between rounded-xl border px-3.5 py-3 text-left transition-all',
|
||||
isSelected
|
||||
? 'border-[#4F46E5] bg-[#FDECE7] shadow-2xs'
|
||||
: 'border-slate-200 bg-white hover:border-slate-300'
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-2.5">
|
||||
<span
|
||||
className={clsx(
|
||||
'flex h-4 w-4 items-center justify-center rounded-full border transition-colors',
|
||||
isSelected
|
||||
? 'border-[#4F46E5] bg-[#4F46E5]'
|
||||
: 'border-slate-300 bg-white'
|
||||
)}
|
||||
>
|
||||
{isSelected && (
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-white" />
|
||||
)}
|
||||
</span>
|
||||
<span className="text-xs font-semibold text-slate-900">
|
||||
{cls.name}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<span className="font-mono text-xs text-slate-400">
|
||||
{cls.shortcutKey ?? index + 1}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Image Flags */}
|
||||
<ImageFlagCheckboxes />
|
||||
|
||||
{/* Reviewer Info Box */}
|
||||
<div className="rounded-xl bg-slate-50 p-3.5">
|
||||
<p className="text-xs font-semibold text-slate-800">
|
||||
{currentImage.submittedBy ?? 'Hà Linh'} đã gửi nhãn {activeClass?.name ?? 'Ô tô'}
|
||||
</p>
|
||||
<p className="mt-1 text-[11px] text-slate-500">
|
||||
{currentImage.submittedAt ?? 'Hôm nay, 09:42'} · Người duyệt:{' '}
|
||||
{currentImage.reviewerName ?? 'Thu Hà'}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Review Actions */}
|
||||
<ReviewActions approveLabel="Duyệt nhãn" targetStatusOnApprove="completed" />
|
||||
|
||||
<p className="text-[11px] text-slate-400">
|
||||
Enter để duyệt · 1–4 chọn lớp
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ImageFlagCheckboxes: React.FC = () => {
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const flagsByImageId = useAnnotatorStore((s) => s.flagsByImageId)
|
||||
const toggleFlag = useAnnotatorStore((s) => s.toggleFlag)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const flags = flagsByImageId[currentImage.id] ?? {
|
||||
blurryOrUncertain: false,
|
||||
needsRecheck: false,
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2 pt-1">
|
||||
<h4 className="text-xs font-bold text-slate-800">Cờ cấp ảnh</h4>
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-slate-600 hover:text-slate-900">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={flags.blurryOrUncertain}
|
||||
onChange={() => toggleFlag('blurryOrUncertain')}
|
||||
className="h-3.5 w-3.5 rounded-xs border-slate-300 text-[#C95C3C] focus:ring-[#C95C3C]"
|
||||
/>
|
||||
<span>Ảnh mờ / khó xác định</span>
|
||||
</label>
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-slate-600 hover:text-slate-900">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={flags.needsRecheck}
|
||||
onChange={() => toggleFlag('needsRecheck')}
|
||||
className="h-3.5 w-3.5 rounded-xs border-slate-300 text-[#C95C3C] focus:ring-[#C95C3C]"
|
||||
/>
|
||||
<span>Cần kiểm tra lại</span>
|
||||
</label>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const LabelSelector: React.FC = () => {
|
||||
const classes = useAnnotatorStore((s) => s.project.classes)
|
||||
const selectedClassId = useAnnotatorStore((s) => s.selectedClassId)
|
||||
const activeGroupId = useAnnotatorStore((s) => s.activeGroupId)
|
||||
const updateSelectedShapeClass = useAnnotatorStore((s) => s.updateSelectedShapeClass)
|
||||
const setActiveGroupId = useAnnotatorStore((s) => s.setActiveGroupId)
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-3 gap-2.5 pt-1">
|
||||
<div className="col-span-2">
|
||||
<label className="mb-1 block text-[11px] font-medium text-slate-500">
|
||||
Nhãn
|
||||
</label>
|
||||
<div className="relative">
|
||||
<select
|
||||
value={selectedClassId}
|
||||
onChange={(e) => updateSelectedShapeClass(e.target.value)}
|
||||
className="w-full appearance-none rounded-xl border border-slate-200 bg-white px-3 py-2 pr-8 text-xs font-semibold text-slate-800 focus:border-[#4F46E5] focus:outline-none"
|
||||
>
|
||||
{classes.map((cls) => (
|
||||
<option key={cls.id} value={cls.id}>
|
||||
{cls.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span className="pointer-events-none absolute inset-y-0 right-2.5 flex items-center text-slate-400">
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="6 9 12 15 18 9" />
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-1 block text-[11px] font-medium text-slate-500">
|
||||
Mã nhóm
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={99}
|
||||
value={activeGroupId}
|
||||
onChange={(e) => setActiveGroupId(Math.max(1, Number(e.target.value) || 1))}
|
||||
className="w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-xs font-semibold text-slate-800 focus:border-[#4F46E5] focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
100
src/pages/annotator/components/sidebar-right/ObjectItem.tsx
Normal file
100
src/pages/annotator/components/sidebar-right/ObjectItem.tsx
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { AnnotationShape, TaskType } from '@/types'
|
||||
|
||||
export interface ObjectItemProps {
|
||||
shape: AnnotationShape
|
||||
isSelected: boolean
|
||||
taskType: TaskType
|
||||
onSelect: () => void
|
||||
onToggleVisible: () => void
|
||||
onDelete: () => void
|
||||
}
|
||||
|
||||
export const ObjectItem: React.FC<ObjectItemProps> = ({
|
||||
shape,
|
||||
isSelected,
|
||||
taskType,
|
||||
onSelect,
|
||||
onToggleVisible,
|
||||
onDelete,
|
||||
}) => {
|
||||
const indexFormatted = String(shape.index).padStart(2, '0')
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={onSelect}
|
||||
className={clsx(
|
||||
'group cursor-pointer rounded-xl border px-3.5 py-2.5 transition-all',
|
||||
isSelected
|
||||
? 'border-[#C95C3C]/30 bg-[#FDECE7]/85'
|
||||
: 'border-slate-200/90 bg-white hover:border-slate-300'
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<span
|
||||
className="h-2.5 w-2.5 shrink-0 rounded-xs"
|
||||
style={{ backgroundColor: shape.color }}
|
||||
/>
|
||||
<span className="text-xs font-semibold text-slate-800">
|
||||
{shape.labelName}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-mono text-[11px] text-slate-400">
|
||||
{taskType === 'segmentation' ? `#${indexFormatted}` : indexFormatted}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onToggleVisible()
|
||||
}}
|
||||
title={shape.visible ? 'Ẩn đối tượng' : 'Hiện đối tượng'}
|
||||
className={clsx(
|
||||
'rounded-md p-0.5 transition-colors',
|
||||
shape.visible
|
||||
? 'text-slate-500 hover:text-slate-800'
|
||||
: 'text-slate-300 hover:text-slate-500'
|
||||
)}
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onDelete()
|
||||
}}
|
||||
title="Xóa đối tượng (Delete)"
|
||||
className="hidden rounded-md p-0.5 text-slate-400 transition-colors hover:text-red-600 group-hover:inline-flex"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="3 6 5 6 21 6" />
|
||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Selected subtitle: BBox coordinates or Polygon vertex/group metadata */}
|
||||
{isSelected && taskType === 'object_detection' && shape.bbox && (
|
||||
<div className="mt-1.5 font-mono text-[11px] text-slate-500">
|
||||
x: {shape.bbox.x} y: {shape.bbox.y} w: {shape.bbox.width} h:{' '}
|
||||
{shape.bbox.height}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isSelected && taskType === 'segmentation' && shape.points && (
|
||||
<div className="mt-1 font-mono text-[11px] text-slate-500">
|
||||
polygon · {shape.points.length} đỉnh · group {shape.groupId ?? 1}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
141
src/pages/annotator/components/sidebar-right/ObjectListPanel.tsx
Normal file
141
src/pages/annotator/components/sidebar-right/ObjectListPanel.tsx
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { ObjectItem } from './ObjectItem'
|
||||
import { StatusBadge } from './StatusBadge'
|
||||
import { ReviewActions } from './ReviewActions'
|
||||
|
||||
export const ObjectListPanel: React.FC = () => {
|
||||
const classes = useAnnotatorStore((s) => s.project.classes)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const statusByImageId = useAnnotatorStore((s) => s.statusByImageId)
|
||||
const selectedShapeId = useAnnotatorStore((s) => s.selectedShapeId)
|
||||
const selectedClassId = useAnnotatorStore((s) => s.selectedClassId)
|
||||
const showBoxes = useAnnotatorStore((s) => s.showBoxes)
|
||||
|
||||
const setShowBoxes = useAnnotatorStore((s) => s.setShowBoxes)
|
||||
const setSelectedShapeId = useAnnotatorStore((s) => s.setSelectedShapeId)
|
||||
const updateSelectedShapeClass = useAnnotatorStore((s) => s.updateSelectedShapeClass)
|
||||
const toggleShapeVisibility = useAnnotatorStore((s) => s.toggleShapeVisibility)
|
||||
const toggleAllShapesVisibility = useAnnotatorStore((s) => s.toggleAllShapesVisibility)
|
||||
const deleteShape = useAnnotatorStore((s) => s.deleteShape)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const shapes = shapesByImageId[currentImage.id] ?? []
|
||||
const currentStatus = statusByImageId[currentImage.id] ?? 'pending_review'
|
||||
|
||||
const getCountByClass = (classId: string) =>
|
||||
shapes.filter((s) => s.labelId === classId).length
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-3.5 rounded-2xl border border-slate-200/80 bg-white p-5 shadow-2xs">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-bold text-slate-900">Danh sách đối tượng</h3>
|
||||
<span className="text-xs font-medium text-[#4F46E5]">{shapes.length} hình</span>
|
||||
</div>
|
||||
|
||||
{/* Show Bounding Boxes Toggle Row */}
|
||||
<div className="flex items-center justify-between">
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-slate-600">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={showBoxes}
|
||||
onChange={(e) => setShowBoxes(e.target.checked)}
|
||||
className="h-3.5 w-3.5 rounded-xs border-slate-300 text-slate-700 focus:ring-[#C95C3C]"
|
||||
/>
|
||||
<span>Hiện hộp giới hạn</span>
|
||||
</label>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleAllShapesVisibility}
|
||||
title="Ẩn/Hiện tất cả"
|
||||
className="text-slate-500 hover:text-slate-800"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Object Cards List */}
|
||||
<div className="max-h-[260px] space-y-2 overflow-y-auto pr-0.5">
|
||||
{shapes.map((shape) => (
|
||||
<ObjectItem
|
||||
key={shape.id}
|
||||
shape={shape}
|
||||
isSelected={shape.id === selectedShapeId}
|
||||
taskType="object_detection"
|
||||
onSelect={() => setSelectedShapeId(shape.id)}
|
||||
onToggleVisible={() => toggleShapeVisibility(shape.id)}
|
||||
onDelete={() => deleteShape(shape.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Project Classes Pills */}
|
||||
<div className="space-y-2 pt-1">
|
||||
<h4 className="text-xs font-bold text-slate-800">Lớp trong dự án</h4>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{classes.map((cls) => {
|
||||
const count = getCountByClass(cls.id)
|
||||
const isActive = cls.id === selectedClassId
|
||||
return (
|
||||
<button
|
||||
key={cls.id}
|
||||
type="button"
|
||||
onClick={() => updateSelectedShapeClass(cls.id)}
|
||||
className={clsx(
|
||||
'inline-flex items-center gap-1.5 rounded-lg border px-2.5 py-1 text-xs font-medium transition-colors',
|
||||
isActive
|
||||
? 'border-[#C95C3C]/40 bg-[#FDF4F1] text-slate-900'
|
||||
: 'border-slate-200 bg-slate-50 text-slate-700 hover:bg-slate-100'
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className="h-1.5 w-1.5 rounded-full"
|
||||
style={{ backgroundColor: cls.color }}
|
||||
/>
|
||||
<span>
|
||||
{cls.name} · {count}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Active Class Dropdown */}
|
||||
<div className="flex items-center gap-1.5 pt-1 text-xs text-slate-500">
|
||||
<span>Lớp đang chọn:</span>
|
||||
<select
|
||||
value={selectedClassId}
|
||||
onChange={(e) => updateSelectedShapeClass(e.target.value)}
|
||||
className="cursor-pointer bg-transparent font-medium text-slate-700 focus:outline-none"
|
||||
>
|
||||
{classes.map((cls) => (
|
||||
<option key={cls.id} value={cls.id}>
|
||||
{cls.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Image Status Row */}
|
||||
<div className="flex items-center justify-between pt-1">
|
||||
<span className="text-xs text-slate-500">Trạng thái ảnh</span>
|
||||
<StatusBadge status={currentStatus} />
|
||||
</div>
|
||||
|
||||
{/* Review Actions */}
|
||||
<ReviewActions
|
||||
approveLabel={`Duyệt ${shapes.length} nhãn`}
|
||||
targetStatusOnApprove="completed"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
import React from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export interface ReviewActionsProps {
|
||||
approveLabel: string
|
||||
targetStatusOnApprove?: 'completed' | 'pending_review'
|
||||
}
|
||||
|
||||
export const ReviewActions: React.FC<ReviewActionsProps> = ({
|
||||
approveLabel,
|
||||
targetStatusOnApprove = 'completed',
|
||||
}) => {
|
||||
const updateImageStatus = useAnnotatorStore((s) => s.updateImageStatus)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
|
||||
const handleReject = () => {
|
||||
updateImageStatus('in_progress')
|
||||
toast(`Đã trả lại ảnh ${currentImage?.fileName ?? ''} để chỉnh sửa`, {
|
||||
icon: '↩️',
|
||||
})
|
||||
}
|
||||
|
||||
const handleApprove = () => {
|
||||
updateImageStatus(targetStatusOnApprove)
|
||||
toast.success(
|
||||
targetStatusOnApprove === 'pending_review'
|
||||
? `Đã gửi duyệt ${currentImage?.fileName ?? ''}`
|
||||
: `Đã duyệt nhãn cho ${currentImage?.fileName ?? ''}`
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2.5 pt-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleReject}
|
||||
className="inline-flex items-center justify-center rounded-xl border border-slate-200 bg-white px-4 py-2 text-xs font-semibold text-slate-800 shadow-2xs transition-colors hover:bg-slate-50"
|
||||
>
|
||||
Trả lại
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleApprove}
|
||||
className="inline-flex flex-1 items-center justify-center gap-1.5 rounded-xl bg-[#C95C3C] px-4 py-2 text-xs font-semibold text-white shadow-sm transition-colors hover:bg-[#B5492B]"
|
||||
>
|
||||
<span>✓</span>
|
||||
<span>{approveLabel}</span>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { ObjectItem } from './ObjectItem'
|
||||
import { LabelSelector } from './LabelSelector'
|
||||
import { StatusBadge } from './StatusBadge'
|
||||
import { ReviewActions } from './ReviewActions'
|
||||
|
||||
export const SegmentationPanel: React.FC = () => {
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const statusByImageId = useAnnotatorStore((s) => s.statusByImageId)
|
||||
const selectedShapeId = useAnnotatorStore((s) => s.selectedShapeId)
|
||||
const showMasks = useAnnotatorStore((s) => s.showMasks)
|
||||
const maskOpacity = useAnnotatorStore((s) => s.maskOpacity)
|
||||
const vertexEditEnabled = useAnnotatorStore((s) => s.vertexEditEnabled)
|
||||
|
||||
const setShowMasks = useAnnotatorStore((s) => s.setShowMasks)
|
||||
const setMaskOpacity = useAnnotatorStore((s) => s.setMaskOpacity)
|
||||
const toggleVertexEdit = useAnnotatorStore((s) => s.toggleVertexEdit)
|
||||
const setSelectedShapeId = useAnnotatorStore((s) => s.setSelectedShapeId)
|
||||
const toggleShapeVisibility = useAnnotatorStore((s) => s.toggleShapeVisibility)
|
||||
const toggleAllShapesVisibility = useAnnotatorStore((s) => s.toggleAllShapesVisibility)
|
||||
const deleteShape = useAnnotatorStore((s) => s.deleteShape)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const shapes = shapesByImageId[currentImage.id] ?? []
|
||||
const currentStatus = statusByImageId[currentImage.id] ?? 'in_progress'
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-3.5 rounded-2xl border border-slate-200/80 bg-white p-5 shadow-2xs">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-bold text-slate-900">Hình và nhãn</h3>
|
||||
<span className="text-xs font-medium text-[#4F46E5]">{shapes.length} hình</span>
|
||||
</div>
|
||||
|
||||
{/* Show Mask Checkbox */}
|
||||
<div className="flex items-center justify-between">
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-slate-600">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={showMasks}
|
||||
onChange={(e) => setShowMasks(e.target.checked)}
|
||||
className="h-3.5 w-3.5 rounded-xs border-slate-300 text-slate-700 focus:ring-[#C95C3C]"
|
||||
/>
|
||||
<span>Hiện mask</span>
|
||||
</label>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleAllShapesVisibility}
|
||||
title="Ẩn/Hiện tất cả mask"
|
||||
className="text-slate-500 hover:text-slate-800"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Mask Opacity Slider */}
|
||||
<div className="space-y-1.5">
|
||||
<div className="flex items-center justify-between text-xs">
|
||||
<span className="text-slate-500">Độ trong suốt</span>
|
||||
<span className="font-semibold text-[#4F46E5]">{maskOpacity}%</span>
|
||||
</div>
|
||||
<input
|
||||
type="range"
|
||||
min={5}
|
||||
max={90}
|
||||
step={5}
|
||||
value={maskOpacity}
|
||||
onChange={(e) => setMaskOpacity(Number(e.target.value))}
|
||||
className="h-1.5 w-full cursor-pointer appearance-none rounded-lg bg-slate-200 accent-[#C95C3C]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Polygon Objects List */}
|
||||
<div className="max-h-[240px] space-y-2 overflow-y-auto pr-0.5">
|
||||
{shapes.map((shape) => (
|
||||
<ObjectItem
|
||||
key={shape.id}
|
||||
shape={shape}
|
||||
isSelected={shape.id === selectedShapeId}
|
||||
taskType="segmentation"
|
||||
onSelect={() => setSelectedShapeId(shape.id)}
|
||||
onToggleVisible={() => toggleShapeVisibility(shape.id)}
|
||||
onDelete={() => deleteShape(shape.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Label & Group Selector */}
|
||||
<LabelSelector />
|
||||
|
||||
{/* Vertex Edit Mode Button */}
|
||||
<div className="space-y-1.5 pt-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleVertexEdit}
|
||||
className={clsx(
|
||||
'flex w-full items-center gap-2 rounded-xl px-3.5 py-2.5 text-xs font-semibold transition-colors',
|
||||
vertexEditEnabled
|
||||
? 'bg-[#FDECE7] text-[#4F46E5]'
|
||||
: 'border border-slate-200 bg-slate-50 text-slate-600 hover:bg-slate-100'
|
||||
)}
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="m3 3 7.07 16.97 2.51-7.39 7.39-2.51L3 3z" />
|
||||
<path d="m13 13 6 6" />
|
||||
</svg>
|
||||
<span>{vertexEditEnabled ? 'Sửa đỉnh đang bật' : 'Bật chế độ sửa đỉnh'}</span>
|
||||
</button>
|
||||
|
||||
<p className="text-[11px] leading-relaxed text-slate-400">
|
||||
Kéo đỉnh để sửa · Double-click cạnh để thêm đỉnh · Delete để xóa đỉnh.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Image Status Row */}
|
||||
<div className="flex items-center justify-between pt-1">
|
||||
<span className="text-xs text-slate-500">Trạng thái ảnh</span>
|
||||
<StatusBadge status={currentStatus} />
|
||||
</div>
|
||||
|
||||
{/* Review Actions */}
|
||||
<ReviewActions approveLabel="Gửi duyệt" targetStatusOnApprove="pending_review" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
54
src/pages/annotator/components/sidebar-right/StatusBadge.tsx
Normal file
54
src/pages/annotator/components/sidebar-right/StatusBadge.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { ImageAnnotationStatus } from '@/types'
|
||||
|
||||
export interface StatusBadgeProps {
|
||||
status: ImageAnnotationStatus
|
||||
}
|
||||
|
||||
export const StatusBadge: React.FC<StatusBadgeProps> = ({ status }) => {
|
||||
const config: Record<
|
||||
ImageAnnotationStatus,
|
||||
{ label: string; bg: string; text: string; dot: string }
|
||||
> = {
|
||||
unassigned: {
|
||||
label: 'Chưa gán',
|
||||
bg: 'bg-slate-100',
|
||||
text: 'text-slate-600',
|
||||
dot: 'bg-slate-400',
|
||||
},
|
||||
in_progress: {
|
||||
label: 'Đang làm',
|
||||
bg: 'bg-[#FEE2E2]',
|
||||
text: 'text-[#B91C1C]',
|
||||
dot: 'bg-[#EF4444]',
|
||||
},
|
||||
pending_review: {
|
||||
label: 'Chờ duyệt',
|
||||
bg: 'bg-[#FEF3C7]',
|
||||
text: 'text-[#B45309]',
|
||||
dot: 'bg-[#F59E0B]',
|
||||
},
|
||||
completed: {
|
||||
label: 'Hoàn thành',
|
||||
bg: 'bg-[#DCFCE7]',
|
||||
text: 'text-[#15803D]',
|
||||
dot: 'bg-[#22C55E]',
|
||||
},
|
||||
}
|
||||
|
||||
const current = config[status] ?? config.pending_review
|
||||
|
||||
return (
|
||||
<span
|
||||
className={clsx(
|
||||
'inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 text-xs font-semibold',
|
||||
current.bg,
|
||||
current.text
|
||||
)}
|
||||
>
|
||||
<span className={clsx('h-1.5 w-1.5 rounded-full', current.dot)} />
|
||||
<span>{current.label}</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
131
src/pages/auth/ForgotPasswordPage.tsx
Normal file
131
src/pages/auth/ForgotPasswordPage.tsx
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
import React, { useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
export const ForgotPasswordPage: React.FC = () => {
|
||||
const [email, setEmail] = useState('minhanh@visionlab.vn')
|
||||
const [submitted, setSubmitted] = useState(false)
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!email.trim()) return
|
||||
setSubmitted(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-white flex flex-col justify-between p-6 sm:p-12">
|
||||
{/* Header */}
|
||||
<header className="max-w-[1360px] w-full mx-auto flex items-center justify-between">
|
||||
<Link to="/login" className="flex items-center gap-2.5">
|
||||
<div className="w-8 h-8 rounded-lg bg-[#C95C3C] flex items-center justify-center text-white shadow-sm">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M4 8V6a2 2 0 0 1 2-2h2" />
|
||||
<path d="M4 16v2a2 2 0 0 0 2 2h2" />
|
||||
<path d="M16 4h2a2 2 0 0 1 2 2v2" />
|
||||
<path d="M16 20h2a2 2 0 0 0 2-2v-2" />
|
||||
</svg>
|
||||
</div>
|
||||
<span className="text-xl font-bold tracking-tight text-slate-900">
|
||||
danable
|
||||
</span>
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-xs font-semibold text-indigo-600 hover:text-indigo-700"
|
||||
>
|
||||
← Quay lại đăng nhập
|
||||
</Link>
|
||||
</header>
|
||||
|
||||
{/* Main Recovery Card */}
|
||||
<main className="w-full max-w-[420px] mx-auto my-auto py-12">
|
||||
<p className="text-[11px] font-semibold uppercase tracking-[0.08em] text-indigo-600 mb-2">
|
||||
KHÔI PHỤC TÀI KHOẢN
|
||||
</p>
|
||||
<h1 className="text-2xl sm:text-[28px] font-bold text-slate-900 tracking-tight mb-2">
|
||||
Quên mật khẩu?
|
||||
</h1>
|
||||
<p className="text-sm text-slate-500 mb-6">
|
||||
Nhập email công việc của bạn để nhận liên kết đặt lại mật khẩu an toàn.
|
||||
</p>
|
||||
|
||||
{submitted ? (
|
||||
<div className="rounded-2xl border border-emerald-200 bg-emerald-50/70 p-5 space-y-4">
|
||||
<div className="flex items-center gap-2.5 text-emerald-800 font-semibold text-sm">
|
||||
<span className="w-2 h-2 rounded-full bg-emerald-500" />
|
||||
<span>Đã gửi hướng dẫn khôi phục mật khẩu</span>
|
||||
</div>
|
||||
<p className="text-xs text-slate-600 leading-relaxed">
|
||||
Nếu địa chỉ <span className="font-semibold text-slate-800">{email}</span> tồn tại trong không gian nhóm, bạn sẽ nhận được email hướng dẫn trong vòng vài phút.
|
||||
</p>
|
||||
<div className="pt-2 flex items-center justify-between">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSubmitted(false)}
|
||||
className="text-xs font-medium text-slate-600 hover:text-slate-900"
|
||||
>
|
||||
Gửi lại với email khác
|
||||
</button>
|
||||
<Link
|
||||
to="/login"
|
||||
className="px-4 py-2 rounded-xl bg-[#C95C3C] text-white text-xs font-semibold hover:bg-[#B5492B] transition-colors"
|
||||
>
|
||||
Quay lại đăng nhập
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor="recovery-email"
|
||||
className="block text-[13px] font-medium text-slate-800 mb-1.5"
|
||||
>
|
||||
Email công việc
|
||||
</label>
|
||||
<input
|
||||
id="recovery-email"
|
||||
type="email"
|
||||
required
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="minhanh@visionlab.vn"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-slate-200 bg-white text-sm text-slate-900 focus:outline-none focus:border-[#C95C3C] focus:ring-2 focus:ring-[#C95C3C]/15"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full py-3 px-4 rounded-xl bg-[#C95C3C] hover:bg-[#B5492B] text-white text-sm font-semibold transition-colors"
|
||||
>
|
||||
Gửi liên kết đặt lại mật khẩu →
|
||||
</button>
|
||||
|
||||
<div className="text-center pt-2">
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-xs font-medium text-slate-600 hover:text-slate-900"
|
||||
>
|
||||
← Quay lại trang đăng nhập
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</main>
|
||||
|
||||
<footer className="text-center text-xs text-slate-400">
|
||||
© 2026 danable. Dữ liệu của bạn, quyền kiểm soát của bạn.
|
||||
</footer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ForgotPasswordPage
|
||||
151
src/pages/auth/LoginPage.tsx
Normal file
151
src/pages/auth/LoginPage.tsx
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
import React, { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { LoginRequest } from '../../types'
|
||||
import { HeroSection } from './components/HeroSection'
|
||||
import { LoginForm } from './components/LoginForm'
|
||||
|
||||
export const LoginPage: React.FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [contactModalOpen, setContactModalOpen] = useState(false)
|
||||
|
||||
const handleLogin = (_credentials: LoginRequest) => {
|
||||
setIsLoading(true)
|
||||
setTimeout(() => {
|
||||
setIsLoading(false)
|
||||
navigate('/projects')
|
||||
}, 250)
|
||||
}
|
||||
|
||||
const handleSSOLogin = () => {
|
||||
setIsLoading(true)
|
||||
setTimeout(() => {
|
||||
setIsLoading(false)
|
||||
navigate('/projects')
|
||||
}, 250)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-white text-slate-900 flex flex-col justify-between">
|
||||
{/* Top Navigation Bar matching wireframe */}
|
||||
<header className="w-full max-w-[1360px] mx-auto px-6 sm:px-12 pt-7 pb-4 flex items-center justify-between">
|
||||
<div className="flex items-center gap-16">
|
||||
{/* Brand Logo */}
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="w-8 h-8 rounded-lg bg-[#C95C3C] flex items-center justify-center text-white shadow-sm">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M4 8V6a2 2 0 0 1 2-2h2" />
|
||||
<path d="M4 16v2a2 2 0 0 0 2 2h2" />
|
||||
<path d="M16 4h2a2 2 0 0 1 2 2v2" />
|
||||
<path d="M16 20h2a2 2 0 0 0 2-2v-2" />
|
||||
</svg>
|
||||
</div>
|
||||
<span className="text-xl font-bold tracking-tight text-slate-900">
|
||||
danable
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<span className="hidden md:inline-block text-[10px] font-semibold uppercase tracking-[0.14em] text-slate-500">
|
||||
NỀN TẢNG DỮ LIỆU CHO AI
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="text-xs text-slate-500">
|
||||
<span>Chưa có tài khoản? </span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setContactModalOpen(true)}
|
||||
className="font-semibold text-indigo-600 hover:text-indigo-700 inline-flex items-center gap-0.5"
|
||||
>
|
||||
<span>Liên hệ quản trị viên</span>
|
||||
<span aria-hidden="true">↗</span>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Main 2-Column Content */}
|
||||
<main className="w-full max-w-[1360px] mx-auto px-6 sm:px-12 py-6 flex-1 flex items-center">
|
||||
<div className="w-full grid grid-cols-1 lg:grid-cols-12 gap-12 lg:gap-8 items-center">
|
||||
{/* Left Column: HeroSection */}
|
||||
<div className="lg:col-span-6">
|
||||
<HeroSection />
|
||||
</div>
|
||||
|
||||
{/* Right Column: LoginForm */}
|
||||
<div className="lg:col-span-6 flex flex-col items-center">
|
||||
<LoginForm
|
||||
onSubmit={handleLogin}
|
||||
onSSOLogin={handleSSOLogin}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{/* Bottom Footer Links */}
|
||||
<footer className="w-full max-w-[1360px] mx-auto px-6 sm:px-12 py-6 flex flex-col sm:flex-row items-center justify-end gap-6 text-xs text-slate-500">
|
||||
<div className="flex items-center gap-6 lg:w-1/2 justify-center">
|
||||
<a
|
||||
href="#terms"
|
||||
onClick={(e) => e.preventDefault()}
|
||||
className="hover:text-slate-800 transition-colors"
|
||||
>
|
||||
Điều khoản sử dụng
|
||||
</a>
|
||||
<a
|
||||
href="#privacy"
|
||||
onClick={(e) => e.preventDefault()}
|
||||
className="hover:text-slate-800 transition-colors"
|
||||
>
|
||||
Chính sách bảo mật
|
||||
</a>
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex items-center gap-1 hover:text-slate-800 transition-colors"
|
||||
>
|
||||
<span>Tiếng Việt</span>
|
||||
<span className="text-[10px]">∨</span>
|
||||
</button>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
{/* Contact Admin Info Modal */}
|
||||
{contactModalOpen && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/40 backdrop-blur-[1px] p-4">
|
||||
<div className="bg-white rounded-2xl max-w-md w-full p-6 shadow-xl border border-slate-200">
|
||||
<h3 className="text-lg font-bold text-slate-900 mb-2">
|
||||
Liên hệ quản trị viên không gian nhóm
|
||||
</h3>
|
||||
<p className="text-sm text-slate-600 leading-relaxed mb-4">
|
||||
danable hoạt động theo mô hình lời mời nội bộ để đảm bảo an toàn
|
||||
dữ liệu. Vui lòng liên hệ Quản trị viên nhóm của bạn (ví dụ:{' '}
|
||||
<span className="font-medium text-slate-900">
|
||||
minhanh@visionlab.vn
|
||||
</span>
|
||||
) để nhận email lời mời tham gia dự án.
|
||||
</p>
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setContactModalOpen(false)}
|
||||
className="px-4 py-2 rounded-xl bg-[#C95C3C] text-white text-sm font-medium hover:bg-[#B5492B] transition-colors"
|
||||
>
|
||||
Đã hiểu
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LoginPage
|
||||
153
src/pages/auth/components/HeroSection.tsx
Normal file
153
src/pages/auth/components/HeroSection.tsx
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
import React, { useState } from 'react'
|
||||
|
||||
export const HeroSection: React.FC = () => {
|
||||
const [hoveredBox, setHoveredBox] = useState<'bus' | 'car' | null>(null)
|
||||
const [activeTask, setActiveTask] = useState<string>('Object Detection')
|
||||
|
||||
return (
|
||||
<div className="flex flex-col justify-between h-full max-w-[540px]">
|
||||
<div>
|
||||
<p className="text-[11px] font-semibold uppercase tracking-[0.12em] text-slate-600 mb-3">
|
||||
TỪ DỮ LIỆU THÔ ĐẾN NHÃN CHẤT LƯỢNG
|
||||
</p>
|
||||
|
||||
<h1 className="text-4xl sm:text-[42px] font-bold tracking-tight text-slate-900 leading-[1.15] mb-3.5">
|
||||
Giải pháp dữ liệu cho AI
|
||||
</h1>
|
||||
|
||||
<p className="text-[15px] text-slate-600 leading-relaxed mb-7">
|
||||
Kiểm soát chất lượng mô hình AI của bạn từ những bước bắt đầu.
|
||||
</p>
|
||||
|
||||
{/* Interactive Preview Card */}
|
||||
<div className="rounded-2xl border border-slate-300 bg-white shadow-sm overflow-hidden transition-shadow hover:shadow-md">
|
||||
{/* Card Top Bar */}
|
||||
<div className="flex items-center justify-between px-4 py-3 border-b border-slate-200 bg-white">
|
||||
<span className="text-xs font-medium text-slate-700">
|
||||
Giao thông đô thị
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1.5 text-xs font-medium text-slate-600">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-emerald-500" />
|
||||
Đã duyệt thủ công
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Street Traffic Image + Bounding Box Overlays */}
|
||||
<div className="relative h-[265px] sm:h-[285px] w-full overflow-hidden bg-slate-900 select-none">
|
||||
<img
|
||||
src="https://images.unsplash.com/photo-1519003722824-194d4455a60c?auto=format&fit=crop&w=1080&q=85"
|
||||
alt="Giao thông đô thị Việt Nam"
|
||||
className="w-full h-full object-cover object-center brightness-95"
|
||||
/>
|
||||
|
||||
{/* Subtle road scene gradient for crisp bounding box contrast */}
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/25 via-transparent to-black/10 pointer-events-none" />
|
||||
|
||||
{/* Purple Bounding Box: Xe buýt */}
|
||||
<div
|
||||
onMouseEnter={() => setHoveredBox('bus')}
|
||||
onMouseLeave={() => setHoveredBox(null)}
|
||||
style={{
|
||||
left: '28%',
|
||||
top: '35%',
|
||||
width: '20%',
|
||||
height: '31%',
|
||||
}}
|
||||
className={`absolute border-2 transition-all duration-150 cursor-pointer ${
|
||||
hoveredBox === 'bus'
|
||||
? 'border-[#A855F7] bg-[#A855F7]/20 shadow-[0_0_0_2px_rgba(168,85,247,0.3)]'
|
||||
: 'border-[#C084FC] bg-[#A855F7]/10'
|
||||
}`}
|
||||
>
|
||||
<span className="absolute -top-6 left-[-2px] inline-flex items-center px-2 py-0.5 rounded-t-md rounded-br-md bg-[#C084FC] text-slate-950 text-[11px] font-bold shadow-sm whitespace-nowrap">
|
||||
Xe buýt
|
||||
</span>
|
||||
{/* Corner handles */}
|
||||
<span className="absolute -top-1 -left-1 w-2 h-2 bg-white border border-[#A855F7] rounded-full" />
|
||||
<span className="absolute -top-1 -right-1 w-2 h-2 bg-white border border-[#A855F7] rounded-full" />
|
||||
<span className="absolute -bottom-1 -left-1 w-2 h-2 bg-white border border-[#A855F7] rounded-full" />
|
||||
<span className="absolute -bottom-1 -right-1 w-2 h-2 bg-white border border-[#A855F7] rounded-full" />
|
||||
</div>
|
||||
|
||||
{/* Cyan Bounding Box: Ô tô */}
|
||||
<div
|
||||
onMouseEnter={() => setHoveredBox('car')}
|
||||
onMouseLeave={() => setHoveredBox(null)}
|
||||
style={{
|
||||
left: '45.5%',
|
||||
top: '57%',
|
||||
width: '13.5%',
|
||||
height: '24%',
|
||||
}}
|
||||
className={`absolute border-2 transition-all duration-150 cursor-pointer ${
|
||||
hoveredBox === 'car'
|
||||
? 'border-[#06B6D4] bg-[#06B6D4]/25 shadow-[0_0_0_2px_rgba(6,182,212,0.35)]'
|
||||
: 'border-[#22D3EE] bg-[#06B6D4]/10'
|
||||
}`}
|
||||
>
|
||||
<span className="absolute -top-6 left-[-2px] inline-flex items-center px-2 py-0.5 rounded-t-md rounded-br-md bg-[#22D3EE] text-slate-950 text-[11px] font-bold shadow-sm whitespace-nowrap">
|
||||
Ô tô
|
||||
</span>
|
||||
{/* Corner handles */}
|
||||
<span className="absolute -top-1 -left-1 w-2 h-2 bg-white border border-[#06B6D4] rounded-full" />
|
||||
<span className="absolute -top-1 -right-1 w-2 h-2 bg-white border border-[#06B6D4] rounded-full" />
|
||||
<span className="absolute -bottom-1 -left-1 w-2 h-2 bg-white border border-[#06B6D4] rounded-full" />
|
||||
<span className="absolute -bottom-1 -right-1 w-2 h-2 bg-white border border-[#06B6D4] rounded-full" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Card Bottom Stats */}
|
||||
<div className="flex items-center justify-between px-5 py-4 bg-white border-t border-slate-200">
|
||||
<div>
|
||||
<div className="text-xl font-bold text-slate-900 tracking-tight">
|
||||
4.320
|
||||
</div>
|
||||
<div className="text-xs text-slate-500 mt-0.5">
|
||||
ảnh trong không gian nhóm
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-right">
|
||||
<div className="text-xl font-bold text-slate-900 tracking-tight">
|
||||
Bạn quyết định
|
||||
</div>
|
||||
<div className="text-xs text-slate-500 mt-0.5">
|
||||
duyệt nhãn trước khi xuất
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom Task Tags */}
|
||||
<div className="flex items-center gap-6 mt-6">
|
||||
{(['Classification', 'Object Detection', 'Segmentation'] as const).map(
|
||||
(task) => {
|
||||
const isSelected = activeTask === task
|
||||
return (
|
||||
<button
|
||||
key={task}
|
||||
type="button"
|
||||
onClick={() => setActiveTask(task)}
|
||||
className={`text-xs transition-colors ${
|
||||
isSelected
|
||||
? 'font-semibold text-slate-900 underline decoration-[#C95C3C] decoration-2 underline-offset-4'
|
||||
: 'font-medium text-slate-600 hover:text-slate-900'
|
||||
}`}
|
||||
>
|
||||
{task}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer Copyright */}
|
||||
<p className="text-xs text-slate-500 mt-8">
|
||||
© 2026 danable. Dữ liệu của bạn, quyền kiểm soát của bạn.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default HeroSection
|
||||
234
src/pages/auth/components/LoginForm.tsx
Normal file
234
src/pages/auth/components/LoginForm.tsx
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
import React, { useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { LoginRequest } from '../../../types'
|
||||
import { SSOButton } from './SSOButton'
|
||||
|
||||
export interface LoginFormProps {
|
||||
onSubmit: (data: LoginRequest) => void
|
||||
onSSOLogin?: () => void
|
||||
isLoading?: boolean
|
||||
}
|
||||
|
||||
export const LoginForm: React.FC<LoginFormProps> = ({
|
||||
onSubmit,
|
||||
onSSOLogin,
|
||||
isLoading = false,
|
||||
}) => {
|
||||
const [email, setEmail] = useState<string>('minhanh@visionlab.vn')
|
||||
const [password, setPassword] = useState<string>('••••••••••••')
|
||||
const [rememberMe, setRememberMe] = useState<boolean>(true)
|
||||
const [showPassword, setShowPassword] = useState<boolean>(false)
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null)
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!email.trim()) {
|
||||
setErrorMessage('Vui lòng nhập email công việc của bạn.')
|
||||
return
|
||||
}
|
||||
if (!password) {
|
||||
setErrorMessage('Vui lòng nhập mật khẩu.')
|
||||
return
|
||||
}
|
||||
setErrorMessage(null)
|
||||
onSubmit({
|
||||
email: email.trim(),
|
||||
password,
|
||||
rememberMe,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full max-w-[420px] mx-auto">
|
||||
{/* Header */}
|
||||
<div className="mb-6">
|
||||
<p className="text-[11px] font-semibold uppercase tracking-[0.08em] text-indigo-600 mb-2">
|
||||
CHÀO MỪNG TRỞ LẠI
|
||||
</p>
|
||||
<h2 className="text-[28px] font-bold text-slate-900 tracking-tight leading-tight mb-2">
|
||||
Đăng nhập vào danable
|
||||
</h2>
|
||||
<p className="text-sm text-slate-500">
|
||||
Tiếp tục xây dựng bộ dữ liệu tốt hơn, cùng đội ngũ của bạn.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* SSO Button */}
|
||||
<SSOButton onClick={onSSOLogin} isLoading={isLoading} />
|
||||
|
||||
{/* Divider */}
|
||||
<div className="relative flex items-center justify-center my-6">
|
||||
<div className="w-full border-t border-slate-200" />
|
||||
<span className="bg-white px-3 text-xs text-slate-400 whitespace-nowrap">
|
||||
hoặc sử dụng email
|
||||
</span>
|
||||
<div className="w-full border-t border-slate-200" />
|
||||
</div>
|
||||
|
||||
{/* Error Alert */}
|
||||
{errorMessage && (
|
||||
<div className="mb-4 px-3.5 py-2.5 rounded-lg bg-red-50 border border-red-200 text-xs text-red-700">
|
||||
{errorMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Form */}
|
||||
<form onSubmit={handleSubmit} className="space-y-4" noValidate>
|
||||
{/* Email Field */}
|
||||
<div>
|
||||
<label
|
||||
htmlFor="work-email"
|
||||
className="block text-[13px] font-medium text-slate-800 mb-1.5"
|
||||
>
|
||||
Email công việc
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<rect x="2" y="4" width="20" height="16" rx="2" />
|
||||
<path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" />
|
||||
</svg>
|
||||
</span>
|
||||
<input
|
||||
id="work-email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="name@company.vn"
|
||||
className="w-full pl-10 pr-4 py-2.5 rounded-xl border border-slate-200 bg-white text-sm text-slate-900 placeholder:text-slate-400 focus:outline-none focus:border-[#C95C3C] focus:ring-2 focus:ring-[#C95C3C]/15 transition-all"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Password Field */}
|
||||
<div>
|
||||
<label
|
||||
htmlFor="work-password"
|
||||
className="block text-[13px] font-medium text-slate-800 mb-1.5"
|
||||
>
|
||||
Mật khẩu
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<rect x="3" y="11" width="18" height="11" rx="2" ry="2" />
|
||||
<path d="M7 11V7a5 5 0 0 1 10 0v4" />
|
||||
</svg>
|
||||
</span>
|
||||
<input
|
||||
id="work-password"
|
||||
type={showPassword ? 'text' : 'password'}
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Nhập mật khẩu"
|
||||
className="w-full pl-10 pr-10 py-2.5 rounded-xl border border-slate-200 bg-white text-sm text-slate-900 placeholder:text-slate-400 focus:outline-none focus:border-[#C95C3C] focus:ring-2 focus:ring-[#C95C3C]/15 transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowPassword((prev) => !prev)}
|
||||
aria-label={showPassword ? 'Ẩn mật khẩu' : 'Hiện mật khẩu'}
|
||||
className="absolute inset-y-0 right-0 pr-3.5 flex items-center text-slate-500 hover:text-slate-700"
|
||||
>
|
||||
{showPassword ? (
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M9.88 9.88a3 3 0 1 0 4.24 4.24" />
|
||||
<path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68" />
|
||||
<path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61" />
|
||||
<line x1="2" x2="22" y1="2" y2="22" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Remember Me & Forgot Password */}
|
||||
<div className="flex items-center justify-between pt-1">
|
||||
<label className="inline-flex items-center gap-2 cursor-pointer select-none">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={rememberMe}
|
||||
onChange={(e) => setRememberMe(e.target.checked)}
|
||||
className="w-4 h-4 rounded border-slate-300 text-slate-700 focus:ring-slate-500 accent-slate-600"
|
||||
/>
|
||||
<span className="text-xs text-slate-600">Ghi nhớ đăng nhập</span>
|
||||
</label>
|
||||
|
||||
<Link
|
||||
to="/forgot-password"
|
||||
className="text-xs font-medium text-indigo-600 hover:text-indigo-700 hover:underline"
|
||||
>
|
||||
Quên mật khẩu?
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Terracotta Submit Button */}
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading}
|
||||
className="w-full flex items-center justify-center gap-2 py-3 px-4 rounded-xl bg-[#C95C3C] hover:bg-[#B5492B] active:bg-[#A03E22] text-white text-sm font-semibold shadow-sm transition-colors disabled:opacity-60 mt-2"
|
||||
>
|
||||
<span>{isLoading ? 'Đang đăng nhập...' : 'Đăng nhập'}</span>
|
||||
<span aria-hidden="true" className="text-base leading-none">
|
||||
→
|
||||
</span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{/* Security Badge */}
|
||||
<div className="flex items-center justify-center gap-1.5 mt-5 text-xs text-slate-500">
|
||||
<svg
|
||||
className="w-3.5 h-3.5 text-slate-500 shrink-0"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10" />
|
||||
<path d="m9 12 2 2 4-4" />
|
||||
</svg>
|
||||
<span>Kết nối được mã hóa. Dữ liệu luôn riêng tư.</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LoginForm
|
||||
46
src/pages/auth/components/SSOButton.tsx
Normal file
46
src/pages/auth/components/SSOButton.tsx
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import React from 'react'
|
||||
|
||||
export interface SSOButtonProps {
|
||||
onClick?: () => void
|
||||
isLoading?: boolean
|
||||
}
|
||||
|
||||
export const SSOButton: React.FC<SSOButtonProps> = ({
|
||||
onClick,
|
||||
isLoading = false,
|
||||
}) => {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
disabled={isLoading}
|
||||
className="w-full flex items-center justify-center gap-2.5 px-4 py-3 rounded-xl border border-slate-200 bg-white text-slate-800 text-sm font-medium hover:bg-slate-50 hover:border-slate-300 active:bg-slate-100 transition-all disabled:opacity-60"
|
||||
>
|
||||
{/* Building Icon */}
|
||||
<svg
|
||||
className="w-4 h-4 text-slate-600 shrink-0"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<rect x="4" y="2" width="16" height="20" rx="2" ry="2" />
|
||||
<path d="M9 22v-4h6v4" />
|
||||
<path d="M8 6h.01" />
|
||||
<path d="M16 6h.01" />
|
||||
<path d="M12 6h.01" />
|
||||
<path d="M12 10h.01" />
|
||||
<path d="M12 14h.01" />
|
||||
<path d="M16 10h.01" />
|
||||
<path d="M16 14h.01" />
|
||||
<path d="M8 10h.01" />
|
||||
<path d="M8 14h.01" />
|
||||
</svg>
|
||||
<span>Đăng nhập bằng SSO công ty</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
export default SSOButton
|
||||
205
src/pages/projects/ProjectDetailPage.tsx
Normal file
205
src/pages/projects/ProjectDetailPage.tsx
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
import React, { useState, useEffect, useRef } from 'react'
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { TaskType } from '@/types'
|
||||
import {
|
||||
OverviewTab,
|
||||
DataTab,
|
||||
LabelsTab,
|
||||
MembersTab,
|
||||
SettingsTab,
|
||||
} from './components'
|
||||
import {
|
||||
getProjectById,
|
||||
getProjectImages,
|
||||
addUploadedImagesToProject,
|
||||
updateProjectClasses,
|
||||
updateProjectMembers,
|
||||
updateProject,
|
||||
deleteProjectById,
|
||||
subscribeProjectsStore,
|
||||
} from './projectData'
|
||||
|
||||
type DetailTabKey = 'overview' | 'data' | 'labels' | 'members' | 'settings'
|
||||
|
||||
const TASK_DISPLAY_NAME: Record<TaskType, string> = {
|
||||
classification: 'Classification',
|
||||
object_detection: 'Object Detection',
|
||||
segmentation: 'Segmentation',
|
||||
}
|
||||
|
||||
const TABS: Array<{ key: DetailTabKey; label: string }> = [
|
||||
{ key: 'overview', label: 'Tổng quan' },
|
||||
{ key: 'data', label: 'Dữ liệu' },
|
||||
{ key: 'labels', label: 'Lớp nhãn' },
|
||||
{ key: 'members', label: 'Thành viên' },
|
||||
{ key: 'settings', label: 'Cài đặt' },
|
||||
]
|
||||
|
||||
export const ProjectDetailPage: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null)
|
||||
|
||||
const [activeTab, setActiveTab] = useState<DetailTabKey>('overview')
|
||||
const [project, setProject] = useState(() => getProjectById(id))
|
||||
const [images, setImages] = useState(() => getProjectImages(project.id))
|
||||
|
||||
useEffect(() => {
|
||||
const current = getProjectById(id)
|
||||
setProject(current)
|
||||
setImages(getProjectImages(current.id))
|
||||
}, [id])
|
||||
|
||||
useEffect(() => {
|
||||
return subscribeProjectsStore(() => {
|
||||
const current = getProjectById(id)
|
||||
setProject(current)
|
||||
setImages(getProjectImages(current.id))
|
||||
})
|
||||
}, [id])
|
||||
|
||||
const handleUploadFiles = (fileList: FileList | null) => {
|
||||
if (!fileList || fileList.length === 0) return
|
||||
const names = Array.from(fileList).map((f) => f.name)
|
||||
addUploadedImagesToProject(project.id, names)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Hidden file input for header "↑ Tải ảnh lên" button */}
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple
|
||||
className="hidden"
|
||||
onChange={(e) => handleUploadFiles(e.target.files)}
|
||||
/>
|
||||
|
||||
{/* Top Header matching MVP · Project dashboard.png */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-[28px] font-bold leading-tight tracking-tight text-slate-900">
|
||||
{project.name}
|
||||
</h1>
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
<span className="font-mono text-slate-600">{project.slug}</span>
|
||||
{' · '}
|
||||
<span>{TASK_DISPLAY_NAME[project.taskType]}</span>
|
||||
{' · '}
|
||||
<span>{project.stats.totalImages.toLocaleString('vi-VN')} ảnh</span>
|
||||
{' · '}
|
||||
<span>{project.updatedAt}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="inline-flex h-10 items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 text-xs font-bold text-slate-800 shadow-sm transition hover:bg-slate-50"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4 text-slate-700"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M4 16v2a2 2 0 002 2h12a2 2 0 002-2v-2M16 8l-4-4m0 0L8 8m4-4v12"
|
||||
/>
|
||||
</svg>
|
||||
<span>Tải ảnh lên</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => navigate(`/projects/${project.id}/annotate`)}
|
||||
className="inline-flex h-10 items-center gap-2 rounded-xl bg-[#C95C3C] px-5 text-xs font-bold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
<span>↗</span>
|
||||
<span>Mở giao diện gán nhãn</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tabs navigation matching MVP · Project dashboard.png */}
|
||||
<div className="border-b border-slate-200">
|
||||
<nav className="-mb-px flex flex-wrap gap-6">
|
||||
{TABS.map((tab) => {
|
||||
const isActive = activeTab === tab.key
|
||||
return (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => setActiveTab(tab.key)}
|
||||
className={`border-b-2 pb-2.5 text-xs font-semibold transition ${
|
||||
isActive
|
||||
? 'border-indigo-600 text-indigo-600'
|
||||
: 'border-transparent text-slate-500 hover:border-slate-300 hover:text-slate-800'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{/* Tab Content */}
|
||||
<div className="pt-1">
|
||||
{activeTab === 'overview' && (
|
||||
<OverviewTab
|
||||
project={project}
|
||||
images={images}
|
||||
onSwitchTab={(tab) => setActiveTab(tab)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'data' && (
|
||||
<DataTab
|
||||
project={project}
|
||||
images={images}
|
||||
onUploadImages={(names) => addUploadedImagesToProject(project.id, names)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'labels' && (
|
||||
<LabelsTab
|
||||
classes={project.classes}
|
||||
onUpdateClasses={(classes) => updateProjectClasses(project.id, classes)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'members' && (
|
||||
<MembersTab
|
||||
members={project.members}
|
||||
onUpdateMembers={(members) => updateProjectMembers(project.id, members)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'settings' && (
|
||||
<SettingsTab
|
||||
project={project}
|
||||
onSaveSettings={(updates) =>
|
||||
updateProject(project.id, (p) => ({
|
||||
...p,
|
||||
name: updates.name,
|
||||
slug: updates.slug,
|
||||
description: updates.description,
|
||||
taskType: updates.taskType,
|
||||
updatedAt: 'Vừa cập nhật',
|
||||
}))
|
||||
}
|
||||
onDeleteProject={() => deleteProjectById(project.id)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProjectDetailPage
|
||||
164
src/pages/projects/ProjectListPage.tsx
Normal file
164
src/pages/projects/ProjectListPage.tsx
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
import React, { useState, useEffect, useMemo } from 'react'
|
||||
import { CreateProjectInput, ProjectStatus, TaskType } from '@/types'
|
||||
import {
|
||||
ProjectStatsCards,
|
||||
ProjectFilters,
|
||||
ProjectCard,
|
||||
ActivityFeed,
|
||||
CreateProjectModal,
|
||||
} from './components'
|
||||
import {
|
||||
getProjects,
|
||||
getActivities,
|
||||
addProject,
|
||||
deleteProjectById,
|
||||
subscribeProjectsStore,
|
||||
} from './projectData'
|
||||
|
||||
export const ProjectListPage: React.FC = () => {
|
||||
const [projects, setProjects] = useState(() => getProjects())
|
||||
const [activities, setActivities] = useState(() => getActivities())
|
||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false)
|
||||
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [selectedTaskType, setSelectedTaskType] = useState<'all' | TaskType>('all')
|
||||
const [selectedStatus, setSelectedStatus] = useState<'all' | ProjectStatus>('all')
|
||||
const [sortBy, setSortBy] = useState<'updated' | 'name' | 'progress'>('updated')
|
||||
const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid')
|
||||
|
||||
useEffect(() => {
|
||||
return subscribeProjectsStore(() => {
|
||||
setProjects(getProjects())
|
||||
setActivities(getActivities())
|
||||
})
|
||||
}, [])
|
||||
|
||||
const filteredProjects = useMemo(() => {
|
||||
const list = projects.filter((proj) => {
|
||||
const q = searchQuery.trim().toLowerCase()
|
||||
const matchesSearch =
|
||||
!q ||
|
||||
proj.name.toLowerCase().includes(q) ||
|
||||
proj.slug.toLowerCase().includes(q) ||
|
||||
proj.description.toLowerCase().includes(q)
|
||||
const matchesTask =
|
||||
selectedTaskType === 'all' || proj.taskType === selectedTaskType
|
||||
const matchesStatus =
|
||||
selectedStatus === 'all' || proj.status === selectedStatus
|
||||
|
||||
return matchesSearch && matchesTask && matchesStatus
|
||||
})
|
||||
|
||||
if (sortBy === 'name') {
|
||||
return [...list].sort((a, b) => a.name.localeCompare(b.name, 'vi'))
|
||||
}
|
||||
if (sortBy === 'progress') {
|
||||
return [...list].sort((a, b) => {
|
||||
const progA =
|
||||
a.stats.totalImages > 0
|
||||
? (a.stats.completed + a.stats.pendingReview) / a.stats.totalImages
|
||||
: 0
|
||||
const progB =
|
||||
b.stats.totalImages > 0
|
||||
? (b.stats.completed + b.stats.pendingReview) / b.stats.totalImages
|
||||
: 0
|
||||
return progB - progA
|
||||
})
|
||||
}
|
||||
return list
|
||||
}, [projects, searchQuery, selectedTaskType, selectedStatus, sortBy])
|
||||
|
||||
const handleCreateProject = (input: CreateProjectInput) => {
|
||||
addProject(input)
|
||||
}
|
||||
|
||||
const handleDeleteProject = (projectId: string) => {
|
||||
deleteProjectById(projectId)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Page Header matching MVP · Quản lý dự án.png */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-[28px] font-bold leading-tight tracking-tight text-slate-900">
|
||||
Dự án của bạn
|
||||
</h1>
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
Quản lý dữ liệu, phân công gán nhãn và kiểm soát chất lượng trong một nơi.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsCreateModalOpen(true)}
|
||||
className="inline-flex items-center gap-2 rounded-xl bg-[#C95C3C] px-4 py-2.5 text-xs font-semibold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
<span className="text-base leading-none">+</span>
|
||||
<span>Tạo dự án</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 4 Summary Cards */}
|
||||
<ProjectStatsCards projects={projects} />
|
||||
|
||||
{/* Filter Bar */}
|
||||
<ProjectFilters
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={setSearchQuery}
|
||||
selectedTaskType={selectedTaskType}
|
||||
onTaskTypeChange={setSelectedTaskType}
|
||||
selectedStatus={selectedStatus}
|
||||
onStatusChange={setSelectedStatus}
|
||||
sortBy={sortBy}
|
||||
onSortChange={setSortBy}
|
||||
viewMode={viewMode}
|
||||
onViewModeChange={setViewMode}
|
||||
/>
|
||||
|
||||
{/* Project Cards Grid / List */}
|
||||
{filteredProjects.length === 0 ? (
|
||||
<div className="rounded-2xl border border-slate-200/80 bg-white py-14 text-center">
|
||||
<p className="text-sm font-semibold text-slate-700">
|
||||
Không tìm thấy dự án phù hợp
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-slate-400">
|
||||
Hãy thử thay đổi từ khóa tìm kiếm hoặc tạo dự án mới.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className={
|
||||
viewMode === 'grid'
|
||||
? 'grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3'
|
||||
: 'grid grid-cols-1 gap-4'
|
||||
}
|
||||
>
|
||||
{filteredProjects.map((project) => (
|
||||
<ProjectCard
|
||||
key={project.id}
|
||||
project={project}
|
||||
onDelete={handleDeleteProject}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Activity Feed Bar */}
|
||||
<ActivityFeed
|
||||
activities={activities}
|
||||
totalCount={projects.length}
|
||||
visibleCount={filteredProjects.length}
|
||||
/>
|
||||
|
||||
{/* Create Project Modal */}
|
||||
<CreateProjectModal
|
||||
isOpen={isCreateModalOpen}
|
||||
onClose={() => setIsCreateModalOpen(false)}
|
||||
onCreate={handleCreateProject}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProjectListPage
|
||||
66
src/pages/projects/components/ActivityFeed.tsx
Normal file
66
src/pages/projects/components/ActivityFeed.tsx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import React, { useState } from 'react'
|
||||
import { ActivityLog } from '@/types'
|
||||
|
||||
interface ActivityFeedProps {
|
||||
activities: ActivityLog[]
|
||||
totalCount?: number
|
||||
visibleCount?: number
|
||||
}
|
||||
|
||||
export const ActivityFeed: React.FC<ActivityFeedProps> = ({
|
||||
activities,
|
||||
totalCount = 3,
|
||||
visibleCount = 3,
|
||||
}) => {
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const displayed = expanded ? activities : activities.slice(0, 2)
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{/* Main Activity Bar matching wireframe */}
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-slate-200/80 bg-white px-5 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.02)]">
|
||||
<div className="flex flex-wrap items-center gap-6 text-xs text-slate-500">
|
||||
{/* Pulse / Waveform icon */}
|
||||
<svg
|
||||
className="h-4 w-4 text-slate-400 shrink-0"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M3 12h4l3-8 4 16 3-8h4"
|
||||
/>
|
||||
</svg>
|
||||
|
||||
{displayed.map((act) => (
|
||||
<span key={act.id} className="inline-flex items-center gap-1 text-slate-500">
|
||||
<span className="font-medium text-slate-600">{act.timestamp}</span>
|
||||
<span>·</span>
|
||||
<span className="font-medium text-slate-700">{act.userName}</span>
|
||||
<span>{act.actionText}</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setExpanded((prev) => !prev)}
|
||||
className="text-xs font-semibold text-indigo-600 hover:text-indigo-700 transition"
|
||||
>
|
||||
{expanded ? 'Thu gọn ↑' : 'Xem tất cả →'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Bottom caption line matching wireframe */}
|
||||
<div className="flex items-center justify-between px-1 text-[11px] text-slate-400">
|
||||
<span>
|
||||
Hiển thị {visibleCount} / {totalCount} dự án trong danable
|
||||
</span>
|
||||
<span>Nhãn được lưu theo từng dự án</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
125
src/pages/projects/components/CreateProjectModal.tsx
Normal file
125
src/pages/projects/components/CreateProjectModal.tsx
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
import React, { useState } from 'react'
|
||||
import { CreateProjectInput, TaskType } from '@/types'
|
||||
import { TaskTypeSelector } from './TaskTypeSelector'
|
||||
|
||||
interface CreateProjectModalProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
onCreate: (input: CreateProjectInput) => void
|
||||
}
|
||||
|
||||
export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
onCreate,
|
||||
}) => {
|
||||
const [name, setName] = useState('')
|
||||
const [description, setDescription] = useState('')
|
||||
const [taskType, setTaskType] = useState<TaskType>('classification')
|
||||
const [error, setError] = useState('')
|
||||
|
||||
if (!isOpen) return null
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!name.trim()) {
|
||||
setError('Vui lòng nhập tên dự án')
|
||||
return
|
||||
}
|
||||
onCreate({
|
||||
name: name.trim(),
|
||||
description: description.trim() || 'Dự án gán nhãn dữ liệu hình ảnh',
|
||||
taskType,
|
||||
})
|
||||
setName('')
|
||||
setDescription('')
|
||||
setTaskType('classification')
|
||||
setError('')
|
||||
onClose()
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/55 p-4 backdrop-blur-[1px]"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className="w-full max-w-[500px] rounded-2xl bg-white p-7 shadow-2xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* Header matching MVP · Tạo dự án.png */}
|
||||
<div>
|
||||
<p className="text-[26px] font-extrabold uppercase leading-none tracking-tight text-[#6336F5]">
|
||||
DỰ ÁN MỚI
|
||||
</p>
|
||||
<h2 className="mt-2.5 text-xl font-bold text-slate-900">Tạo dự án mới</h2>
|
||||
<p className="mt-1.5 text-xs text-slate-500">
|
||||
Thiết lập bộ dữ liệu và bài toán gán nhãn trước khi tải ảnh lên.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="mt-5 space-y-4">
|
||||
{/* Tên dự án */}
|
||||
<div
|
||||
className={`rounded-xl border px-3.5 py-2.5 transition focus-within:border-indigo-500 focus-within:ring-2 focus-within:ring-indigo-500/15 ${
|
||||
error ? 'border-rose-400' : 'border-slate-200'
|
||||
}`}
|
||||
>
|
||||
<label className="block text-xs font-semibold text-slate-800">
|
||||
Tên dự án
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => {
|
||||
setName(e.target.value)
|
||||
if (error) setError('')
|
||||
}}
|
||||
placeholder="e.g. City Streets"
|
||||
className="mt-0.5 w-full border-none bg-transparent p-0 text-sm text-slate-900 placeholder:text-slate-400 focus:outline-none"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
{error && <p className="text-xs font-medium text-rose-600">{error}</p>}
|
||||
|
||||
{/* Mô tả */}
|
||||
<div className="rounded-xl border border-slate-200 px-3.5 py-2.5 transition focus-within:border-indigo-500 focus-within:ring-2 focus-within:ring-indigo-500/15">
|
||||
<label className="block text-xs font-semibold text-slate-800">
|
||||
Mô tả
|
||||
</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="Dự án này sẽ gán nhãn cho nội dung gì?"
|
||||
className="mt-1 w-full resize-none border-none bg-transparent p-0 text-sm text-slate-900 placeholder:text-slate-400 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Bài toán gán nhãn */}
|
||||
<div className="pt-1">
|
||||
<h3 className="mb-3 text-xl font-bold text-slate-900">Bài toán gán nhãn</h3>
|
||||
<TaskTypeSelector value={taskType} onChange={setTaskType} />
|
||||
</div>
|
||||
|
||||
{/* Footer actions */}
|
||||
<div className="flex items-center justify-between pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="rounded-xl border border-slate-200 bg-white px-6 py-2.5 text-xs font-semibold text-slate-700 transition hover:bg-slate-50"
|
||||
>
|
||||
Hủy
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-xl bg-[#C95C3C] px-9 py-2.5 text-xs font-semibold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
Tạo dự án
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
301
src/pages/projects/components/ProjectCard.tsx
Normal file
301
src/pages/projects/components/ProjectCard.tsx
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
import React, { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Project, TaskType } from '@/types'
|
||||
|
||||
interface ProjectCardProps {
|
||||
project: Project
|
||||
onDelete?: (projectId: string) => void
|
||||
}
|
||||
|
||||
const TASK_BADGE_CONFIG: Record<
|
||||
TaskType,
|
||||
{ label: string; icon: React.ReactNode }
|
||||
> = {
|
||||
classification: {
|
||||
label: 'Classification',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5 text-slate-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
object_detection: {
|
||||
label: 'Object Detection',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5 text-slate-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M4 8V5a1 1 0 011-1h3M16 4h3a1 1 0 011 1v3M20 16v3a1 1 0 01-1 1h-3M8 20H5a1 1 0 01-1-1v-3" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
segmentation: {
|
||||
label: 'Segmentation',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5 text-slate-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<polygon points="12 3 20 8.5 17 19 7 19 4 8.5" strokeLinecap="round" strokeLinejoin="round" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
export const ProjectCard: React.FC<ProjectCardProps> = ({ project, onDelete }) => {
|
||||
const navigate = useNavigate()
|
||||
const [menuOpen, setMenuOpen] = useState(false)
|
||||
|
||||
const badge = TASK_BADGE_CONFIG[project.taskType]
|
||||
const annotatedCount = project.stats.completed + project.stats.pendingReview
|
||||
const progressPercent =
|
||||
project.stats.totalImages > 0
|
||||
? Math.round((annotatedCount / project.stats.totalImages) * 100)
|
||||
: 0
|
||||
|
||||
const formatNum = (n: number) => n.toLocaleString('vi-VN')
|
||||
|
||||
const isPendingReviewHighlight =
|
||||
project.status === 'pending_review' && project.stats.pendingReview > 0
|
||||
|
||||
const displayMembers = project.members.slice(0, 3)
|
||||
|
||||
const handleOpenOverview = () => {
|
||||
navigate(`/projects/${project.id}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={handleOpenOverview}
|
||||
className="group relative flex cursor-pointer flex-col overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-[0_1px_3px_rgba(15,23,42,0.04)] transition-all duration-200 hover:-translate-y-0.5 hover:border-slate-300 hover:shadow-md"
|
||||
>
|
||||
{/* Top Thumbnail with decorative overlays */}
|
||||
<div className="relative h-44 w-full overflow-hidden bg-slate-100">
|
||||
<img
|
||||
src={project.thumbnailUrl}
|
||||
alt={project.name}
|
||||
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.02]"
|
||||
/>
|
||||
|
||||
{/* Decorative Bounding Box overlay for Object Detection */}
|
||||
{project.taskType === 'object_detection' && (
|
||||
<svg
|
||||
className="pointer-events-none absolute inset-0 h-full w-full"
|
||||
viewBox="0 0 400 180"
|
||||
preserveAspectRatio="none"
|
||||
>
|
||||
{/* Cyan bbox around car */}
|
||||
<rect
|
||||
x="105"
|
||||
y="72"
|
||||
width="66"
|
||||
height="48"
|
||||
fill="rgba(6, 182, 212, 0.14)"
|
||||
stroke="#06B6D4"
|
||||
strokeWidth="2"
|
||||
rx="2"
|
||||
/>
|
||||
<rect x="105" y="61" width="32" height="11" fill="#06B6D4" rx="1.5" />
|
||||
<text x="109" y="69" fill="#ffffff" fontSize="7.5" fontWeight="600">
|
||||
Ô tô
|
||||
</text>
|
||||
|
||||
{/* Red/Orange bbox around bus */}
|
||||
<rect
|
||||
x="212"
|
||||
y="34"
|
||||
width="124"
|
||||
height="84"
|
||||
fill="rgba(239, 68, 68, 0.14)"
|
||||
stroke="#EF4444"
|
||||
strokeWidth="2"
|
||||
rx="2"
|
||||
/>
|
||||
<rect x="212" y="23" width="44" height="11" fill="#EF4444" rx="1.5" />
|
||||
<text x="216" y="31" fill="#ffffff" fontSize="7.5" fontWeight="600">
|
||||
Xe buýt
|
||||
</text>
|
||||
|
||||
{/* Amber bbox around motorbike */}
|
||||
<rect
|
||||
x="248"
|
||||
y="112"
|
||||
width="34"
|
||||
height="52"
|
||||
fill="rgba(245, 158, 11, 0.16)"
|
||||
stroke="#F59E0B"
|
||||
strokeWidth="1.8"
|
||||
rx="2"
|
||||
/>
|
||||
<rect
|
||||
x="298"
|
||||
y="108"
|
||||
width="36"
|
||||
height="56"
|
||||
fill="rgba(34, 197, 94, 0.16)"
|
||||
stroke="#22C55E"
|
||||
strokeWidth="1.8"
|
||||
rx="2"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
|
||||
{/* Decorative Polygon Mask overlay for Segmentation */}
|
||||
{project.taskType === 'segmentation' && (
|
||||
<svg
|
||||
className="pointer-events-none absolute inset-0 h-full w-full"
|
||||
viewBox="0 0 400 180"
|
||||
preserveAspectRatio="none"
|
||||
>
|
||||
{/* Cyan polygon mask on car */}
|
||||
<polygon
|
||||
points="110,94 122,74 156,74 168,92 166,118 108,118"
|
||||
fill="rgba(6, 182, 212, 0.36)"
|
||||
stroke="#22D3EE"
|
||||
strokeWidth="2"
|
||||
/>
|
||||
{/* Red/Coral polygon mask on bus */}
|
||||
<polygon
|
||||
points="216,42 292,35 334,54 334,114 276,118 216,96"
|
||||
fill="rgba(239, 68, 68, 0.35)"
|
||||
stroke="#F87171"
|
||||
strokeWidth="2"
|
||||
/>
|
||||
{/* Green polygon masks on motorbikes */}
|
||||
<polygon
|
||||
points="254,124 268,112 280,128 276,162 252,160"
|
||||
fill="rgba(34, 197, 94, 0.38)"
|
||||
stroke="#4ADE80"
|
||||
strokeWidth="1.8"
|
||||
/>
|
||||
<polygon
|
||||
points="304,118 318,108 332,126 328,162 302,160"
|
||||
fill="rgba(168, 85, 247, 0.38)"
|
||||
stroke="#C084FC"
|
||||
strokeWidth="1.8"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
|
||||
{/* Top-left Task Badge */}
|
||||
<div className="absolute left-3.5 top-3.5 inline-flex items-center gap-1.5 rounded-lg bg-white/95 px-2.5 py-1 text-xs font-semibold text-slate-800 shadow-sm backdrop-blur-sm">
|
||||
{badge.icon}
|
||||
<span>{badge.label}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Card Content */}
|
||||
<div className="flex flex-1 flex-col p-5">
|
||||
{/* Title + 3-dots menu */}
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<h3 className="text-lg font-bold text-slate-900 group-hover:text-[#C95C3C] transition-colors">
|
||||
{project.name}
|
||||
</h3>
|
||||
<div className="relative" onClick={(e) => e.stopPropagation()}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMenuOpen((prev) => !prev)}
|
||||
className="flex h-7 w-7 items-center justify-center rounded-lg text-slate-400 hover:bg-slate-100 hover:text-slate-600"
|
||||
aria-label="Tùy chọn dự án"
|
||||
>
|
||||
<svg className="h-4 w-4" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M6 10a2 2 0 11-4 0 2 2 0 014 0zm6 0a2 2 0 11-4 0 2 2 0 014 0zm6 0a2 2 0 11-4 0 2 2 0 014 0z" />
|
||||
</svg>
|
||||
</button>
|
||||
{menuOpen && (
|
||||
<div className="absolute right-0 top-8 z-20 w-44 rounded-xl border border-slate-200 bg-white py-1.5 shadow-lg">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMenuOpen(false)
|
||||
navigate(`/projects/${project.id}`)
|
||||
}}
|
||||
className="flex w-full items-center px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
Mở tổng quan dự án
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMenuOpen(false)
|
||||
navigate(`/projects/${project.id}/annotate`)
|
||||
}}
|
||||
className="flex w-full items-center px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
Mở giao diện gán nhãn
|
||||
</button>
|
||||
{onDelete && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMenuOpen(false)
|
||||
onDelete(project.id)
|
||||
}}
|
||||
className="flex w-full items-center px-3.5 py-2 text-left text-xs font-medium text-rose-600 hover:bg-rose-50"
|
||||
>
|
||||
Xóa dự án
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description & Monospace Slug */}
|
||||
<p className="mt-1 text-xs text-slate-500">{project.description}</p>
|
||||
<p className="mt-2 font-mono text-[11px] text-slate-400">{project.slug}</p>
|
||||
|
||||
{/* Image count & class count */}
|
||||
<div className="mt-3.5 flex items-center gap-3 text-xs font-medium text-slate-600">
|
||||
<span>{formatNum(project.stats.totalImages)} ảnh</span>
|
||||
<span>{project.classes.length} lớp</span>
|
||||
</div>
|
||||
|
||||
{/* Progress text & bar */}
|
||||
<div className="mt-3">
|
||||
<div className="flex items-center justify-between text-xs">
|
||||
<span className="text-slate-500">{formatNum(annotatedCount)} đã gán nhãn</span>
|
||||
<span className="font-bold text-indigo-600">{progressPercent}%</span>
|
||||
</div>
|
||||
<div className="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-slate-100">
|
||||
<div
|
||||
className="h-full rounded-full bg-[#C95C3C] transition-all duration-300"
|
||||
style={{ width: `${Math.min(100, Math.max(0, progressPercent))}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Status Pill & Member Avatar Stack */}
|
||||
<div className="mt-4 flex items-center justify-between">
|
||||
{isPendingReviewHighlight ? (
|
||||
<span className="inline-flex items-center gap-1.5 rounded-full bg-[#FEF3C7] px-3 py-1 text-xs font-semibold text-[#B45309]">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-[#F59E0B]" />
|
||||
{formatNum(project.stats.pendingReview)} ảnh chờ duyệt
|
||||
</span>
|
||||
) : (
|
||||
<span className="inline-flex items-center gap-1.5 rounded-full bg-[#FEE2E2]/80 px-3 py-1 text-xs font-semibold text-[#B91C1C]">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-[#EF4444]" />
|
||||
Đang gán nhãn
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div className="flex items-center -space-x-1.5">
|
||||
{displayMembers.map((member) => (
|
||||
<div
|
||||
key={member.id}
|
||||
title={member.name}
|
||||
style={{ backgroundColor: member.color }}
|
||||
className="flex h-6 w-6 items-center justify-center rounded-full border-2 border-white text-[10px] font-bold text-slate-700"
|
||||
>
|
||||
{member.initials}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Divider + Footer */}
|
||||
<div className="mt-4 flex items-center justify-between border-t border-slate-100 pt-3.5 text-xs">
|
||||
<span className="text-slate-400">{project.updatedAt}</span>
|
||||
<span className="inline-flex items-center gap-1 font-semibold text-indigo-600 group-hover:translate-x-0.5 transition-transform">
|
||||
Mở tổng quan →
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
148
src/pages/projects/components/ProjectFilters.tsx
Normal file
148
src/pages/projects/components/ProjectFilters.tsx
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
import React from 'react'
|
||||
import { TaskType, ProjectStatus } from '@/types'
|
||||
|
||||
interface ProjectFiltersProps {
|
||||
searchQuery: string
|
||||
onSearchChange: (val: string) => void
|
||||
selectedTaskType: 'all' | TaskType
|
||||
onTaskTypeChange: (val: 'all' | TaskType) => void
|
||||
selectedStatus: 'all' | ProjectStatus
|
||||
onStatusChange: (val: 'all' | ProjectStatus) => void
|
||||
sortBy: 'updated' | 'name' | 'progress'
|
||||
onSortChange: (val: 'updated' | 'name' | 'progress') => void
|
||||
viewMode: 'grid' | 'list'
|
||||
onViewModeChange: (val: 'grid' | 'list') => void
|
||||
}
|
||||
|
||||
export const ProjectFilters: React.FC<ProjectFiltersProps> = ({
|
||||
searchQuery,
|
||||
onSearchChange,
|
||||
selectedTaskType,
|
||||
onTaskTypeChange,
|
||||
selectedStatus,
|
||||
onStatusChange,
|
||||
sortBy,
|
||||
onSortChange,
|
||||
viewMode,
|
||||
onViewModeChange,
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{/* Search Input */}
|
||||
<div className="relative w-full sm:w-80">
|
||||
<svg
|
||||
className="pointer-events-none absolute left-3.5 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M21 21l-4.35-4.35m0 0A7.5 7.5 0 104.5 4.5a7.5 7.5 0 0012.15 12.15z"
|
||||
/>
|
||||
</svg>
|
||||
<input
|
||||
type="text"
|
||||
value={searchQuery}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
placeholder="Tìm theo tên dự án..."
|
||||
className="h-10 w-full rounded-xl border border-slate-200 bg-white pl-10 pr-4 text-sm text-slate-800 placeholder:text-slate-400 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Task Type Filter */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={selectedTaskType}
|
||||
onChange={(e) => onTaskTypeChange(e.target.value as 'all' | TaskType)}
|
||||
className="h-10 appearance-none rounded-xl border border-slate-200 bg-white pl-3.5 pr-9 text-sm font-medium text-slate-700 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
>
|
||||
<option value="all">Tất cả bài toán</option>
|
||||
<option value="classification">Classification</option>
|
||||
<option value="object_detection">Object Detection</option>
|
||||
<option value="segmentation">Segmentation</option>
|
||||
</select>
|
||||
<svg
|
||||
className="pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-500"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
{/* Status Filter */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={selectedStatus}
|
||||
onChange={(e) => onStatusChange(e.target.value as 'all' | ProjectStatus)}
|
||||
className="h-10 appearance-none rounded-xl border border-slate-200 bg-white pl-3.5 pr-9 text-sm font-medium text-slate-700 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
>
|
||||
<option value="all">Tất cả trạng thái</option>
|
||||
<option value="annotating">Đang gán nhãn</option>
|
||||
<option value="pending_review">Chờ duyệt</option>
|
||||
<option value="completed">Hoàn thành</option>
|
||||
</select>
|
||||
<svg
|
||||
className="pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-500"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right side: Sort + Grid/List toggle */}
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="relative flex items-center">
|
||||
<select
|
||||
value={sortBy}
|
||||
onChange={(e) => onSortChange(e.target.value as 'updated' | 'name' | 'progress')}
|
||||
className="appearance-none bg-transparent pr-5 text-xs font-medium text-slate-500 hover:text-slate-800 focus:outline-none cursor-pointer"
|
||||
>
|
||||
<option value="updated">Mới cập nhật</option>
|
||||
<option value="name">Tên dự án (A-Z)</option>
|
||||
<option value="progress">Tiến độ gán nhãn</option>
|
||||
</select>
|
||||
<svg
|
||||
className="pointer-events-none absolute right-0.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-400"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onViewModeChange(viewMode === 'grid' ? 'list' : 'grid')}
|
||||
title={viewMode === 'grid' ? 'Chuyển sang dạng danh sách' : 'Chuyển sang dạng lưới'}
|
||||
className="flex h-8 w-8 items-center justify-center rounded-lg text-indigo-600 transition hover:bg-indigo-50"
|
||||
>
|
||||
{viewMode === 'grid' ? (
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<rect x="3" y="3" width="7" height="7" rx="1.5" />
|
||||
<rect x="14" y="3" width="7" height="7" rx="1.5" />
|
||||
<rect x="3" y="14" width="7" height="7" rx="1.5" />
|
||||
<rect x="14" y="14" width="7" height="7" rx="1.5" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
66
src/pages/projects/components/ProjectStatsCards.tsx
Normal file
66
src/pages/projects/components/ProjectStatsCards.tsx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import React from 'react'
|
||||
import { Project } from '@/types'
|
||||
|
||||
interface ProjectStatsCardsProps {
|
||||
projects?: Project[]
|
||||
}
|
||||
|
||||
export const ProjectStatsCards: React.FC<ProjectStatsCardsProps> = ({ projects }) => {
|
||||
const totalProjects = projects ? projects.length : 3
|
||||
const totalImages = projects
|
||||
? projects.reduce((sum, p) => sum + p.stats.totalImages, 0)
|
||||
: 4320
|
||||
const totalAnnotated = projects
|
||||
? projects.reduce((sum, p) => sum + p.stats.completed + p.stats.pendingReview, 0)
|
||||
: 3144
|
||||
const totalPendingReview = projects
|
||||
? projects.reduce((sum, p) => sum + p.stats.pendingReview, 0)
|
||||
: 372
|
||||
|
||||
const annotatedPercent =
|
||||
totalImages > 0
|
||||
? ((totalAnnotated / totalImages) * 100).toFixed(1).replace('.', ',')
|
||||
: '0'
|
||||
|
||||
const formatNumber = (num: number) => num.toLocaleString('vi-VN')
|
||||
|
||||
const cards = [
|
||||
{
|
||||
label: 'Tổng dự án',
|
||||
value: formatNumber(totalProjects),
|
||||
subtext: `${totalProjects} bài toán · đang hoạt động`,
|
||||
},
|
||||
{
|
||||
label: 'Tổng dữ liệu',
|
||||
value: formatNumber(totalImages),
|
||||
subtext: 'ảnh trong không gian nhóm',
|
||||
},
|
||||
{
|
||||
label: 'Đã gán nhãn',
|
||||
value: formatNumber(totalAnnotated),
|
||||
subtext: `${annotatedPercent}% · bao gồm ảnh chờ duyệt`,
|
||||
},
|
||||
{
|
||||
label: 'Chờ duyệt',
|
||||
value: formatNumber(totalPendingReview),
|
||||
subtext: 'ảnh cần kiểm tra chất lượng',
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{cards.map((card) => (
|
||||
<div
|
||||
key={card.label}
|
||||
className="rounded-2xl border border-slate-200/80 bg-white px-5 py-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]"
|
||||
>
|
||||
<p className="text-xs font-medium text-slate-500">{card.label}</p>
|
||||
<p className="mt-2 text-[28px] font-bold leading-tight tracking-tight text-slate-900">
|
||||
{card.value}
|
||||
</p>
|
||||
<p className="mt-2 text-xs text-slate-500">{card.subtext}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
60
src/pages/projects/components/TaskTypeSelector.tsx
Normal file
60
src/pages/projects/components/TaskTypeSelector.tsx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import React from 'react'
|
||||
import { TaskType } from '@/types'
|
||||
|
||||
interface TaskTypeSelectorProps {
|
||||
value: TaskType
|
||||
onChange: (taskType: TaskType) => void
|
||||
}
|
||||
|
||||
const TASK_OPTIONS: Array<{
|
||||
type: TaskType
|
||||
title: string
|
||||
subtitle: string
|
||||
}> = [
|
||||
{
|
||||
type: 'classification',
|
||||
title: 'Classification',
|
||||
subtitle: 'Bài toán phân loại ảnh',
|
||||
},
|
||||
{
|
||||
type: 'object_detection',
|
||||
title: 'Object Detection',
|
||||
subtitle: 'Phát hiện vật thể',
|
||||
},
|
||||
{
|
||||
type: 'segmentation',
|
||||
title: 'Segmentation',
|
||||
subtitle: 'Phân đoạn hình ảnh',
|
||||
},
|
||||
]
|
||||
|
||||
export const TaskTypeSelector: React.FC<TaskTypeSelectorProps> = ({ value, onChange }) => {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-3.5 sm:grid-cols-2">
|
||||
{TASK_OPTIONS.map((opt) => {
|
||||
const isSelected = value === opt.type
|
||||
return (
|
||||
<button
|
||||
key={opt.type}
|
||||
type="button"
|
||||
onClick={() => onChange(opt.type)}
|
||||
className={`flex flex-col items-center justify-center rounded-xl border px-4 py-4 text-center transition-all ${
|
||||
isSelected
|
||||
? 'border-indigo-500 bg-indigo-50/70 shadow-sm'
|
||||
: 'border-slate-200 bg-white hover:border-slate-300 hover:bg-slate-50/60'
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`text-sm font-bold ${
|
||||
isSelected ? 'text-indigo-600' : 'text-slate-900'
|
||||
}`}
|
||||
>
|
||||
{opt.title}
|
||||
</span>
|
||||
<span className="mt-1 text-xs text-slate-500">{opt.subtitle}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
216
src/pages/projects/components/detail/DataTab.tsx
Normal file
216
src/pages/projects/components/detail/DataTab.tsx
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
import React, { useState, useRef } from 'react'
|
||||
import { ImageItem, Project } from '@/types'
|
||||
import { ImageTable } from './ImageTable'
|
||||
|
||||
interface DataTabProps {
|
||||
project: Project
|
||||
images: ImageItem[]
|
||||
onUploadImages: (fileNames: string[]) => void
|
||||
}
|
||||
|
||||
interface DatasetBatch {
|
||||
id: string
|
||||
batchName: string
|
||||
uploadedBy: string
|
||||
uploadedAt: string
|
||||
imageCount: number
|
||||
status: 'Đã phân công' | 'Đang gán nhãn' | 'Hoàn thành'
|
||||
}
|
||||
|
||||
export const DataTab: React.FC<DataTabProps> = ({
|
||||
project,
|
||||
images,
|
||||
onUploadImages,
|
||||
}) => {
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null)
|
||||
const [isDragging, setIsDragging] = useState(false)
|
||||
const [batches, setBatches] = useState<DatasetBatch[]>([
|
||||
{
|
||||
id: 'batch-03',
|
||||
batchName: 'batch_2026_10_morning_cam04',
|
||||
uploadedBy: 'Minh Anh',
|
||||
uploadedAt: 'Hôm nay, 08:30',
|
||||
imageCount: 320,
|
||||
status: 'Đang gán nhãn',
|
||||
},
|
||||
{
|
||||
id: 'batch-02',
|
||||
batchName: 'batch_2026_10_intersection_02',
|
||||
uploadedBy: 'Minh Anh',
|
||||
uploadedAt: 'Hôm qua, 16:15',
|
||||
imageCount: 480,
|
||||
status: 'Đang gán nhãn',
|
||||
},
|
||||
{
|
||||
id: 'batch-01',
|
||||
batchName: 'batch_2026_09_initial_seed',
|
||||
uploadedBy: 'Thu Hà',
|
||||
uploadedAt: '5 ngày trước',
|
||||
imageCount: 480,
|
||||
status: 'Hoàn thành',
|
||||
},
|
||||
])
|
||||
|
||||
const handleFilesSelected = (files: FileList | null) => {
|
||||
if (!files || files.length === 0) return
|
||||
const names = Array.from(files).map((f) => f.name)
|
||||
onUploadImages(names)
|
||||
setBatches((prev) => [
|
||||
{
|
||||
id: `batch-${Date.now()}`,
|
||||
batchName: `upload_batch_${new Date().toISOString().slice(0, 10).replace(/-/g, '_')}`,
|
||||
uploadedBy: 'Minh Anh',
|
||||
uploadedAt: 'Vừa tải lên',
|
||||
imageCount: names.length,
|
||||
status: 'Đã phân công',
|
||||
},
|
||||
...prev,
|
||||
])
|
||||
}
|
||||
|
||||
const handleSimulatedSampleUpload = () => {
|
||||
const sampleNames = [
|
||||
`traffic_${String(327 + images.length).padStart(5, '0')}.jpg`,
|
||||
`traffic_${String(328 + images.length).padStart(5, '0')}.jpg`,
|
||||
`traffic_${String(329 + images.length).padStart(5, '0')}.jpg`,
|
||||
]
|
||||
onUploadImages(sampleNames)
|
||||
setBatches((prev) => [
|
||||
{
|
||||
id: `batch-${Date.now()}`,
|
||||
batchName: `camera_import_${batches.length + 1}`,
|
||||
uploadedBy: 'Minh Anh',
|
||||
uploadedAt: 'Vừa tải lên',
|
||||
imageCount: sampleNames.length,
|
||||
status: 'Đã phân công',
|
||||
},
|
||||
...prev,
|
||||
])
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Upload Dropzone */}
|
||||
<div
|
||||
onDragOver={(e) => {
|
||||
e.preventDefault()
|
||||
setIsDragging(true)
|
||||
}}
|
||||
onDragLeave={() => setIsDragging(false)}
|
||||
onDrop={(e) => {
|
||||
e.preventDefault()
|
||||
setIsDragging(false)
|
||||
handleFilesSelected(e.dataTransfer.files)
|
||||
}}
|
||||
className={`flex flex-col items-center justify-center rounded-2xl border-2 border-dashed p-8 text-center transition ${
|
||||
isDragging
|
||||
? 'border-[#C95C3C] bg-[#FDF4F1]'
|
||||
: 'border-slate-300 bg-white hover:border-slate-400'
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple
|
||||
className="hidden"
|
||||
onChange={(e) => handleFilesSelected(e.target.files)}
|
||||
/>
|
||||
<div className="flex h-12 w-12 items-center justify-center rounded-2xl bg-[#FDF4F1] text-[#C95C3C]">
|
||||
<svg
|
||||
className="h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M4 16v2a2 2 0 002 2h12a2 2 0 002-2v-2M16 8l-4-4m0 0L8 8m4-4v12"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<h3 className="mt-3 text-sm font-bold text-slate-900">
|
||||
Kéo thả ảnh hoặc thư mục dữ liệu vào đây
|
||||
</h3>
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
Hỗ trợ định dạng JPG, PNG, WEBP tối đa 25MB/ảnh cho dự án{' '}
|
||||
<span className="font-mono font-semibold text-slate-700">{project.slug}</span>
|
||||
</p>
|
||||
<div className="mt-4 flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="rounded-xl bg-[#C95C3C] px-4 py-2 text-xs font-semibold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
Chọn tệp từ máy tính
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSimulatedSampleUpload}
|
||||
className="rounded-xl border border-slate-200 bg-white px-4 py-2 text-xs font-semibold text-slate-700 transition hover:bg-slate-50"
|
||||
>
|
||||
+ Nhập nhanh 3 ảnh mẫu
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Dataset Batches Table */}
|
||||
<div className="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className="text-base font-bold text-slate-900">Lô dữ liệu đã tải lên</h3>
|
||||
<p className="mt-0.5 text-xs text-slate-500">
|
||||
Quản lý các đợt nhập ảnh vào dự án và trạng thái phân công
|
||||
</p>
|
||||
</div>
|
||||
<span className="rounded-lg bg-slate-100 px-2.5 py-1 text-xs font-semibold text-slate-700">
|
||||
{batches.length} lô dữ liệu
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 divide-y divide-slate-100">
|
||||
{batches.map((batch) => (
|
||||
<div
|
||||
key={batch.id}
|
||||
className="flex flex-wrap items-center justify-between gap-3 py-3 text-xs"
|
||||
>
|
||||
<div>
|
||||
<p className="font-mono font-semibold text-slate-900">{batch.batchName}</p>
|
||||
<p className="mt-0.5 text-slate-400">
|
||||
Tải lên bởi {batch.uploadedBy} · {batch.uploadedAt}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<span className="font-semibold text-slate-700">
|
||||
{batch.imageCount.toLocaleString('vi-VN')} ảnh
|
||||
</span>
|
||||
<span
|
||||
className={`rounded-full px-2.5 py-0.5 font-semibold ${
|
||||
batch.status === 'Hoàn thành'
|
||||
? 'bg-emerald-50 text-emerald-700'
|
||||
: batch.status === 'Đang gán nhãn'
|
||||
? 'bg-amber-50 text-amber-700'
|
||||
: 'bg-indigo-50 text-indigo-700'
|
||||
}`}
|
||||
>
|
||||
{batch.status}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Full Image Table */}
|
||||
<ImageTable
|
||||
projectId={project.id}
|
||||
projectSlug={project.slug}
|
||||
images={images}
|
||||
stats={project.stats}
|
||||
classes={project.classes}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
104
src/pages/projects/components/detail/ExportButton.tsx
Normal file
104
src/pages/projects/components/detail/ExportButton.tsx
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
import React, { useState } from 'react'
|
||||
import { ImageItem, LabelClass } from '@/types'
|
||||
|
||||
interface ExportButtonProps {
|
||||
projectSlug?: string
|
||||
images?: ImageItem[]
|
||||
classes?: LabelClass[]
|
||||
}
|
||||
|
||||
export const ExportButton: React.FC<ExportButtonProps> = ({
|
||||
projectSlug = 'traffic_camera_v2',
|
||||
images = [],
|
||||
classes = [],
|
||||
}) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
const triggerDownload = (format: 'coco' | 'yolo' | 'json') => {
|
||||
const payload = {
|
||||
dataset: projectSlug,
|
||||
exportFormat: format.toUpperCase(),
|
||||
exportedAt: new Date().toISOString(),
|
||||
classes: classes.map((c, idx) => ({ id: idx + 1, name: c.name, color: c.color, count: c.count })),
|
||||
images: images.map((img) => ({
|
||||
id: img.id,
|
||||
file_name: img.fileName,
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
status: img.status,
|
||||
object_count: img.objectCount,
|
||||
assigned_to: img.assignedTo.name,
|
||||
})),
|
||||
}
|
||||
|
||||
const blob = new Blob([JSON.stringify(payload, null, 2)], {
|
||||
type: 'application/json',
|
||||
})
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `${projectSlug}_${format}_annotations.json`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(url)
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
className="inline-flex h-10 items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 text-xs font-bold text-slate-800 shadow-sm transition hover:bg-slate-50"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4 text-slate-600"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M4 16v2a2 2 0 002 2h12a2 2 0 002-2v-2M7 10l5 5m0 0l5-5m-5 5V4"
|
||||
/>
|
||||
</svg>
|
||||
<span>Xuất nhãn</span>
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute right-0 top-11 z-20 w-52 rounded-xl border border-slate-200 bg-white py-1.5 shadow-lg">
|
||||
<div className="px-3.5 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-slate-400">
|
||||
Định dạng xuất
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => triggerDownload('coco')}
|
||||
className="flex w-full items-center justify-between px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
<span>COCO JSON (.json)</span>
|
||||
<span className="rounded bg-indigo-50 px-1.5 py-0.5 text-[10px] font-semibold text-indigo-600">
|
||||
Chuẩn
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => triggerDownload('yolo')}
|
||||
className="flex w-full items-center justify-between px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
<span>YOLO Format (.json)</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => triggerDownload('json')}
|
||||
className="flex w-full items-center justify-between px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
<span>LabelMe / Danable JSON</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
190
src/pages/projects/components/detail/ImageTable.tsx
Normal file
190
src/pages/projects/components/detail/ImageTable.tsx
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
import React, { useState, useMemo } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { ImageAnnotationStatus, ImageItem, LabelClass, ProjectStats } from '@/types'
|
||||
import { ImageTableFilters } from './ImageTableFilters'
|
||||
|
||||
interface ImageTableProps {
|
||||
projectId: string
|
||||
projectSlug: string
|
||||
images: ImageItem[]
|
||||
stats: ProjectStats
|
||||
classes: LabelClass[]
|
||||
}
|
||||
|
||||
const STATUS_BADGE_MAP: Record<
|
||||
ImageAnnotationStatus,
|
||||
{ label: string; bg: string; text: string; dot: string }
|
||||
> = {
|
||||
pending_review: {
|
||||
label: 'Chờ duyệt',
|
||||
bg: 'bg-[#FEF3C7]',
|
||||
text: 'text-[#B45309]',
|
||||
dot: 'bg-[#F59E0B]',
|
||||
},
|
||||
in_progress: {
|
||||
label: 'Đang làm',
|
||||
bg: 'bg-[#FEE2E2]/80',
|
||||
text: 'text-[#B91C1C]',
|
||||
dot: 'bg-[#EF4444]',
|
||||
},
|
||||
completed: {
|
||||
label: 'Hoàn thành',
|
||||
bg: 'bg-[#DCFCE7]',
|
||||
text: 'text-[#15803D]',
|
||||
dot: 'bg-[#22C55E]',
|
||||
},
|
||||
unassigned: {
|
||||
label: 'Chưa gán nhãn',
|
||||
bg: 'bg-slate-100',
|
||||
text: 'text-slate-600',
|
||||
dot: 'bg-slate-400',
|
||||
},
|
||||
}
|
||||
|
||||
export const ImageTable: React.FC<ImageTableProps> = ({
|
||||
projectId,
|
||||
projectSlug,
|
||||
images,
|
||||
stats,
|
||||
classes,
|
||||
}) => {
|
||||
const navigate = useNavigate()
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [selectedStatus, setSelectedStatus] = useState<'all' | ImageAnnotationStatus>('all')
|
||||
const [selectedMember, setSelectedMember] = useState('all')
|
||||
|
||||
const memberNames = useMemo(() => {
|
||||
const set = new Set<string>()
|
||||
images.forEach((img) => set.add(img.assignedTo.name))
|
||||
return Array.from(set)
|
||||
}, [images])
|
||||
|
||||
const filteredImages = useMemo(() => {
|
||||
return images.filter((img) => {
|
||||
const matchSearch =
|
||||
!searchQuery.trim() ||
|
||||
img.fileName.toLowerCase().includes(searchQuery.trim().toLowerCase())
|
||||
const matchStatus = selectedStatus === 'all' || img.status === selectedStatus
|
||||
const matchMember = selectedMember === 'all' || img.assignedTo.name === selectedMember
|
||||
return matchSearch && matchStatus && matchMember
|
||||
})
|
||||
}, [images, searchQuery, selectedStatus, selectedMember])
|
||||
|
||||
const totalObjects =
|
||||
stats.totalObjects ??
|
||||
classes.reduce((sum, cls) => sum + cls.count, 0)
|
||||
|
||||
const formatNum = (n: number) => n.toLocaleString('vi-VN')
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
|
||||
{/* Top Header + Filter Bar */}
|
||||
<div className="p-5">
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<h3 className="text-base font-bold text-slate-900">Danh sách ảnh</h3>
|
||||
<span className="text-xs font-medium text-indigo-600">
|
||||
{formatNum(stats.totalImages)} ảnh · {formatNum(totalObjects)} đối tượng
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<ImageTableFilters
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={setSearchQuery}
|
||||
selectedStatus={selectedStatus}
|
||||
onStatusChange={setSelectedStatus}
|
||||
selectedMember={selectedMember}
|
||||
onMemberChange={setSelectedMember}
|
||||
memberNames={memberNames}
|
||||
projectSlug={projectSlug}
|
||||
images={images}
|
||||
classes={classes}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Table */}
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full border-collapse text-left">
|
||||
<thead>
|
||||
<tr className="border-y border-slate-200/70 bg-slate-50/70 text-[11px] font-bold uppercase tracking-wider text-slate-400">
|
||||
<th className="py-3 pl-5 pr-4">TÊN ẢNH</th>
|
||||
<th className="px-4 py-3">TRẠNG THÁI</th>
|
||||
<th className="px-4 py-3">NHÃN</th>
|
||||
<th className="px-4 py-3">PHÂN CÔNG</th>
|
||||
<th className="py-3 pl-4 pr-5">THAO TÁC</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100 text-xs">
|
||||
{filteredImages.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={5} className="py-10 text-center text-slate-400">
|
||||
Không tìm thấy ảnh phù hợp với bộ lọc hiện tại.
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
filteredImages.map((image) => {
|
||||
const badge = STATUS_BADGE_MAP[image.status]
|
||||
return (
|
||||
<tr
|
||||
key={image.id}
|
||||
onClick={() =>
|
||||
navigate(`/projects/${projectId}/annotate?imageId=${image.id}`)
|
||||
}
|
||||
className="cursor-pointer transition hover:bg-slate-50/80"
|
||||
>
|
||||
<td className="py-3.5 pl-5 pr-4">
|
||||
<div className="flex items-center gap-3.5">
|
||||
<img
|
||||
src={image.thumbnailUrl}
|
||||
alt={image.fileName}
|
||||
className="h-9 w-14 rounded-lg object-cover border border-slate-200/60 shrink-0"
|
||||
/>
|
||||
<div>
|
||||
<p className="font-mono text-xs font-semibold text-slate-900">
|
||||
{image.fileName}
|
||||
</p>
|
||||
<p className="mt-0.5 text-[11px] text-slate-400">
|
||||
{image.width} × {image.height} px
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td className="px-4 py-3.5">
|
||||
<span
|
||||
className={`inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-semibold ${badge.bg} ${badge.text}`}
|
||||
>
|
||||
<span className={`h-1.5 w-1.5 rounded-full ${badge.dot}`} />
|
||||
{badge.label}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td className="px-4 py-3.5 text-slate-600">
|
||||
{image.objectCount} đối tượng
|
||||
</td>
|
||||
|
||||
<td className="px-4 py-3.5 font-semibold text-slate-800">
|
||||
{image.assignedTo.name}
|
||||
</td>
|
||||
|
||||
<td className="py-3.5 pl-4 pr-5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
navigate(`/projects/${projectId}/annotate?imageId=${image.id}`)
|
||||
}}
|
||||
className="font-semibold text-indigo-600 hover:text-indigo-700 transition"
|
||||
>
|
||||
Mở ảnh →
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
110
src/pages/projects/components/detail/ImageTableFilters.tsx
Normal file
110
src/pages/projects/components/detail/ImageTableFilters.tsx
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
import React from 'react'
|
||||
import { ImageAnnotationStatus, ImageItem, LabelClass } from '@/types'
|
||||
import { ExportButton } from './ExportButton'
|
||||
|
||||
interface ImageTableFiltersProps {
|
||||
searchQuery: string
|
||||
onSearchChange: (val: string) => void
|
||||
selectedStatus: 'all' | ImageAnnotationStatus
|
||||
onStatusChange: (val: 'all' | ImageAnnotationStatus) => void
|
||||
selectedMember: string
|
||||
onMemberChange: (val: string) => void
|
||||
memberNames: string[]
|
||||
projectSlug?: string
|
||||
images?: ImageItem[]
|
||||
classes?: LabelClass[]
|
||||
}
|
||||
|
||||
export const ImageTableFilters: React.FC<ImageTableFiltersProps> = ({
|
||||
searchQuery,
|
||||
onSearchChange,
|
||||
selectedStatus,
|
||||
onStatusChange,
|
||||
selectedMember,
|
||||
onMemberChange,
|
||||
memberNames,
|
||||
projectSlug,
|
||||
images,
|
||||
classes,
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{/* Search Input */}
|
||||
<div className="relative w-full sm:w-64">
|
||||
<svg
|
||||
className="pointer-events-none absolute left-3.5 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M21 21l-4.35-4.35m0 0A7.5 7.5 0 104.5 4.5a7.5 7.5 0 0012.15 12.15z"
|
||||
/>
|
||||
</svg>
|
||||
<input
|
||||
type="text"
|
||||
value={searchQuery}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
placeholder="Tìm tên ảnh..."
|
||||
className="h-10 w-full rounded-xl border border-slate-200 bg-white pl-10 pr-4 text-xs text-slate-800 placeholder:text-slate-400 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Status Select */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={selectedStatus}
|
||||
onChange={(e) => onStatusChange(e.target.value as 'all' | ImageAnnotationStatus)}
|
||||
className="h-10 appearance-none rounded-xl border border-slate-200 bg-white pl-3.5 pr-9 text-xs font-medium text-slate-700 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
>
|
||||
<option value="all">Tất cả trạng thái</option>
|
||||
<option value="pending_review">Chờ duyệt</option>
|
||||
<option value="in_progress">Đang làm</option>
|
||||
<option value="completed">Hoàn thành</option>
|
||||
<option value="unassigned">Chưa gán nhãn</option>
|
||||
</select>
|
||||
<svg
|
||||
className="pointer-events-none absolute right-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-500"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
{/* Member Select */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={selectedMember}
|
||||
onChange={(e) => onMemberChange(e.target.value)}
|
||||
className="h-10 appearance-none rounded-xl border border-slate-200 bg-white pl-3.5 pr-9 text-xs font-medium text-slate-700 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
>
|
||||
<option value="all">Tất cả thành viên</option>
|
||||
{memberNames.map((name) => (
|
||||
<option key={name} value={name}>
|
||||
{name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<svg
|
||||
className="pointer-events-none absolute right-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-500"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ExportButton projectSlug={projectSlug} images={images} classes={classes} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
72
src/pages/projects/components/detail/LabelDistribution.tsx
Normal file
72
src/pages/projects/components/detail/LabelDistribution.tsx
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import React from 'react'
|
||||
import { LabelClass, ProjectStats } from '@/types'
|
||||
|
||||
interface LabelDistributionProps {
|
||||
classes: LabelClass[]
|
||||
stats: ProjectStats
|
||||
onManageLabels?: () => void
|
||||
}
|
||||
|
||||
export const LabelDistribution: React.FC<LabelDistributionProps> = ({
|
||||
classes,
|
||||
stats,
|
||||
onManageLabels,
|
||||
}) => {
|
||||
const annotatedImages = stats.completed + stats.pendingReview
|
||||
const totalImages = stats.totalImages
|
||||
const progressPercent =
|
||||
totalImages > 0 ? Math.round((annotatedImages / totalImages) * 100) : 0
|
||||
|
||||
const formatNum = (n: number) => n.toLocaleString('vi-VN')
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col justify-between rounded-2xl border border-slate-200/80 bg-white p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
|
||||
<div>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-base font-bold text-slate-900">Lớp nhãn</h3>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onManageLabels}
|
||||
className="text-xs font-semibold text-indigo-600 hover:text-indigo-700 transition"
|
||||
>
|
||||
Quản lý {classes.length} lớp →
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 4 columns with colored dots matching MVP · Project dashboard.png */}
|
||||
<div className="mt-5 grid grid-cols-2 gap-4 sm:grid-cols-4">
|
||||
{classes.map((cls) => (
|
||||
<div key={cls.id}>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span
|
||||
className="h-2 w-2 rounded-full shrink-0"
|
||||
style={{ backgroundColor: cls.color }}
|
||||
/>
|
||||
<span className="text-xs font-semibold text-slate-800">{cls.name}</span>
|
||||
</div>
|
||||
<p className="mt-2 text-2xl font-bold tracking-tight text-slate-900">
|
||||
{formatNum(cls.count)}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom progress bar */}
|
||||
<div className="mt-6 pt-2">
|
||||
<div className="flex items-center justify-between text-xs">
|
||||
<span className="text-slate-500">
|
||||
{formatNum(annotatedImages)} / {formatNum(totalImages)} ảnh đã gán nhãn
|
||||
</span>
|
||||
<span className="font-bold text-indigo-600">{progressPercent}%</span>
|
||||
</div>
|
||||
<div className="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-slate-100">
|
||||
<div
|
||||
className="h-full rounded-full bg-[#C95C3C] transition-all duration-300"
|
||||
style={{ width: `${Math.min(100, Math.max(0, progressPercent))}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
197
src/pages/projects/components/detail/LabelsTab.tsx
Normal file
197
src/pages/projects/components/detail/LabelsTab.tsx
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
import React, { useState } from 'react'
|
||||
import { LabelClass } from '@/types'
|
||||
|
||||
interface LabelsTabProps {
|
||||
classes: LabelClass[]
|
||||
onUpdateClasses: (classes: LabelClass[]) => void
|
||||
}
|
||||
|
||||
const PRESET_COLORS = [
|
||||
'#06B6D4', // Cyan (Ô tô)
|
||||
'#F59E0B', // Amber (Xe máy)
|
||||
'#A855F7', // Purple (Xe buýt)
|
||||
'#3B82F6', // Blue (Xe tải)
|
||||
'#10B981', // Emerald
|
||||
'#EF4444', // Red
|
||||
'#EC4899', // Pink
|
||||
'#6366F1', // Indigo
|
||||
]
|
||||
|
||||
export const LabelsTab: React.FC<LabelsTabProps> = ({
|
||||
classes,
|
||||
onUpdateClasses,
|
||||
}) => {
|
||||
const [newName, setNewName] = useState('')
|
||||
const [newColor, setNewColor] = useState('#10B981')
|
||||
const [editingId, setEditingId] = useState<string | null>(null)
|
||||
const [editingName, setEditingName] = useState('')
|
||||
const [editingColor, setEditingColor] = useState('')
|
||||
|
||||
const handleAddClass = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!newName.trim()) return
|
||||
const nextShortcut = String(classes.length + 1)
|
||||
const created: LabelClass = {
|
||||
id: `cls-${Date.now()}`,
|
||||
name: newName.trim(),
|
||||
color: newColor,
|
||||
count: 0,
|
||||
shortcutKey: nextShortcut,
|
||||
}
|
||||
onUpdateClasses([...classes, created])
|
||||
setNewName('')
|
||||
}
|
||||
|
||||
const startEditing = (cls: LabelClass) => {
|
||||
setEditingId(cls.id)
|
||||
setEditingName(cls.name)
|
||||
setEditingColor(cls.color)
|
||||
}
|
||||
|
||||
const saveEditing = (id: string) => {
|
||||
if (!editingName.trim()) return
|
||||
onUpdateClasses(
|
||||
classes.map((c) =>
|
||||
c.id === id ? { ...c, name: editingName.trim(), color: editingColor } : c
|
||||
)
|
||||
)
|
||||
setEditingId(null)
|
||||
}
|
||||
|
||||
const handleDelete = (id: string) => {
|
||||
onUpdateClasses(classes.filter((c) => c.id !== id))
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Add New Label Class Form */}
|
||||
<div className="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
|
||||
<h3 className="text-base font-bold text-slate-900">Thêm lớp nhãn mới</h3>
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
Thiết lập tên lớp nhãn, màu sắc hiển thị trên khung vẽ và phím tắt gán nhãn nhanh.
|
||||
</p>
|
||||
|
||||
<form onSubmit={handleAddClass} className="mt-4 flex flex-wrap items-center gap-3">
|
||||
<input
|
||||
type="text"
|
||||
value={newName}
|
||||
onChange={(e) => setNewName(e.target.value)}
|
||||
placeholder="Nhập tên lớp nhãn (VD: Người đi bộ, Biển báo...)"
|
||||
className="h-10 min-w-[240px] flex-1 rounded-xl border border-slate-200 px-3.5 text-xs text-slate-900 placeholder:text-slate-400 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
/>
|
||||
|
||||
<div className="flex items-center gap-1.5 rounded-xl border border-slate-200 px-3 py-1.5">
|
||||
{PRESET_COLORS.map((color) => (
|
||||
<button
|
||||
key={color}
|
||||
type="button"
|
||||
onClick={() => setNewColor(color)}
|
||||
style={{ backgroundColor: color }}
|
||||
className={`h-5 w-5 rounded-full transition ${
|
||||
newColor === color ? 'ring-2 ring-slate-900 ring-offset-2' : 'opacity-80 hover:opacity-100'
|
||||
}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="h-10 rounded-xl bg-[#C95C3C] px-5 text-xs font-semibold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
+ Thêm lớp nhãn
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{/* Existing Label Classes List */}
|
||||
<div className="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-base font-bold text-slate-900">
|
||||
Danh sách lớp nhãn ({classes.length})
|
||||
</h3>
|
||||
<span className="text-xs text-slate-500">
|
||||
Tổng số {classes.reduce((s, c) => s + c.count, 0).toLocaleString('vi-VN')} đối tượng đã gán
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 divide-y divide-slate-100">
|
||||
{classes.map((cls, index) => {
|
||||
const isEditing = editingId === cls.id
|
||||
return (
|
||||
<div
|
||||
key={cls.id}
|
||||
className="flex flex-wrap items-center justify-between gap-3 py-3.5"
|
||||
>
|
||||
{isEditing ? (
|
||||
<div className="flex flex-1 flex-wrap items-center gap-3">
|
||||
<input
|
||||
type="color"
|
||||
value={editingColor}
|
||||
onChange={(e) => setEditingColor(e.target.value)}
|
||||
className="h-8 w-8 cursor-pointer rounded border border-slate-200 bg-white p-0.5"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={editingName}
|
||||
onChange={(e) => setEditingName(e.target.value)}
|
||||
className="h-9 rounded-lg border border-slate-300 px-3 text-xs font-semibold text-slate-900 focus:border-indigo-500 focus:outline-none"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => saveEditing(cls.id)}
|
||||
className="rounded-lg bg-indigo-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-indigo-700"
|
||||
>
|
||||
Lưu
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setEditingId(null)}
|
||||
className="rounded-lg border border-slate-200 px-3 py-1.5 text-xs font-semibold text-slate-600 hover:bg-slate-50"
|
||||
>
|
||||
Hủy
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center gap-3">
|
||||
<span
|
||||
className="h-3.5 w-3.5 rounded-full shrink-0"
|
||||
style={{ backgroundColor: cls.color }}
|
||||
/>
|
||||
<span className="text-sm font-bold text-slate-900">{cls.name}</span>
|
||||
<span className="rounded-md bg-slate-100 px-2 py-0.5 font-mono text-[11px] font-semibold text-slate-500">
|
||||
Phím {cls.shortcutKey ?? index + 1}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-4 text-xs">
|
||||
<span className="font-semibold text-slate-700">
|
||||
{cls.count.toLocaleString('vi-VN')} đối tượng
|
||||
</span>
|
||||
{!isEditing && (
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => startEditing(cls)}
|
||||
className="rounded-lg border border-slate-200 px-2.5 py-1 font-semibold text-slate-600 hover:bg-slate-50"
|
||||
>
|
||||
Sửa
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleDelete(cls.id)}
|
||||
className="rounded-lg border border-rose-200 px-2.5 py-1 font-semibold text-rose-600 hover:bg-rose-50"
|
||||
>
|
||||
Xóa
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
81
src/pages/projects/components/detail/MemberAssignment.tsx
Normal file
81
src/pages/projects/components/detail/MemberAssignment.tsx
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
import React from 'react'
|
||||
import { ProjectMemberSummary } from '@/types'
|
||||
|
||||
interface MemberAssignmentProps {
|
||||
members: ProjectMemberSummary[]
|
||||
onEditMembers?: () => void
|
||||
}
|
||||
|
||||
const ROLE_LABELS: Record<ProjectMemberSummary['role'], string> = {
|
||||
annotator: 'Người gán nhãn',
|
||||
reviewer: 'Người duyệt',
|
||||
manager: 'Quản lý dự án',
|
||||
}
|
||||
|
||||
export const MemberAssignment: React.FC<MemberAssignmentProps> = ({
|
||||
members,
|
||||
onEditMembers,
|
||||
}) => {
|
||||
// Show annotators and reviewers first to match MVP · Project dashboard.png (HL Hà Linh, TN Tuấn Nam, TH Thu Hà)
|
||||
const sortedMembers = [...members].sort((a, b) => {
|
||||
const order = { annotator: 0, reviewer: 1, manager: 2 }
|
||||
return order[a.role] - order[b.role]
|
||||
})
|
||||
|
||||
const displayMembers = sortedMembers.filter((m) => m.role !== 'manager').length >= 3
|
||||
? sortedMembers.filter((m) => m.role !== 'manager')
|
||||
: sortedMembers
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col justify-between rounded-2xl border border-slate-200/80 bg-white p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
|
||||
<div>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-base font-bold text-slate-900">Phân công thành viên</h3>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onEditMembers}
|
||||
className="text-xs font-semibold text-indigo-600 hover:text-indigo-700 transition"
|
||||
>
|
||||
Chỉnh sửa →
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 space-y-3">
|
||||
{displayMembers.map((member) => {
|
||||
const rightLabel =
|
||||
member.role === 'reviewer' && member.pendingReviewCount !== undefined
|
||||
? `${member.pendingReviewCount.toLocaleString('vi-VN')} chờ duyệt`
|
||||
: `${member.assignedCount.toLocaleString('vi-VN')} ảnh`
|
||||
|
||||
return (
|
||||
<div
|
||||
key={member.id}
|
||||
className="flex items-center justify-between py-0.5"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<div
|
||||
style={{ backgroundColor: member.color }}
|
||||
className="flex h-8 w-8 items-center justify-center rounded-full text-xs font-bold text-indigo-700"
|
||||
>
|
||||
{member.initials}
|
||||
</div>
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-xs font-bold text-slate-900">
|
||||
{member.name}
|
||||
</span>
|
||||
<span className="text-xs text-slate-400">
|
||||
{ROLE_LABELS[member.role]}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<span className="text-xs font-medium text-slate-600">
|
||||
{rightLabel}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
166
src/pages/projects/components/detail/MembersTab.tsx
Normal file
166
src/pages/projects/components/detail/MembersTab.tsx
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
import React, { useState } from 'react'
|
||||
import { ProjectMemberSummary } from '@/types'
|
||||
|
||||
interface MembersTabProps {
|
||||
members: ProjectMemberSummary[]
|
||||
onUpdateMembers: (members: ProjectMemberSummary[]) => void
|
||||
}
|
||||
|
||||
const ROLE_OPTIONS: Array<{ value: ProjectMemberSummary['role']; label: string }> = [
|
||||
{ value: 'annotator', label: 'Người gán nhãn' },
|
||||
{ value: 'reviewer', label: 'Người duyệt' },
|
||||
{ value: 'manager', label: 'Quản lý dự án' },
|
||||
]
|
||||
|
||||
export const MembersTab: React.FC<MembersTabProps> = ({
|
||||
members,
|
||||
onUpdateMembers,
|
||||
}) => {
|
||||
const [newName, setNewName] = useState('')
|
||||
const [newRole, setNewRole] = useState<ProjectMemberSummary['role']>('annotator')
|
||||
const [newQuota, setNewQuota] = useState('120')
|
||||
|
||||
const handleAddMember = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!newName.trim()) return
|
||||
const words = newName.trim().split(/\s+/)
|
||||
const initials =
|
||||
words.length >= 2
|
||||
? `${words[0]?.[0] ?? ''}${words[words.length - 1]?.[0] ?? ''}`.toUpperCase()
|
||||
: newName.trim().slice(0, 2).toUpperCase()
|
||||
|
||||
const count = Math.max(0, parseInt(newQuota, 10) || 0)
|
||||
const created: ProjectMemberSummary = {
|
||||
id: `mem-${Date.now()}`,
|
||||
name: newName.trim(),
|
||||
initials,
|
||||
color: '#E0E7FF',
|
||||
role: newRole,
|
||||
assignedCount: count,
|
||||
pendingReviewCount: newRole === 'reviewer' ? count : undefined,
|
||||
}
|
||||
onUpdateMembers([...members, created])
|
||||
setNewName('')
|
||||
setNewQuota('120')
|
||||
}
|
||||
|
||||
const handleRoleChange = (id: string, role: ProjectMemberSummary['role']) => {
|
||||
onUpdateMembers(
|
||||
members.map((m) => (m.id === id ? { ...m, role } : m))
|
||||
)
|
||||
}
|
||||
|
||||
const handleRemove = (id: string) => {
|
||||
onUpdateMembers(members.filter((m) => m.id !== id))
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Add Member to Project */}
|
||||
<div className="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
|
||||
<h3 className="text-base font-bold text-slate-900">Phân công thành viên mới</h3>
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
Thêm người gán nhãn hoặc người kiểm duyệt vào dự án này và thiết lập khối lượng ảnh.
|
||||
</p>
|
||||
|
||||
<form onSubmit={handleAddMember} className="mt-4 flex flex-wrap items-center gap-3">
|
||||
<input
|
||||
type="text"
|
||||
value={newName}
|
||||
onChange={(e) => setNewName(e.target.value)}
|
||||
placeholder="Tên thành viên (VD: Hoàng Long, Bảo Trâm...)"
|
||||
className="h-10 min-w-[220px] flex-1 rounded-xl border border-slate-200 px-3.5 text-xs text-slate-900 placeholder:text-slate-400 focus:border-indigo-500 focus:outline-none"
|
||||
/>
|
||||
|
||||
<select
|
||||
value={newRole}
|
||||
onChange={(e) => setNewRole(e.target.value as ProjectMemberSummary['role'])}
|
||||
className="h-10 rounded-xl border border-slate-200 bg-white px-3.5 text-xs font-medium text-slate-700 focus:border-indigo-500 focus:outline-none"
|
||||
>
|
||||
{ROLE_OPTIONS.map((r) => (
|
||||
<option key={r.value} value={r.value}>
|
||||
{r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={newQuota}
|
||||
onChange={(e) => setNewQuota(e.target.value)}
|
||||
placeholder="Số ảnh"
|
||||
className="h-10 w-28 rounded-xl border border-slate-200 px-3 text-xs text-slate-900 focus:border-indigo-500 focus:outline-none"
|
||||
/>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="h-10 rounded-xl bg-[#C95C3C] px-5 text-xs font-semibold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
+ Phân công
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{/* Member Table */}
|
||||
<div className="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
|
||||
<h3 className="text-base font-bold text-slate-900">
|
||||
Thành viên trong dự án ({members.length})
|
||||
</h3>
|
||||
|
||||
<div className="mt-4 divide-y divide-slate-100">
|
||||
{members.map((member) => (
|
||||
<div
|
||||
key={member.id}
|
||||
className="flex flex-wrap items-center justify-between gap-3 py-3.5"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<div
|
||||
style={{ backgroundColor: member.color }}
|
||||
className="flex h-9 w-9 items-center justify-center rounded-full text-xs font-bold text-indigo-700"
|
||||
>
|
||||
{member.initials}
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-bold text-slate-900">{member.name}</p>
|
||||
<p className="text-xs text-slate-500">
|
||||
{member.role === 'reviewer' && member.pendingReviewCount !== undefined
|
||||
? `${member.pendingReviewCount.toLocaleString('vi-VN')} ảnh chờ duyệt`
|
||||
: `${member.assignedCount.toLocaleString('vi-VN')} ảnh được giao`}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<select
|
||||
value={member.role}
|
||||
onChange={(e) =>
|
||||
handleRoleChange(
|
||||
member.id,
|
||||
e.target.value as ProjectMemberSummary['role']
|
||||
)
|
||||
}
|
||||
className="h-9 rounded-lg border border-slate-200 bg-white px-3 text-xs font-medium text-slate-700 focus:border-indigo-500 focus:outline-none"
|
||||
>
|
||||
{ROLE_OPTIONS.map((r) => (
|
||||
<option key={r.value} value={r.value}>
|
||||
{r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleRemove(member.id)}
|
||||
className="rounded-lg border border-rose-200 px-3 py-1.5 text-xs font-semibold text-rose-600 hover:bg-rose-50"
|
||||
>
|
||||
Gỡ
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
51
src/pages/projects/components/detail/OverviewTab.tsx
Normal file
51
src/pages/projects/components/detail/OverviewTab.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import React from 'react'
|
||||
import { ImageItem, Project } from '@/types'
|
||||
import { StatusCards } from './StatusCards'
|
||||
import { LabelDistribution } from './LabelDistribution'
|
||||
import { MemberAssignment } from './MemberAssignment'
|
||||
import { ImageTable } from './ImageTable'
|
||||
|
||||
interface OverviewTabProps {
|
||||
project: Project
|
||||
images: ImageItem[]
|
||||
onSwitchTab: (tab: 'overview' | 'data' | 'labels' | 'members' | 'settings') => void
|
||||
}
|
||||
|
||||
export const OverviewTab: React.FC<OverviewTabProps> = ({
|
||||
project,
|
||||
images,
|
||||
onSwitchTab,
|
||||
}) => {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* 4 Status Cards */}
|
||||
<StatusCards stats={project.stats} />
|
||||
|
||||
{/* Side-by-side Label Distribution (7 cols) + Member Assignment (5 cols) */}
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-12">
|
||||
<div className="lg:col-span-7">
|
||||
<LabelDistribution
|
||||
classes={project.classes}
|
||||
stats={project.stats}
|
||||
onManageLabels={() => onSwitchTab('labels')}
|
||||
/>
|
||||
</div>
|
||||
<div className="lg:col-span-5">
|
||||
<MemberAssignment
|
||||
members={project.members}
|
||||
onEditMembers={() => onSwitchTab('members')}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Image Table */}
|
||||
<ImageTable
|
||||
projectId={project.id}
|
||||
projectSlug={project.slug}
|
||||
images={images}
|
||||
stats={project.stats}
|
||||
classes={project.classes}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
158
src/pages/projects/components/detail/SettingsTab.tsx
Normal file
158
src/pages/projects/components/detail/SettingsTab.tsx
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
import React, { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Project, TaskType } from '@/types'
|
||||
import { TaskTypeSelector } from '../TaskTypeSelector'
|
||||
|
||||
interface SettingsTabProps {
|
||||
project: Project
|
||||
onSaveSettings: (updates: {
|
||||
name: string
|
||||
slug: string
|
||||
description: string
|
||||
taskType: TaskType
|
||||
}) => void
|
||||
onDeleteProject: () => void
|
||||
}
|
||||
|
||||
export const SettingsTab: React.FC<SettingsTabProps> = ({
|
||||
project,
|
||||
onSaveSettings,
|
||||
onDeleteProject,
|
||||
}) => {
|
||||
const navigate = useNavigate()
|
||||
const [name, setName] = useState(project.name)
|
||||
const [slug, setSlug] = useState(project.slug)
|
||||
const [description, setDescription] = useState(project.description)
|
||||
const [taskType, setTaskType] = useState<TaskType>(project.taskType)
|
||||
const [savedBanner, setSavedBanner] = useState(false)
|
||||
const [confirmDelete, setConfirmDelete] = useState(false)
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!name.trim()) return
|
||||
onSaveSettings({
|
||||
name: name.trim(),
|
||||
slug: slug.trim() || project.slug,
|
||||
description: description.trim(),
|
||||
taskType,
|
||||
})
|
||||
setSavedBanner(true)
|
||||
setTimeout(() => setSavedBanner(false), 2500)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-5 max-w-3xl">
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className="rounded-2xl border border-slate-200/80 bg-white p-6 shadow-[0_1px_2px_rgba(15,23,42,0.03)] space-y-4"
|
||||
>
|
||||
<div>
|
||||
<h3 className="text-base font-bold text-slate-900">Thiết lập chung</h3>
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
Cập nhật thông tin định danh dự án, mã bộ dữ liệu và cấu hình bài toán gán nhãn.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{savedBanner && (
|
||||
<div className="rounded-xl bg-emerald-50 px-4 py-2.5 text-xs font-semibold text-emerald-700">
|
||||
Đã lưu thay đổi cài đặt dự án thành công!
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<div>
|
||||
<label className="block text-xs font-semibold text-slate-700">
|
||||
Tên dự án
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
className="mt-1.5 h-10 w-full rounded-xl border border-slate-200 px-3.5 text-sm text-slate-900 focus:border-indigo-500 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-semibold text-slate-700">
|
||||
Mã bộ dữ liệu (Slug)
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={slug}
|
||||
onChange={(e) => setSlug(e.target.value)}
|
||||
className="mt-1.5 h-10 w-full rounded-xl border border-slate-200 px-3.5 font-mono text-sm text-slate-800 focus:border-indigo-500 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-semibold text-slate-700">Mô tả</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
className="mt-1.5 w-full rounded-xl border border-slate-200 p-3.5 text-sm text-slate-900 focus:border-indigo-500 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-xs font-semibold text-slate-700">
|
||||
Bài toán gán nhãn
|
||||
</label>
|
||||
<TaskTypeSelector value={taskType} onChange={setTaskType} />
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end pt-2">
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-xl bg-[#C95C3C] px-6 py-2.5 text-xs font-semibold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
Lưu cài đặt
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{/* Danger Zone */}
|
||||
<div className="rounded-2xl border border-rose-200 bg-rose-50/40 p-6">
|
||||
<div className="flex flex-wrap items-center justify-between gap-4">
|
||||
<div>
|
||||
<h4 className="text-sm font-bold text-rose-900">Xóa dự án này</h4>
|
||||
<p className="mt-1 text-xs text-rose-700">
|
||||
Toàn bộ ảnh và nhãn trong dự án{' '}
|
||||
<span className="font-mono font-semibold">{project.slug}</span> sẽ bị xóa khỏi không gian nhóm.
|
||||
</p>
|
||||
</div>
|
||||
{!confirmDelete ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setConfirmDelete(true)}
|
||||
className="rounded-xl border border-rose-300 bg-white px-4 py-2 text-xs font-semibold text-rose-600 hover:bg-rose-50"
|
||||
>
|
||||
Xóa dự án
|
||||
</button>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onDeleteProject()
|
||||
navigate('/projects')
|
||||
}}
|
||||
className="rounded-xl bg-rose-600 px-4 py-2 text-xs font-semibold text-white hover:bg-rose-700"
|
||||
>
|
||||
Xác nhận xóa
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setConfirmDelete(false)}
|
||||
className="rounded-xl border border-slate-200 bg-white px-3 py-2 text-xs font-semibold text-slate-600"
|
||||
>
|
||||
Hủy
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
60
src/pages/projects/components/detail/StatusCards.tsx
Normal file
60
src/pages/projects/components/detail/StatusCards.tsx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import React from 'react'
|
||||
import { ProjectStats } from '@/types'
|
||||
|
||||
interface StatusCardsProps {
|
||||
stats: ProjectStats
|
||||
}
|
||||
|
||||
export const StatusCards: React.FC<StatusCardsProps> = ({ stats }) => {
|
||||
const total = stats.totalImages || 1
|
||||
const calcPercent = (val: number) => {
|
||||
const raw = (val / total) * 100
|
||||
// Match exact formatting like 18,75%, 6,25%, 10%, 65%
|
||||
const formatted = Number.isInteger(raw)
|
||||
? raw.toString()
|
||||
: Number(raw.toFixed(2)).toString().replace('.', ',')
|
||||
return `${formatted}%`
|
||||
}
|
||||
|
||||
const formatNum = (n: number) => n.toLocaleString('vi-VN')
|
||||
|
||||
const cards = [
|
||||
{
|
||||
label: 'Chưa gán nhãn',
|
||||
value: formatNum(stats.unassigned),
|
||||
subtext: `${calcPercent(stats.unassigned)} · sẵn sàng phân công`,
|
||||
},
|
||||
{
|
||||
label: 'Đang làm',
|
||||
value: formatNum(stats.inProgress),
|
||||
subtext: `${calcPercent(stats.inProgress)} · nhãn đang soạn`,
|
||||
},
|
||||
{
|
||||
label: 'Chờ duyệt',
|
||||
value: formatNum(stats.pendingReview),
|
||||
subtext: `${calcPercent(stats.pendingReview)} · đã gửi kiểm tra`,
|
||||
},
|
||||
{
|
||||
label: 'Hoàn thành',
|
||||
value: formatNum(stats.completed),
|
||||
subtext: `${calcPercent(stats.completed)} · đã được duyệt`,
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{cards.map((c) => (
|
||||
<div
|
||||
key={c.label}
|
||||
className="rounded-2xl border border-slate-200/80 bg-white px-5 py-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]"
|
||||
>
|
||||
<p className="text-xs font-medium text-slate-500">{c.label}</p>
|
||||
<p className="mt-2 text-[28px] font-bold leading-tight tracking-tight text-slate-900">
|
||||
{c.value}
|
||||
</p>
|
||||
<p className="mt-2 text-xs text-slate-500">{c.subtext}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
18
src/pages/projects/components/index.ts
Normal file
18
src/pages/projects/components/index.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
export * from './ProjectStatsCards'
|
||||
export * from './ProjectFilters'
|
||||
export * from './ProjectCard'
|
||||
export * from './ActivityFeed'
|
||||
export * from './TaskTypeSelector'
|
||||
export * from './CreateProjectModal'
|
||||
|
||||
export * from './detail/StatusCards'
|
||||
export * from './detail/LabelDistribution'
|
||||
export * from './detail/MemberAssignment'
|
||||
export * from './detail/ImageTableFilters'
|
||||
export * from './detail/ExportButton'
|
||||
export * from './detail/ImageTable'
|
||||
export * from './detail/OverviewTab'
|
||||
export * from './detail/DataTab'
|
||||
export * from './detail/LabelsTab'
|
||||
export * from './detail/MembersTab'
|
||||
export * from './detail/SettingsTab'
|
||||
4
src/pages/projects/index.ts
Normal file
4
src/pages/projects/index.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export * from './ProjectListPage'
|
||||
export * from './ProjectDetailPage'
|
||||
export * from './components'
|
||||
export * from './projectData'
|
||||
366
src/pages/projects/projectData.ts
Normal file
366
src/pages/projects/projectData.ts
Normal file
|
|
@ -0,0 +1,366 @@
|
|||
import { Project, ImageItem, ActivityLog, CreateProjectInput, LabelClass, ProjectMemberSummary } from '@/types'
|
||||
|
||||
// SVG Data URLs for realistic street/vehicle thumbnails matching the wireframes
|
||||
export const THUMBNAIL_CAR_SEDAN =
|
||||
'https://images.unsplash.com/photo-1549399542-7e3f8b79c341?auto=format&fit=crop&w=900&q=80'
|
||||
|
||||
export const THUMBNAIL_TRAFFIC_STREET =
|
||||
'https://images.unsplash.com/photo-1519003722824-194d4455a60c?auto=format&fit=crop&w=900&q=80'
|
||||
|
||||
export const THUMBNAIL_STREET_SEGMENTATION =
|
||||
'https://images.unsplash.com/photo-1506521781263-d8422e82f27a?auto=format&fit=crop&w=900&q=80'
|
||||
|
||||
export const INITIAL_PROJECTS: Project[] = [
|
||||
{
|
||||
id: 'urban_vehicles_v2',
|
||||
name: 'Phương tiện đô thị',
|
||||
slug: 'urban_vehicles_v2',
|
||||
description: 'Phân loại phương tiện ở cấp ảnh',
|
||||
taskType: 'classification',
|
||||
status: 'annotating',
|
||||
thumbnailUrl: THUMBNAIL_CAR_SEDAN,
|
||||
updatedAt: 'Cập nhật 5 phút trước',
|
||||
classes: [
|
||||
{ id: 'cls-car', name: 'Ô tô', color: '#06B6D4', count: 980, shortcutKey: '1' },
|
||||
{ id: 'cls-motorbike', name: 'Xe máy', color: '#F59E0B', count: 1120, shortcutKey: '2' },
|
||||
{ id: 'cls-bus', name: 'Xe buýt', color: '#A855F7', count: 140, shortcutKey: '3' },
|
||||
{ id: 'cls-truck', name: 'Xe tải', color: '#3B82F6', count: 160, shortcutKey: '4' },
|
||||
],
|
||||
stats: {
|
||||
totalImages: 2400,
|
||||
unassigned: 420,
|
||||
inProgress: 180,
|
||||
pendingReview: 244,
|
||||
completed: 1556,
|
||||
totalObjects: 2400,
|
||||
},
|
||||
members: [
|
||||
{ id: 'mem-ma', name: 'Minh Anh', initials: 'MA', color: '#E0E7FF', role: 'manager', assignedCount: 400 },
|
||||
{ id: 'mem-hl', name: 'Hà Linh', initials: 'HL', color: '#DBEAFE', role: 'annotator', assignedCount: 1100 },
|
||||
{ id: 'mem-tn', name: 'Tuấn Nam', initials: 'TN', color: '#FCE7F3', role: 'annotator', assignedCount: 900 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'traffic_camera_v2',
|
||||
name: 'Giao thông đô thị',
|
||||
slug: 'traffic_camera_v2',
|
||||
description: 'Hộp giới hạn cho camera giao thông',
|
||||
taskType: 'object_detection',
|
||||
status: 'pending_review',
|
||||
thumbnailUrl: THUMBNAIL_TRAFFIC_STREET,
|
||||
updatedAt: 'Cập nhật 5 phút trước',
|
||||
classes: [
|
||||
{ id: 'cls-car', name: 'Ô tô', color: '#06B6D4', count: 1420, shortcutKey: '1' },
|
||||
{ id: 'cls-motorbike', name: 'Xe máy', color: '#F59E0B', count: 1860, shortcutKey: '2' },
|
||||
{ id: 'cls-bus', name: 'Xe buýt', color: '#A855F7', count: 264, shortcutKey: '3' },
|
||||
{ id: 'cls-truck', name: 'Xe tải', color: '#3B82F6', count: 312, shortcutKey: '4' },
|
||||
],
|
||||
stats: {
|
||||
totalImages: 1280,
|
||||
unassigned: 240,
|
||||
inProgress: 80,
|
||||
pendingReview: 128,
|
||||
completed: 832,
|
||||
totalObjects: 3856,
|
||||
},
|
||||
members: [
|
||||
{ id: 'mem-ma', name: 'Minh Anh', initials: 'MA', color: '#E0E7FF', role: 'manager', assignedCount: 240 },
|
||||
{ id: 'mem-th', name: 'Thu Hà', initials: 'TH', color: '#FFEDD5', role: 'reviewer', assignedCount: 128, pendingReviewCount: 128 },
|
||||
{ id: 'mem-hl', name: 'Hà Linh', initials: 'HL', color: '#DBEAFE', role: 'annotator', assignedCount: 480 },
|
||||
{ id: 'mem-tn', name: 'Tuấn Nam', initials: 'TN', color: '#EDE9FE', role: 'annotator', assignedCount: 560 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'street_masks_v1',
|
||||
name: 'Phân vùng đường phố',
|
||||
slug: 'street_masks_v1',
|
||||
description: 'Polygon và mask cho từng đối tượng',
|
||||
taskType: 'segmentation',
|
||||
status: 'annotating',
|
||||
thumbnailUrl: THUMBNAIL_STREET_SEGMENTATION,
|
||||
updatedAt: 'Cập nhật 5 phút trước',
|
||||
classes: [
|
||||
{ id: 'cls-car', name: 'Ô tô', color: '#06B6D4', count: 520, shortcutKey: '1' },
|
||||
{ id: 'cls-motorbike', name: 'Xe máy', color: '#F59E0B', count: 640, shortcutKey: '2' },
|
||||
{ id: 'cls-bus', name: 'Xe buýt', color: '#A855F7', count: 110, shortcutKey: '3' },
|
||||
{ id: 'cls-truck', name: 'Xe tải', color: '#3B82F6', count: 145, shortcutKey: '4' },
|
||||
],
|
||||
stats: {
|
||||
totalImages: 640,
|
||||
unassigned: 196,
|
||||
inProgress: 60,
|
||||
pendingReview: 0,
|
||||
completed: 384,
|
||||
totalObjects: 1415,
|
||||
},
|
||||
members: [
|
||||
{ id: 'mem-ma', name: 'Minh Anh', initials: 'MA', color: '#E0E7FF', role: 'manager', assignedCount: 140 },
|
||||
{ id: 'mem-hl', name: 'Hà Linh', initials: 'HL', color: '#DBEAFE', role: 'annotator', assignedCount: 260 },
|
||||
{ id: 'mem-tn', name: 'Tuấn Nam', initials: 'TN', color: '#FCE7F3', role: 'annotator', assignedCount: 240 },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export const INITIAL_PROJECT_IMAGES: ImageItem[] = [
|
||||
{
|
||||
id: 'img-321',
|
||||
projectId: 'traffic_camera_v2',
|
||||
fileName: 'traffic_00321.jpg',
|
||||
url: THUMBNAIL_TRAFFIC_STREET,
|
||||
thumbnailUrl: THUMBNAIL_TRAFFIC_STREET,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
status: 'pending_review',
|
||||
objectCount: 4,
|
||||
assignedTo: { id: 'mem-th', name: 'Thu Hà', role: 'reviewer' },
|
||||
reviewerName: 'Thu Hà',
|
||||
submittedBy: 'Hà Linh',
|
||||
submittedAt: '10 phút trước',
|
||||
},
|
||||
{
|
||||
id: 'img-322',
|
||||
projectId: 'traffic_camera_v2',
|
||||
fileName: 'traffic_00322.jpg',
|
||||
url: THUMBNAIL_STREET_SEGMENTATION,
|
||||
thumbnailUrl: THUMBNAIL_STREET_SEGMENTATION,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
status: 'in_progress',
|
||||
objectCount: 2,
|
||||
assignedTo: { id: 'mem-hl', name: 'Hà Linh', role: 'annotator' },
|
||||
savedAt: '5 phút trước',
|
||||
},
|
||||
{
|
||||
id: 'img-323',
|
||||
projectId: 'traffic_camera_v2',
|
||||
fileName: 'traffic_00323.jpg',
|
||||
url: THUMBNAIL_CAR_SEDAN,
|
||||
thumbnailUrl: THUMBNAIL_CAR_SEDAN,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
status: 'completed',
|
||||
objectCount: 3,
|
||||
assignedTo: { id: 'mem-th', name: 'Thu Hà', role: 'reviewer' },
|
||||
reviewerName: 'Thu Hà',
|
||||
savedAt: '18 phút trước',
|
||||
},
|
||||
{
|
||||
id: 'img-324',
|
||||
projectId: 'traffic_camera_v2',
|
||||
fileName: 'traffic_00324.jpg',
|
||||
url: THUMBNAIL_TRAFFIC_STREET,
|
||||
thumbnailUrl: THUMBNAIL_TRAFFIC_STREET,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
status: 'completed',
|
||||
objectCount: 5,
|
||||
assignedTo: { id: 'mem-tn', name: 'Tuấn Nam', role: 'annotator' },
|
||||
savedAt: '25 phút trước',
|
||||
},
|
||||
{
|
||||
id: 'img-325',
|
||||
projectId: 'traffic_camera_v2',
|
||||
fileName: 'traffic_00325.jpg',
|
||||
url: THUMBNAIL_STREET_SEGMENTATION,
|
||||
thumbnailUrl: THUMBNAIL_STREET_SEGMENTATION,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
status: 'pending_review',
|
||||
objectCount: 6,
|
||||
assignedTo: { id: 'mem-th', name: 'Thu Hà', role: 'reviewer' },
|
||||
savedAt: '32 phút trước',
|
||||
},
|
||||
{
|
||||
id: 'img-326',
|
||||
projectId: 'traffic_camera_v2',
|
||||
fileName: 'traffic_00326.jpg',
|
||||
url: THUMBNAIL_CAR_SEDAN,
|
||||
thumbnailUrl: THUMBNAIL_CAR_SEDAN,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
status: 'unassigned',
|
||||
objectCount: 0,
|
||||
assignedTo: { id: 'mem-hl', name: 'Hà Linh', role: 'annotator' },
|
||||
},
|
||||
]
|
||||
|
||||
export const INITIAL_ACTIVITIES: ActivityLog[] = [
|
||||
{
|
||||
id: 'act-1',
|
||||
timestamp: '09:42',
|
||||
userName: 'Hà Linh',
|
||||
actionText: 'đã gán nhãn 24 ảnh',
|
||||
projectId: 'traffic_camera_v2',
|
||||
},
|
||||
{
|
||||
id: 'act-2',
|
||||
timestamp: '09:38',
|
||||
userName: 'Thu Hà',
|
||||
actionText: 'đã duyệt 16 ảnh giao thông',
|
||||
projectId: 'traffic_camera_v2',
|
||||
},
|
||||
{
|
||||
id: 'act-3',
|
||||
timestamp: '09:15',
|
||||
userName: 'Tuấn Nam',
|
||||
actionText: 'đã gửi duyệt lô 32 ảnh đường phố',
|
||||
projectId: 'street_masks_v1',
|
||||
},
|
||||
{
|
||||
id: 'act-4',
|
||||
timestamp: '08:50',
|
||||
userName: 'Minh Anh',
|
||||
actionText: 'đã cập nhật bộ nhãn Phương tiện đô thị',
|
||||
projectId: 'urban_vehicles_v2',
|
||||
},
|
||||
]
|
||||
|
||||
// Simple reactive in-memory store with listener subscription so changes persist across navigations
|
||||
let projectsStore: Project[] = [...INITIAL_PROJECTS]
|
||||
let imagesStore: ImageItem[] = [...INITIAL_PROJECT_IMAGES]
|
||||
let activitiesStore: ActivityLog[] = [...INITIAL_ACTIVITIES]
|
||||
const listeners = new Set<() => void>()
|
||||
|
||||
function notifyListeners() {
|
||||
listeners.forEach((fn) => fn())
|
||||
}
|
||||
|
||||
export function subscribeProjectsStore(listener: () => void): () => void {
|
||||
listeners.add(listener)
|
||||
return () => {
|
||||
listeners.delete(listener)
|
||||
}
|
||||
}
|
||||
|
||||
export function getProjects(): Project[] {
|
||||
return projectsStore
|
||||
}
|
||||
|
||||
export function getProjectById(projectId?: string): Project {
|
||||
if (!projectId) return projectsStore[1] ?? projectsStore[0]!
|
||||
const found = projectsStore.find((p) => p.id === projectId || p.slug === projectId)
|
||||
return found ?? projectsStore[1] ?? projectsStore[0]!
|
||||
}
|
||||
|
||||
export function getProjectImages(projectId: string): ImageItem[] {
|
||||
const filtered = imagesStore.filter((img) => img.projectId === projectId)
|
||||
if (filtered.length > 0) return filtered
|
||||
return imagesStore
|
||||
}
|
||||
|
||||
export function getActivities(): ActivityLog[] {
|
||||
return activitiesStore
|
||||
}
|
||||
|
||||
export function addProject(input: CreateProjectInput): Project {
|
||||
const slug =
|
||||
input.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.replace(/đ/g, 'd')
|
||||
.replace(/[^a-z0-9]+/g, '_')
|
||||
.replace(/^_|_$/g, '') + '_v1'
|
||||
|
||||
const newProject: Project = {
|
||||
id: slug || `project_${Date.now()}`,
|
||||
name: input.name.trim(),
|
||||
slug: slug || `dataset_${Date.now()}`,
|
||||
description: input.description.trim() || 'Bộ dữ liệu gán nhãn mới',
|
||||
taskType: input.taskType,
|
||||
status: 'annotating',
|
||||
thumbnailUrl:
|
||||
input.taskType === 'classification'
|
||||
? THUMBNAIL_CAR_SEDAN
|
||||
: input.taskType === 'object_detection'
|
||||
? THUMBNAIL_TRAFFIC_STREET
|
||||
: THUMBNAIL_STREET_SEGMENTATION,
|
||||
updatedAt: 'Vừa tạo xong',
|
||||
classes: [
|
||||
{ id: 'cls-car', name: 'Ô tô', color: '#06B6D4', count: 0, shortcutKey: '1' },
|
||||
{ id: 'cls-motorbike', name: 'Xe máy', color: '#F59E0B', count: 0, shortcutKey: '2' },
|
||||
{ id: 'cls-bus', name: 'Xe buýt', color: '#A855F7', count: 0, shortcutKey: '3' },
|
||||
{ id: 'cls-truck', name: 'Xe tải', color: '#3B82F6', count: 0, shortcutKey: '4' },
|
||||
],
|
||||
stats: {
|
||||
totalImages: 0,
|
||||
unassigned: 0,
|
||||
inProgress: 0,
|
||||
pendingReview: 0,
|
||||
completed: 0,
|
||||
totalObjects: 0,
|
||||
},
|
||||
members: [
|
||||
{ id: 'mem-ma', name: 'Minh Anh', initials: 'MA', color: '#E0E7FF', role: 'manager', assignedCount: 0 },
|
||||
],
|
||||
}
|
||||
|
||||
projectsStore = [newProject, ...projectsStore]
|
||||
const now = new Date()
|
||||
const hh = String(now.getHours()).padStart(2, '0')
|
||||
const mm = String(now.getMinutes()).padStart(2, '0')
|
||||
activitiesStore = [
|
||||
{
|
||||
id: `act-${Date.now()}`,
|
||||
timestamp: `${hh}:${mm}`,
|
||||
userName: 'Minh Anh',
|
||||
actionText: `đã tạo dự án ${newProject.name}`,
|
||||
projectId: newProject.id,
|
||||
},
|
||||
...activitiesStore,
|
||||
]
|
||||
notifyListeners()
|
||||
return newProject
|
||||
}
|
||||
|
||||
export function updateProject(projectId: string, updater: (project: Project) => Project): void {
|
||||
projectsStore = projectsStore.map((p) => (p.id === projectId || p.slug === projectId ? updater(p) : p))
|
||||
notifyListeners()
|
||||
}
|
||||
|
||||
export function deleteProjectById(projectId: string): void {
|
||||
projectsStore = projectsStore.filter((p) => p.id !== projectId && p.slug !== projectId)
|
||||
notifyListeners()
|
||||
}
|
||||
|
||||
export function addUploadedImagesToProject(projectId: string, fileNames: string[]): void {
|
||||
const newItems: ImageItem[] = fileNames.map((name, idx) => ({
|
||||
id: `img-upload-${Date.now()}-${idx}`,
|
||||
projectId,
|
||||
fileName: name,
|
||||
url: idx % 2 === 0 ? THUMBNAIL_TRAFFIC_STREET : THUMBNAIL_CAR_SEDAN,
|
||||
thumbnailUrl: idx % 2 === 0 ? THUMBNAIL_TRAFFIC_STREET : THUMBNAIL_CAR_SEDAN,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
status: 'unassigned',
|
||||
objectCount: 0,
|
||||
assignedTo: { id: 'mem-hl', name: 'Hà Linh', role: 'annotator' },
|
||||
savedAt: 'Vừa tải lên',
|
||||
}))
|
||||
imagesStore = [...newItems, ...imagesStore]
|
||||
updateProject(projectId, (p) => ({
|
||||
...p,
|
||||
updatedAt: 'Vừa cập nhật',
|
||||
stats: {
|
||||
...p.stats,
|
||||
totalImages: p.stats.totalImages + fileNames.length,
|
||||
unassigned: p.stats.unassigned + fileNames.length,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
export function updateProjectClasses(projectId: string, classes: LabelClass[]): void {
|
||||
updateProject(projectId, (p) => ({
|
||||
...p,
|
||||
classes,
|
||||
updatedAt: 'Vừa cập nhật',
|
||||
}))
|
||||
}
|
||||
|
||||
export function updateProjectMembers(projectId: string, members: ProjectMemberSummary[]): void {
|
||||
updateProject(projectId, (p) => ({
|
||||
...p,
|
||||
members,
|
||||
updatedAt: 'Vừa cập nhật',
|
||||
}))
|
||||
}
|
||||
431
src/pages/users/UserManagementPage.tsx
Normal file
431
src/pages/users/UserManagementPage.tsx
Normal file
|
|
@ -0,0 +1,431 @@
|
|||
import React, { useState, useMemo } from 'react'
|
||||
import {
|
||||
WorkspaceMember,
|
||||
UserRole,
|
||||
UserStatus,
|
||||
InviteMemberInput,
|
||||
} from '../../types'
|
||||
import { UserStatsCards } from './components/UserStatsCards'
|
||||
import { UserTableFilters } from './components/UserTableFilters'
|
||||
import { UserTable } from './components/UserTable'
|
||||
import { InviteUserModal } from './components/InviteUserModal'
|
||||
import { PendingInvitesTab } from './components/PendingInvitesTab'
|
||||
import { RolesPermissionsTab } from './components/RolesPermissionsTab'
|
||||
import { ROLE_ACCESS_SUMMARIES } from './components/UserRoleBadge'
|
||||
|
||||
const INITIAL_MEMBERS: WorkspaceMember[] = [
|
||||
{
|
||||
id: 'usr-1',
|
||||
name: 'Minh Anh',
|
||||
email: 'minhanh@visionlab.vn',
|
||||
initials: 'MA',
|
||||
avatarColor: '#FCE7DE',
|
||||
role: 'admin',
|
||||
status: 'active',
|
||||
isCurrentUser: true,
|
||||
assignedProjectsText: 'Tất cả 3 dự án',
|
||||
assignedProjectIds: ['proj-1', 'proj-2', 'proj-3'],
|
||||
accessSummary: 'Toàn quyền',
|
||||
activityStatusText: 'Đang trực tuyến',
|
||||
isOnline: true,
|
||||
},
|
||||
{
|
||||
id: 'usr-2',
|
||||
name: 'Hoàng Long',
|
||||
email: 'hoanglong@visionlab.vn',
|
||||
initials: 'HL',
|
||||
avatarColor: '#FCE7DE',
|
||||
role: 'manager',
|
||||
status: 'active',
|
||||
assignedProjectsText: 'Tất cả 3 dự án',
|
||||
assignedProjectIds: ['proj-1', 'proj-2', 'proj-3'],
|
||||
accessSummary: 'Quản lý & phân công',
|
||||
activityStatusText: '5 phút trước',
|
||||
isOnline: false,
|
||||
},
|
||||
{
|
||||
id: 'usr-3',
|
||||
name: 'Hà Linh',
|
||||
email: 'halinh@visionlab.vn',
|
||||
initials: 'HL',
|
||||
avatarColor: '#FCE7DE',
|
||||
role: 'annotator',
|
||||
status: 'active',
|
||||
assignedProjectsText: 'Tất cả 3 dự án',
|
||||
assignedProjectIds: ['proj-1', 'proj-2', 'proj-3'],
|
||||
accessSummary: 'Tạo / sửa nhãn',
|
||||
activityStatusText: 'Đang trực tuyến',
|
||||
isOnline: true,
|
||||
},
|
||||
{
|
||||
id: 'usr-4',
|
||||
name: 'Tuấn Nam',
|
||||
email: 'tuannam@visionlab.vn',
|
||||
initials: 'TN',
|
||||
avatarColor: '#FCE7DE',
|
||||
role: 'annotator',
|
||||
status: 'active',
|
||||
assignedProjectsText: 'Tất cả 3 dự án',
|
||||
assignedProjectIds: ['proj-1', 'proj-2', 'proj-3'],
|
||||
accessSummary: 'Tạo / sửa nhãn',
|
||||
activityStatusText: '2 phút trước',
|
||||
isOnline: false,
|
||||
},
|
||||
{
|
||||
id: 'usr-5',
|
||||
name: 'Thu Hà',
|
||||
email: 'thuha@visionlab.vn',
|
||||
initials: 'TH',
|
||||
avatarColor: '#FCE7DE',
|
||||
role: 'reviewer',
|
||||
status: 'active',
|
||||
assignedProjectsText: 'Tất cả 3 dự án',
|
||||
assignedProjectIds: ['proj-1', 'proj-2', 'proj-3'],
|
||||
accessSummary: 'Duyệt / trả lại nhãn',
|
||||
activityStatusText: 'Đang trực tuyến',
|
||||
isOnline: true,
|
||||
},
|
||||
{
|
||||
id: 'usr-6',
|
||||
name: 'Đức Minh',
|
||||
email: 'ducminh@visionlab.vn',
|
||||
initials: 'DM',
|
||||
avatarColor: '#FCE7DE',
|
||||
role: 'reviewer',
|
||||
status: 'active',
|
||||
assignedProjectsText: 'Phân vùng đường phố',
|
||||
assignedProjectIds: ['proj-3'],
|
||||
accessSummary: 'Duyệt / trả lại nhãn',
|
||||
activityStatusText: '1 giờ trước',
|
||||
isOnline: false,
|
||||
},
|
||||
{
|
||||
id: 'usr-7',
|
||||
name: 'Bảo Trâm',
|
||||
email: 'baotram@visionlab.vn',
|
||||
initials: 'BT',
|
||||
avatarColor: '#E0E7FF',
|
||||
role: 'annotator',
|
||||
status: 'invited',
|
||||
assignedProjectsText: 'Giao thông đô thị',
|
||||
assignedProjectIds: ['proj-2'],
|
||||
accessSummary: 'Tạo / sửa nhãn',
|
||||
activityStatusText: 'Đã mời 2 ngày trước',
|
||||
isOnline: false,
|
||||
},
|
||||
{
|
||||
id: 'usr-8',
|
||||
name: 'Quốc Khánh',
|
||||
email: 'quockhanh@visionlab.vn',
|
||||
initials: 'QK',
|
||||
avatarColor: '#F1F5F9',
|
||||
role: 'annotator',
|
||||
status: 'suspended',
|
||||
assignedProjectsText: 'Phương tiện đô thị',
|
||||
assignedProjectIds: ['proj-1'],
|
||||
accessSummary: 'Tạm khóa truy cập',
|
||||
activityStatusText: 'Ngừng hoạt động',
|
||||
isOnline: false,
|
||||
},
|
||||
]
|
||||
|
||||
export const UserManagementPage: React.FC = () => {
|
||||
const [members, setMembers] = useState<WorkspaceMember[]>(INITIAL_MEMBERS)
|
||||
const [activeTab, setActiveTab] = useState<'members' | 'invites' | 'roles'>(
|
||||
'members'
|
||||
)
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [roleFilter, setRoleFilter] = useState<UserRole | 'all'>('all')
|
||||
const [statusFilter, setStatusFilter] = useState<UserStatus | 'all'>('all')
|
||||
const [projectFilter, setProjectFilter] = useState<string>('all')
|
||||
const [inviteModalOpen, setInviteModalOpen] = useState(false)
|
||||
const [toastMessage, setToastMessage] = useState<string | null>(null)
|
||||
|
||||
const showToast = (msg: string) => {
|
||||
setToastMessage(msg)
|
||||
setTimeout(() => {
|
||||
setToastMessage((prev) => (prev === msg ? null : prev))
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
const stats = useMemo(() => {
|
||||
const totalMembers = members.length
|
||||
const activeMembers = members.filter((m) => m.status === 'active').length
|
||||
const onlineCount = members.filter((m) => m.isOnline).length
|
||||
const pendingInvites = members.filter((m) => m.status === 'invited').length
|
||||
const suspendedMembers = members.filter(
|
||||
(m) => m.status === 'suspended'
|
||||
).length
|
||||
return {
|
||||
totalMembers,
|
||||
activeMembers,
|
||||
onlineCount,
|
||||
pendingInvites,
|
||||
suspendedMembers,
|
||||
}
|
||||
}, [members])
|
||||
|
||||
const filteredMembers = useMemo(() => {
|
||||
return members.filter((member) => {
|
||||
const q = searchQuery.trim().toLowerCase()
|
||||
if (
|
||||
q &&
|
||||
!member.name.toLowerCase().includes(q) &&
|
||||
!member.email.toLowerCase().includes(q)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
if (roleFilter !== 'all' && member.role !== roleFilter) {
|
||||
return false
|
||||
}
|
||||
if (statusFilter !== 'all' && member.status !== statusFilter) {
|
||||
return false
|
||||
}
|
||||
if (
|
||||
projectFilter !== 'all' &&
|
||||
!member.assignedProjectIds.includes(projectFilter)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
}, [members, searchQuery, roleFilter, statusFilter, projectFilter])
|
||||
|
||||
const pendingInvitesList = useMemo(
|
||||
() => members.filter((m) => m.status === 'invited'),
|
||||
[members]
|
||||
)
|
||||
|
||||
const handleChangeRole = (memberId: string, newRole: UserRole) => {
|
||||
setMembers((prev) =>
|
||||
prev.map((m) =>
|
||||
m.id === memberId
|
||||
? {
|
||||
...m,
|
||||
role: newRole,
|
||||
accessSummary: ROLE_ACCESS_SUMMARIES[newRole],
|
||||
}
|
||||
: m
|
||||
)
|
||||
)
|
||||
showToast('Đã cập nhật vai trò thành viên.')
|
||||
}
|
||||
|
||||
const handleToggleStatus = (memberId: string) => {
|
||||
setMembers((prev) =>
|
||||
prev.map((m) => {
|
||||
if (m.id !== memberId) return m
|
||||
const nextStatus: UserStatus =
|
||||
m.status === 'suspended' ? 'active' : 'suspended'
|
||||
return {
|
||||
...m,
|
||||
status: nextStatus,
|
||||
accessSummary:
|
||||
nextStatus === 'suspended'
|
||||
? 'Tạm khóa truy cập'
|
||||
: ROLE_ACCESS_SUMMARIES[m.role],
|
||||
}
|
||||
})
|
||||
)
|
||||
showToast('Đã cập nhật trạng thái tài khoản.')
|
||||
}
|
||||
|
||||
const handleInviteMember = (input: InviteMemberInput) => {
|
||||
const emailPrefix = input.email.split('@')[0] || 'Thành viên'
|
||||
const formattedName = emailPrefix
|
||||
.replace(/[._-]/g, ' ')
|
||||
.replace(/\b\w/g, (l) => l.toUpperCase())
|
||||
const initials = formattedName
|
||||
.split(' ')
|
||||
.map((part) => part[0])
|
||||
.join('')
|
||||
.slice(0, 2)
|
||||
.toUpperCase()
|
||||
|
||||
const assignedText =
|
||||
input.projectIds.length >= 3
|
||||
? 'Tất cả 3 dự án'
|
||||
: input.projectIds.length === 1
|
||||
? '1 dự án'
|
||||
: `${input.projectIds.length} dự án`
|
||||
|
||||
const newMember: WorkspaceMember = {
|
||||
id: `usr-${Date.now()}`,
|
||||
name: formattedName,
|
||||
email: input.email,
|
||||
initials: initials || 'NV',
|
||||
avatarColor: '#FCE7DE',
|
||||
role: input.role,
|
||||
status: 'invited',
|
||||
assignedProjectsText: assignedText,
|
||||
assignedProjectIds: input.projectIds,
|
||||
accessSummary: ROLE_ACCESS_SUMMARIES[input.role],
|
||||
activityStatusText: 'Vừa gửi lời mời',
|
||||
isOnline: false,
|
||||
}
|
||||
|
||||
setMembers((prev) => [newMember, ...prev])
|
||||
showToast(`Đã gửi lời mời đến ${input.email}`)
|
||||
}
|
||||
|
||||
const handleResendInvite = (id: string) => {
|
||||
const target = members.find((m) => m.id === id)
|
||||
if (target) {
|
||||
showToast(`Đã gửi lại email lời mời cho ${target.email}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCancelInvite = (id: string) => {
|
||||
setMembers((prev) => prev.filter((m) => m.id !== id))
|
||||
showToast('Đã hủy lời mời.')
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full max-w-[1220px] mx-auto">
|
||||
{/* Toast Notification */}
|
||||
{toastMessage && (
|
||||
<div className="fixed bottom-5 right-5 z-50 px-4 py-2.5 rounded-xl bg-slate-900 text-white text-xs font-medium shadow-lg">
|
||||
{toastMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Page Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6">
|
||||
<div>
|
||||
<h1 className="text-[28px] font-bold text-slate-900 tracking-tight leading-tight">
|
||||
Người dùng & quyền truy cập
|
||||
</h1>
|
||||
<p className="text-sm text-slate-500 mt-1">
|
||||
Quản lý thành viên, vai trò và phạm vi dự án trong danable.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setInviteModalOpen(true)}
|
||||
className="inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-[#C95C3C] hover:bg-[#B5492B] text-white text-sm font-semibold shadow-sm transition-colors shrink-0"
|
||||
>
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" />
|
||||
<circle cx="9" cy="7" r="4" />
|
||||
<line x1="19" x2="19" y1="8" y2="14" />
|
||||
<line x1="22" x2="16" y1="11" y2="11" />
|
||||
</svg>
|
||||
<span>Mời người dùng</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 4 KPI Cards */}
|
||||
<UserStatsCards
|
||||
totalMembers={stats.totalMembers}
|
||||
activeMembers={stats.activeMembers}
|
||||
onlineCount={stats.onlineCount}
|
||||
pendingInvites={stats.pendingInvites}
|
||||
suspendedMembers={stats.suspendedMembers}
|
||||
/>
|
||||
|
||||
{/* Tabs Navigation */}
|
||||
<div className="border-b border-slate-200 mb-5 flex items-center gap-7">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setActiveTab('members')}
|
||||
className={`pb-3 text-xs sm:text-[13px] font-semibold transition-colors border-b-2 -mb-px flex items-center gap-1.5 ${
|
||||
activeTab === 'members'
|
||||
? 'border-indigo-600 text-indigo-600'
|
||||
: 'border-transparent text-slate-500 hover:text-slate-800'
|
||||
}`}
|
||||
>
|
||||
<span>Thành viên</span>
|
||||
<span>{stats.totalMembers}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setActiveTab('invites')}
|
||||
className={`pb-3 text-xs sm:text-[13px] font-medium transition-colors border-b-2 -mb-px flex items-center gap-1.5 ${
|
||||
activeTab === 'invites'
|
||||
? 'border-indigo-600 text-indigo-600 font-semibold'
|
||||
: 'border-transparent text-slate-500 hover:text-slate-800'
|
||||
}`}
|
||||
>
|
||||
<span>Lời mời</span>
|
||||
<span>{stats.pendingInvites}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setActiveTab('roles')}
|
||||
className={`pb-3 text-xs sm:text-[13px] font-medium transition-colors border-b-2 -mb-px ${
|
||||
activeTab === 'roles'
|
||||
? 'border-indigo-600 text-indigo-600 font-semibold'
|
||||
: 'border-transparent text-slate-500 hover:text-slate-800'
|
||||
}`}
|
||||
>
|
||||
Vai trò & quyền
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Tab Content */}
|
||||
{activeTab === 'members' && (
|
||||
<div className="rounded-2xl border border-slate-200 bg-white shadow-[0_1px_2px_rgba(15,23,42,0.03)] overflow-hidden">
|
||||
{/* Card Header + Filters */}
|
||||
<div className="p-5 space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-[15px] font-bold text-slate-900">
|
||||
Thành viên trong nhóm
|
||||
</h2>
|
||||
<span className="text-xs font-semibold text-indigo-600">
|
||||
{filteredMembers.length} người dùng
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<UserTableFilters
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={setSearchQuery}
|
||||
roleFilter={roleFilter}
|
||||
onRoleFilterChange={setRoleFilter}
|
||||
statusFilter={statusFilter}
|
||||
onStatusFilterChange={setStatusFilter}
|
||||
projectFilter={projectFilter}
|
||||
onProjectFilterChange={setProjectFilter}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Members Table */}
|
||||
<UserTable
|
||||
members={filteredMembers}
|
||||
onChangeRole={handleChangeRole}
|
||||
onToggleStatus={handleToggleStatus}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'invites' && (
|
||||
<PendingInvitesTab
|
||||
invites={pendingInvitesList}
|
||||
onResendInvite={handleResendInvite}
|
||||
onCancelInvite={handleCancelInvite}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'roles' && <RolesPermissionsTab />}
|
||||
|
||||
{/* Invite User Modal */}
|
||||
<InviteUserModal
|
||||
isOpen={inviteModalOpen}
|
||||
onClose={() => setInviteModalOpen(false)}
|
||||
onInvite={handleInviteMember}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default UserManagementPage
|
||||
199
src/pages/users/components/InviteUserModal.tsx
Normal file
199
src/pages/users/components/InviteUserModal.tsx
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
import React, { useState } from 'react'
|
||||
import { InviteMemberInput, UserRole } from '../../../types'
|
||||
|
||||
export interface InviteUserModalProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
onInvite: (input: InviteMemberInput) => void
|
||||
}
|
||||
|
||||
const AVAILABLE_PROJECTS = [
|
||||
{ id: 'proj-1', name: 'Phương tiện đô thị', count: '1.850 ảnh' },
|
||||
{ id: 'proj-2', name: 'Giao thông đô thị', count: '1.420 ảnh' },
|
||||
{ id: 'proj-3', name: 'Phân vùng đường phố', count: '1.050 ảnh' },
|
||||
]
|
||||
|
||||
export const InviteUserModal: React.FC<InviteUserModalProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
onInvite,
|
||||
}) => {
|
||||
const [email, setEmail] = useState('')
|
||||
const [role, setRole] = useState<UserRole>('annotator')
|
||||
const [selectedProjects, setSelectedProjects] = useState<string[]>([
|
||||
'proj-1',
|
||||
'proj-2',
|
||||
'proj-3',
|
||||
])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
if (!isOpen) return null
|
||||
|
||||
const toggleProject = (id: string) => {
|
||||
setSelectedProjects((prev) =>
|
||||
prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]
|
||||
)
|
||||
}
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!email.trim() || !email.includes('@')) {
|
||||
setError('Vui lòng nhập địa chỉ email hợp lệ.')
|
||||
return
|
||||
}
|
||||
setError(null)
|
||||
onInvite({
|
||||
email: email.trim(),
|
||||
role,
|
||||
projectIds: selectedProjects,
|
||||
})
|
||||
setEmail('')
|
||||
setRole('annotator')
|
||||
onClose()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/40 backdrop-blur-[1px] p-4">
|
||||
<div className="bg-white rounded-2xl max-w-lg w-full border border-slate-200 shadow-xl overflow-hidden">
|
||||
{/* Modal Header */}
|
||||
<div className="flex items-center justify-between px-6 py-4 border-b border-slate-200">
|
||||
<div>
|
||||
<h3 className="text-base font-bold text-slate-900">
|
||||
Mời người dùng mới
|
||||
</h3>
|
||||
<p className="text-xs text-slate-500 mt-0.5">
|
||||
Gửi lời mời tham gia không gian nhóm danable qua email công việc.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="p-1.5 rounded-lg text-slate-400 hover:text-slate-700 hover:bg-slate-100"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Form Body */}
|
||||
<form onSubmit={handleSubmit} className="p-6 space-y-5">
|
||||
{error && (
|
||||
<div className="px-3.5 py-2.5 rounded-xl bg-rose-50 border border-rose-200 text-xs text-rose-700">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Email */}
|
||||
<div>
|
||||
<label className="block text-xs font-semibold text-slate-800 mb-1.5">
|
||||
Email công việc
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="thanhvien@visionlab.vn"
|
||||
className="w-full px-3.5 py-2.5 rounded-xl border border-slate-200 text-sm text-slate-900 focus:outline-none focus:border-[#C95C3C]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Role Selection */}
|
||||
<div>
|
||||
<label className="block text-xs font-semibold text-slate-800 mb-2">
|
||||
Vai trò trong nhóm
|
||||
</label>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2.5">
|
||||
{(
|
||||
[
|
||||
{
|
||||
value: 'annotator',
|
||||
title: 'Người gán nhãn',
|
||||
desc: 'Tạo & sửa nhãn',
|
||||
},
|
||||
{
|
||||
value: 'reviewer',
|
||||
title: 'Người duyệt',
|
||||
desc: 'Duyệt & trả lại nhãn',
|
||||
},
|
||||
{
|
||||
value: 'manager',
|
||||
title: 'Quản lý',
|
||||
desc: 'Quản lý & phân công',
|
||||
},
|
||||
] as const
|
||||
).map((item) => {
|
||||
const active = role === item.value
|
||||
return (
|
||||
<button
|
||||
key={item.value}
|
||||
type="button"
|
||||
onClick={() => setRole(item.value)}
|
||||
className={`text-left p-3 rounded-xl border transition-all ${
|
||||
active
|
||||
? 'border-[#C95C3C] bg-[#FDF4F1] ring-1 ring-[#C95C3C]'
|
||||
: 'border-slate-200 bg-white hover:bg-slate-50'
|
||||
}`}
|
||||
>
|
||||
<div className="text-xs font-bold text-slate-900">
|
||||
{item.title}
|
||||
</div>
|
||||
<div className="text-[11px] text-slate-500 mt-0.5">
|
||||
{item.desc}
|
||||
</div>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Project Assignment Checkboxes */}
|
||||
<div>
|
||||
<label className="block text-xs font-semibold text-slate-800 mb-2">
|
||||
Dự án được phân công
|
||||
</label>
|
||||
<div className="space-y-2 rounded-xl border border-slate-200 p-3 bg-slate-50/50">
|
||||
{AVAILABLE_PROJECTS.map((proj) => {
|
||||
const checked = selectedProjects.includes(proj.id)
|
||||
return (
|
||||
<label
|
||||
key={proj.id}
|
||||
className="flex items-center justify-between text-xs text-slate-800 cursor-pointer py-1 px-1"
|
||||
>
|
||||
<span className="inline-flex items-center gap-2.5 font-medium">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
onChange={() => toggleProject(proj.id)}
|
||||
className="w-4 h-4 rounded border-slate-300 accent-[#C95C3C]"
|
||||
/>
|
||||
<span>{proj.name}</span>
|
||||
</span>
|
||||
<span className="text-slate-400">{proj.count}</span>
|
||||
</label>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer Buttons */}
|
||||
<div className="flex items-center justify-end gap-2.5 pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="px-4 py-2.5 rounded-xl border border-slate-200 bg-white text-xs font-semibold text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
Hủy
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="px-4 py-2.5 rounded-xl bg-[#C95C3C] hover:bg-[#B5492B] text-white text-xs font-semibold shadow-sm transition-colors"
|
||||
>
|
||||
Gửi lời mời
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default InviteUserModal
|
||||
91
src/pages/users/components/PendingInvitesTab.tsx
Normal file
91
src/pages/users/components/PendingInvitesTab.tsx
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
import React from 'react'
|
||||
import { WorkspaceMember } from '../../../types'
|
||||
import { ROLE_LABELS } from './UserRoleBadge'
|
||||
|
||||
export interface PendingInvitesTabProps {
|
||||
invites: WorkspaceMember[]
|
||||
onResendInvite: (id: string) => void
|
||||
onCancelInvite: (id: string) => void
|
||||
}
|
||||
|
||||
export const PendingInvitesTab: React.FC<PendingInvitesTabProps> = ({
|
||||
invites,
|
||||
onResendInvite,
|
||||
onCancelInvite,
|
||||
}) => {
|
||||
if (invites.length === 0) {
|
||||
return (
|
||||
<div className="rounded-2xl border border-slate-200 bg-white p-10 text-center">
|
||||
<p className="text-sm font-medium text-slate-700">
|
||||
Không có lời mời nào đang chờ xác nhận
|
||||
</p>
|
||||
<p className="text-xs text-slate-500 mt-1">
|
||||
Sử dụng nút “+ Mời người dùng” ở góc phải để thêm thành viên mới.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="rounded-2xl border border-slate-200 bg-white overflow-hidden">
|
||||
<div className="flex items-center justify-between px-5 py-4 border-b border-slate-200">
|
||||
<div>
|
||||
<h3 className="text-sm font-bold text-slate-900">
|
||||
Lời mời đang chờ xác nhận
|
||||
</h3>
|
||||
<p className="text-xs text-slate-500 mt-0.5">
|
||||
Lời mời tự động hết hạn sau 7 ngày kể từ khi gửi.
|
||||
</p>
|
||||
</div>
|
||||
<span className="text-xs font-semibold text-indigo-600">
|
||||
{invites.length} lời mời
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="divide-y divide-slate-200">
|
||||
{invites.map((invite) => (
|
||||
<div
|
||||
key={invite.id}
|
||||
className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-5 py-4"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<div
|
||||
style={{ backgroundColor: invite.avatarColor }}
|
||||
className="w-9 h-9 rounded-full flex items-center justify-center text-xs font-bold text-indigo-700"
|
||||
>
|
||||
{invite.initials}
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm font-semibold text-slate-900">
|
||||
{invite.email}
|
||||
</div>
|
||||
<div className="text-xs text-slate-500 mt-0.5">
|
||||
Vai trò: <span className="font-medium text-slate-700">{ROLE_LABELS[invite.role]}</span> · {invite.assignedProjectsText} · {invite.activityStatusText}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onResendInvite(invite.id)}
|
||||
className="px-3 py-1.5 rounded-xl border border-slate-200 bg-white text-xs font-semibold text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
Gửi lại
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onCancelInvite(invite.id)}
|
||||
className="px-3 py-1.5 rounded-xl border border-rose-200 bg-rose-50/50 text-xs font-semibold text-rose-600 hover:bg-rose-100/60"
|
||||
>
|
||||
Hủy lời mời
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default PendingInvitesTab
|
||||
89
src/pages/users/components/RolesPermissionsTab.tsx
Normal file
89
src/pages/users/components/RolesPermissionsTab.tsx
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
import React from 'react'
|
||||
import { RolePermissionItem } from '../../../types'
|
||||
|
||||
const ROLE_MATRICES: RolePermissionItem[] = [
|
||||
{
|
||||
role: 'admin',
|
||||
title: 'Quản trị viên',
|
||||
description:
|
||||
'Toàn quyền quản trị hệ thống, thành viên, cấu hình dự án và xuất bộ dữ liệu.',
|
||||
permissions: [
|
||||
'Tạo, chỉnh sửa và xóa dự án',
|
||||
'Mời, đổi vai trò và tạm khóa thành viên',
|
||||
'Phê duyệt cuối cùng và xuất dữ liệu (YOLO, COCO, Pascal VOC)',
|
||||
'Cấu hình bộ nhãn và quy chuẩn chất lượng',
|
||||
],
|
||||
},
|
||||
{
|
||||
role: 'manager',
|
||||
title: 'Quản lý',
|
||||
description:
|
||||
'Quản lý tiến độ dự án, phân công nhiệm vụ gán nhãn và theo dõi hiệu suất.',
|
||||
permissions: [
|
||||
'Tải ảnh lên và chia lô dữ liệu',
|
||||
'Phân công ảnh cho Người gán nhãn và Người duyệt',
|
||||
'Xem thống kê tiến độ và báo cáo chất lượng',
|
||||
'Xuất bộ dữ liệu đã được duyệt',
|
||||
],
|
||||
},
|
||||
{
|
||||
role: 'reviewer',
|
||||
title: 'Người duyệt',
|
||||
description:
|
||||
'Kiểm tra chất lượng nhãn, chấp thuận hoặc trả lại ảnh kèm nhận xét chỉnh sửa.',
|
||||
permissions: [
|
||||
'Xem và kiểm tra toàn bộ ảnh chờ duyệt',
|
||||
'Duyệt nhãn đạt chuẩn (Chấp thuận)',
|
||||
'Trả lại ảnh kèm ghi chú lỗi để sửa lại',
|
||||
'Tinh chỉnh trực tiếp bounding box / polygon khi cần',
|
||||
],
|
||||
},
|
||||
{
|
||||
role: 'annotator',
|
||||
title: 'Người gán nhãn',
|
||||
description:
|
||||
'Thực hiện vẽ nhãn trên các ảnh được phân công và gửi duyệt.',
|
||||
permissions: [
|
||||
'Truy cập không gian gán nhãn (Canvas)',
|
||||
'Tạo, chỉnh sửa và xóa nhãn trên ảnh được giao',
|
||||
'Gửi ảnh đã gán nhãn sang trạng thái Chờ duyệt',
|
||||
'Xem phản hồi từ Người duyệt và sửa lại nhãn',
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export const RolesPermissionsTab: React.FC = () => {
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{ROLE_MATRICES.map((item) => (
|
||||
<div
|
||||
key={item.role}
|
||||
className="rounded-2xl border border-slate-200 bg-white p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)]"
|
||||
>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<h3 className="text-base font-bold text-slate-900">{item.title}</h3>
|
||||
<span className="px-2.5 py-0.5 rounded-full bg-slate-100 text-slate-600 text-[11px] font-semibold uppercase">
|
||||
{item.role}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-xs text-slate-500 leading-relaxed mb-4">
|
||||
{item.description}
|
||||
</p>
|
||||
<ul className="space-y-2">
|
||||
{item.permissions.map((perm) => (
|
||||
<li
|
||||
key={perm}
|
||||
className="flex items-start gap-2 text-xs text-slate-700"
|
||||
>
|
||||
<span className="text-emerald-600 font-bold mt-0.5">✓</span>
|
||||
<span>{perm}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default RolesPermissionsTab
|
||||
116
src/pages/users/components/UserRoleBadge.tsx
Normal file
116
src/pages/users/components/UserRoleBadge.tsx
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
import React, { useState, useRef, useEffect } from 'react'
|
||||
import { UserRole } from '../../../types'
|
||||
|
||||
export interface UserRoleBadgeProps {
|
||||
role: UserRole
|
||||
disabled?: boolean
|
||||
onChange?: (newRole: UserRole) => void
|
||||
}
|
||||
|
||||
export const ROLE_LABELS: Record<UserRole, string> = {
|
||||
admin: 'Quản trị viên',
|
||||
manager: 'Quản lý',
|
||||
annotator: 'Người gán nhãn',
|
||||
reviewer: 'Người duyệt',
|
||||
}
|
||||
|
||||
export const ROLE_ACCESS_SUMMARIES: Record<UserRole, string> = {
|
||||
admin: 'Toàn quyền',
|
||||
manager: 'Quản lý & phân công',
|
||||
annotator: 'Tạo / sửa nhãn',
|
||||
reviewer: 'Duyệt / trả lại nhãn',
|
||||
}
|
||||
|
||||
export const UserRoleBadge: React.FC<UserRoleBadgeProps> = ({
|
||||
role,
|
||||
disabled = false,
|
||||
onChange,
|
||||
}) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (
|
||||
containerRef.current &&
|
||||
!containerRef.current.contains(event.target as Node)
|
||||
) {
|
||||
setOpen(false)
|
||||
}
|
||||
}
|
||||
if (open) {
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
}
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside)
|
||||
}
|
||||
}, [open])
|
||||
|
||||
if (disabled || !onChange) {
|
||||
return (
|
||||
<span className="text-[13px] font-semibold text-slate-900">
|
||||
{ROLE_LABELS[role]}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const selectableRoles: UserRole[] = [
|
||||
'admin',
|
||||
'manager',
|
||||
'annotator',
|
||||
'reviewer',
|
||||
]
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="relative inline-block">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
className="inline-flex items-center gap-1.5 text-[13px] font-semibold text-slate-900 hover:text-indigo-600 transition-colors py-1 rounded-lg"
|
||||
>
|
||||
<span>{ROLE_LABELS[role]}</span>
|
||||
<svg
|
||||
className="w-3.5 h-3.5 text-slate-500"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="m6 9 6 6 6-6" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute left-0 mt-1 w-44 rounded-xl border border-slate-200 bg-white py-1.5 shadow-lg z-30">
|
||||
{selectableRoles.map((r) => {
|
||||
const isSelected = r === role
|
||||
return (
|
||||
<button
|
||||
key={r}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onChange(r)
|
||||
setOpen(false)
|
||||
}}
|
||||
className={`w-full text-left px-3.5 py-2 text-xs flex items-center justify-between transition-colors ${
|
||||
isSelected
|
||||
? 'bg-indigo-50/80 text-indigo-700 font-semibold'
|
||||
: 'text-slate-700 hover:bg-slate-50 font-medium'
|
||||
}`}
|
||||
>
|
||||
<span>{ROLE_LABELS[r]}</span>
|
||||
{isSelected && (
|
||||
<span className="text-indigo-600 font-bold">✓</span>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default UserRoleBadge
|
||||
61
src/pages/users/components/UserStatsCards.tsx
Normal file
61
src/pages/users/components/UserStatsCards.tsx
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import React from 'react'
|
||||
|
||||
export interface UserStatsCardsProps {
|
||||
totalMembers: number
|
||||
activeMembers: number
|
||||
onlineCount: number
|
||||
pendingInvites: number
|
||||
suspendedMembers: number
|
||||
}
|
||||
|
||||
export const UserStatsCards: React.FC<UserStatsCardsProps> = ({
|
||||
totalMembers,
|
||||
activeMembers,
|
||||
onlineCount,
|
||||
pendingInvites,
|
||||
suspendedMembers,
|
||||
}) => {
|
||||
const cards = [
|
||||
{
|
||||
label: 'Tổng thành viên',
|
||||
value: totalMembers,
|
||||
subtitle: 'trong không gian nhóm',
|
||||
},
|
||||
{
|
||||
label: 'Đang hoạt động',
|
||||
value: activeMembers,
|
||||
subtitle: `${onlineCount} thành viên trực tuyến`,
|
||||
},
|
||||
{
|
||||
label: 'Lời mời đang chờ',
|
||||
value: pendingInvites,
|
||||
subtitle: 'Hết hạn sau 7 ngày',
|
||||
},
|
||||
{
|
||||
label: 'Tạm khóa',
|
||||
value: suspendedMembers,
|
||||
subtitle: 'Không thể truy cập dữ liệu',
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
|
||||
{cards.map((card) => (
|
||||
<div
|
||||
key={card.label}
|
||||
className="rounded-2xl border border-slate-200 bg-white px-5 py-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]"
|
||||
>
|
||||
<p className="text-xs font-medium text-slate-600 mb-2">
|
||||
{card.label}
|
||||
</p>
|
||||
<div className="text-3xl font-bold text-slate-900 tracking-tight mb-2">
|
||||
{card.value}
|
||||
</div>
|
||||
<p className="text-xs text-slate-500">{card.subtitle}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default UserStatsCards
|
||||
213
src/pages/users/components/UserTable.tsx
Normal file
213
src/pages/users/components/UserTable.tsx
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
import React, { useState } from 'react'
|
||||
import { WorkspaceMember, UserRole, UserStatus } from '../../../types'
|
||||
import { UserRoleBadge } from './UserRoleBadge'
|
||||
|
||||
export interface UserTableProps {
|
||||
members: WorkspaceMember[]
|
||||
onChangeRole: (memberId: string, newRole: UserRole) => void
|
||||
onToggleStatus: (memberId: string) => void
|
||||
onRemoveMember?: (memberId: string) => void
|
||||
}
|
||||
|
||||
export const UserTable: React.FC<UserTableProps> = ({
|
||||
members,
|
||||
onChangeRole,
|
||||
onToggleStatus,
|
||||
onRemoveMember,
|
||||
}) => {
|
||||
const [openMenuId, setOpenMenuId] = useState<string | null>(null)
|
||||
|
||||
const renderStatusBadge = (status: UserStatus) => {
|
||||
if (status === 'active') {
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-emerald-50 text-emerald-700 text-xs font-medium">
|
||||
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500" />
|
||||
Hoạt động
|
||||
</span>
|
||||
)
|
||||
}
|
||||
if (status === 'invited') {
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-amber-50 text-amber-700 text-xs font-medium">
|
||||
<span className="w-1.5 h-1.5 rounded-full bg-amber-500" />
|
||||
Chờ xác nhận
|
||||
</span>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-rose-50 text-rose-700 text-xs font-medium">
|
||||
<span className="w-1.5 h-1.5 rounded-full bg-rose-500" />
|
||||
Tạm khóa
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left border-collapse">
|
||||
<thead>
|
||||
<tr className="border-t border-b border-slate-200/80 text-[11px] font-semibold uppercase tracking-wider text-slate-500 bg-slate-50/40">
|
||||
<th className="py-3 pl-5 pr-4">THÀNH VIÊN</th>
|
||||
<th className="py-3 px-4">VAI TRÒ</th>
|
||||
<th className="py-3 px-4">TRẠNG THÁI</th>
|
||||
<th className="py-3 px-4">DỰ ÁN ĐƯỢC PHÂN CÔNG</th>
|
||||
<th className="py-3 px-4">QUYỀN TRUY CẬP</th>
|
||||
<th className="py-3 pl-4 pr-5 text-right sm:text-left">TÙY CHỌN</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-200/75 text-sm">
|
||||
{members.length === 0 ? (
|
||||
<tr>
|
||||
<td
|
||||
colSpan={6}
|
||||
className="py-12 text-center text-sm text-slate-500"
|
||||
>
|
||||
Không tìm thấy thành viên nào phù hợp với bộ lọc hiện tại.
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
members.map((member) => {
|
||||
const isMenuOpen = openMenuId === member.id
|
||||
return (
|
||||
<tr
|
||||
key={member.id}
|
||||
className="hover:bg-slate-50/60 transition-colors"
|
||||
>
|
||||
{/* THÀNH VIÊN */}
|
||||
<td className="py-3.5 pl-5 pr-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div
|
||||
style={{ backgroundColor: member.avatarColor }}
|
||||
className="w-9 h-9 rounded-full flex items-center justify-center text-xs font-bold text-indigo-700 shrink-0"
|
||||
>
|
||||
{member.initials}
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<div className="text-[13px] font-semibold text-slate-900 truncate">
|
||||
{member.name}
|
||||
{member.isCurrentUser ? ' (bạn)' : ''}
|
||||
</div>
|
||||
<div className="text-xs text-slate-500 truncate">
|
||||
{member.email}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* VAI TRÒ */}
|
||||
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||
<UserRoleBadge
|
||||
role={member.role}
|
||||
disabled={Boolean(member.isCurrentUser)}
|
||||
onChange={(newRole) => onChangeRole(member.id, newRole)}
|
||||
/>
|
||||
</td>
|
||||
|
||||
{/* TRẠNG THÁI */}
|
||||
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||
{renderStatusBadge(member.status)}
|
||||
</td>
|
||||
|
||||
{/* DỰ ÁN ĐƯỢC PHÂN CÔNG */}
|
||||
<td className="py-3.5 px-4 whitespace-nowrap text-[13px] text-slate-800">
|
||||
{member.assignedProjectsText}
|
||||
</td>
|
||||
|
||||
{/* QUYỀN TRUY CẬP */}
|
||||
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||
<div className="text-xs font-medium text-slate-700">
|
||||
{member.accessSummary}
|
||||
</div>
|
||||
<div className="text-[11px] text-slate-400 mt-0.5">
|
||||
{member.activityStatusText}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* TÙY CHỌN */}
|
||||
<td className="py-3.5 pl-4 pr-5 whitespace-nowrap relative">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
setOpenMenuId(isMenuOpen ? null : member.id)
|
||||
}
|
||||
aria-label={`Tùy chọn cho ${member.name}`}
|
||||
className="p-1.5 rounded-lg text-slate-500 hover:text-slate-900 hover:bg-slate-100 transition-colors"
|
||||
>
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="currentColor"
|
||||
>
|
||||
<circle cx="5" cy="12" r="1.75" />
|
||||
<circle cx="12" cy="12" r="1.75" />
|
||||
<circle cx="19" cy="12" r="1.75" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{isMenuOpen && (
|
||||
<div
|
||||
onMouseLeave={() => setOpenMenuId(null)}
|
||||
className="absolute right-6 top-11 w-48 rounded-xl border border-slate-200 bg-white py-1.5 shadow-lg z-30"
|
||||
>
|
||||
{!member.isCurrentUser ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
const nextRole: UserRole =
|
||||
member.role === 'annotator'
|
||||
? 'reviewer'
|
||||
: member.role === 'reviewer'
|
||||
? 'manager'
|
||||
: 'annotator'
|
||||
onChangeRole(member.id, nextRole)
|
||||
setOpenMenuId(null)
|
||||
}}
|
||||
className="w-full text-left px-3.5 py-2 text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
Đổi vai trò nhanh
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onToggleStatus(member.id)
|
||||
setOpenMenuId(null)
|
||||
}}
|
||||
className="w-full text-left px-3.5 py-2 text-xs font-medium text-amber-700 hover:bg-amber-50/60"
|
||||
>
|
||||
{member.status === 'suspended'
|
||||
? 'Kích hoạt lại tài khoản'
|
||||
: 'Tạm khóa tài khoản'}
|
||||
</button>
|
||||
{onRemoveMember && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onRemoveMember(member.id)
|
||||
setOpenMenuId(null)
|
||||
}}
|
||||
className="w-full text-left px-3.5 py-2 text-xs font-medium text-rose-600 hover:bg-rose-50/60"
|
||||
>
|
||||
Xóa khỏi không gian nhóm
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="px-3.5 py-2 text-xs text-slate-400">
|
||||
Tài khoản quản trị của bạn
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default UserTable
|
||||
135
src/pages/users/components/UserTableFilters.tsx
Normal file
135
src/pages/users/components/UserTableFilters.tsx
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
import React from 'react'
|
||||
import { UserRole, UserStatus } from '../../../types'
|
||||
|
||||
export interface UserTableFiltersProps {
|
||||
searchQuery: string
|
||||
onSearchChange: (value: string) => void
|
||||
roleFilter: UserRole | 'all'
|
||||
onRoleFilterChange: (value: UserRole | 'all') => void
|
||||
statusFilter: UserStatus | 'all'
|
||||
onStatusFilterChange: (value: UserStatus | 'all') => void
|
||||
projectFilter: string
|
||||
onProjectFilterChange: (value: string) => void
|
||||
}
|
||||
|
||||
export const UserTableFilters: React.FC<UserTableFiltersProps> = ({
|
||||
searchQuery,
|
||||
onSearchChange,
|
||||
roleFilter,
|
||||
onRoleFilterChange,
|
||||
statusFilter,
|
||||
onStatusFilterChange,
|
||||
projectFilter,
|
||||
onProjectFilterChange,
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-2.5">
|
||||
{/* Search input */}
|
||||
<div className="relative w-full sm:w-[270px]">
|
||||
<span className="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<path d="m21 21-4.3-4.3" />
|
||||
</svg>
|
||||
</span>
|
||||
<input
|
||||
type="text"
|
||||
value={searchQuery}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
placeholder="Tìm tên hoặc email..."
|
||||
className="w-full pl-9 pr-3.5 py-2 rounded-xl border border-slate-200 bg-white text-xs sm:text-[13px] text-slate-800 placeholder:text-slate-400 focus:outline-none focus:border-indigo-500 transition-colors"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Role Filter Dropdown */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={roleFilter}
|
||||
onChange={(e) =>
|
||||
onRoleFilterChange(e.target.value as UserRole | 'all')
|
||||
}
|
||||
className="appearance-none pl-3.5 pr-8 py-2 rounded-xl border border-slate-200 bg-white text-xs sm:text-[13px] font-medium text-slate-700 hover:border-slate-300 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
>
|
||||
<option value="all">Tất cả vai trò</option>
|
||||
<option value="admin">Quản trị viên</option>
|
||||
<option value="manager">Quản lý</option>
|
||||
<option value="annotator">Người gán nhãn</option>
|
||||
<option value="reviewer">Người duyệt</option>
|
||||
</select>
|
||||
<span className="pointer-events-none absolute inset-y-0 right-0 pr-2.5 flex items-center text-slate-500">
|
||||
<svg
|
||||
className="w-3.5 h-3.5"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="m6 9 6 6 6-6" />
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Status Filter Dropdown */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={statusFilter}
|
||||
onChange={(e) =>
|
||||
onStatusFilterChange(e.target.value as UserStatus | 'all')
|
||||
}
|
||||
className="appearance-none pl-3.5 pr-8 py-2 rounded-xl border border-slate-200 bg-white text-xs sm:text-[13px] font-medium text-slate-700 hover:border-slate-300 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
>
|
||||
<option value="all">Tất cả trạng thái</option>
|
||||
<option value="active">Hoạt động</option>
|
||||
<option value="invited">Đang chờ lời mời</option>
|
||||
<option value="suspended">Tạm khóa</option>
|
||||
</select>
|
||||
<span className="pointer-events-none absolute inset-y-0 right-0 pr-2.5 flex items-center text-slate-500">
|
||||
<svg
|
||||
className="w-3.5 h-3.5"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="m6 9 6 6 6-6" />
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Project Filter Dropdown */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={projectFilter}
|
||||
onChange={(e) => onProjectFilterChange(e.target.value)}
|
||||
className="appearance-none pl-3.5 pr-8 py-2 rounded-xl border border-slate-200 bg-white text-xs sm:text-[13px] font-medium text-slate-700 hover:border-slate-300 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
>
|
||||
<option value="all">Tất cả dự án</option>
|
||||
<option value="proj-1">Phương tiện đô thị</option>
|
||||
<option value="proj-2">Giao thông đô thị</option>
|
||||
<option value="proj-3">Phân vùng đường phố</option>
|
||||
</select>
|
||||
<span className="pointer-events-none absolute inset-y-0 right-0 pr-2.5 flex items-center text-slate-500">
|
||||
<svg
|
||||
className="w-3.5 h-3.5"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="m6 9 6 6 6-6" />
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default UserTableFilters
|
||||
Loading…
Add table
Add a link
Reference in a new issue