Spaces:
Running
Running
File size: 8,392 Bytes
5301c48 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
'use client'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Label } from "@/components/ui/label"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Textarea } from "@/components/ui/textarea"
import { ArrowLeft, Save, Star, ChevronLeft, ChevronRight } from "lucide-react"
import { useState } from "react"
import type { ToEvaluateDatasetRecord, TemplateResult } from './TemplateManager'
interface TemplateEvaluateStepProps {
evaluatedData: ToEvaluateDatasetRecord[]
setEvaluatedData: (data: ToEvaluateDatasetRecord[]) => void
templateResult: TemplateResult | null
onSaveExport: () => void
onBackToResults: () => void
}
export default function TemplateEvaluateStep({
evaluatedData,
setEvaluatedData,
templateResult,
onSaveExport,
onBackToResults
}: TemplateEvaluateStepProps) {
const [currentPage, setCurrentPage] = useState(1)
const recordsPerPage = 10
const totalRecords = evaluatedData.length
const totalPages = Math.ceil(totalRecords / recordsPerPage)
const startIndex = (currentPage - 1) * recordsPerPage
const endIndex = startIndex + recordsPerPage
const currentRecords = evaluatedData.slice(startIndex, endIndex)
const goToPage = (page: number) => {
setCurrentPage(Math.max(1, Math.min(page, totalPages)))
}
const handleScoreChange = (recordId: string, score: number) => {
setEvaluatedData(
evaluatedData.map(record =>
record.id === recordId ? { ...record, score } : record
)
)
}
const handleCommentChange = (recordId: string, comments: string) => {
setEvaluatedData(
evaluatedData.map(record =>
record.id === recordId ? { ...record, comments } : record
)
)
}
const StarRating = ({ recordId, currentRating }: { recordId: string, currentRating: number }) => {
const [hoveredRating, setHoveredRating] = useState(0)
return (
<div className="flex items-center gap-1">
{[1, 2, 3, 4, 5].map((star) => (
<Star
key={star}
className={`h-4 w-4 cursor-pointer transition-colors ${
star <= (hoveredRating || currentRating)
? 'fill-yellow-400 text-yellow-400'
: 'text-gray-300 hover:text-yellow-400'
}`}
onClick={() => handleScoreChange(recordId, star)}
onMouseEnter={() => setHoveredRating(star)}
onMouseLeave={() => setHoveredRating(0)}
/>
))}
</div>
)
}
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h2 className="text-2xl font-bold">Evaluate Dataset</h2>
<p className="text-gray-600 mt-1">
Add quality scores and comments to each record
{totalRecords > recordsPerPage && (
<span> • Showing {startIndex + 1}-{Math.min(endIndex, totalRecords)} of {totalRecords} records</span>
)}
</p>
</div>
<Button
onClick={onSaveExport}
className="bg-pink-600 hover:bg-pink-700 text-white flex items-center gap-2"
>
<Save className="h-4 w-4" />
Save & Export
</Button>
</div>
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Star className="h-5 w-5" />
Quality Evaluation
</CardTitle>
<CardDescription>
Rate each record's quality from 1 (poor) to 5 (excellent) and add comments
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-6 max-h-96 overflow-y-auto">
{currentRecords.map((record, index) => (
<div key={record.id} className="border rounded-lg p-4 space-y-4">
<div className="flex items-start justify-between gap-4">
<div className="flex-1">
<h4 className="font-medium mb-2">Record {startIndex + index + 1}</h4>
<div className="text-sm text-gray-600 space-y-1">
{Object.entries(record).filter(([key]) =>
// {.slice(0, 3)}
key !== 'id' && key !== 'score' && key !== 'rating' && key !== 'comments'
).map(([key, value]) => (
<div key={key}>
<span className="font-medium capitalize">{key.replace(/_/g, ' ')}:</span>{' '}
<span className="break-words">
{typeof value === 'object' ? JSON.stringify(value, null, 2) : String(value)}
</span>
</div>
))}
</div>
</div>
</div>
{/* Scoring and Comments Section */}
<div className="border-t pt-4 space-y-3">
<div className="flex items-center gap-4">
<div className="flex items-center gap-2">
<Label className="text-sm font-medium">Rating:</Label>
<StarRating
recordId={record.id}
currentRating={record.score || record.rating || 0}
/>
</div>
<div className="flex items-center gap-2">
<Label className="text-sm font-medium">Score:</Label>
<Select
value={(record.score || record.rating)?.toString() || ''}
onValueChange={(value) => handleScoreChange(record.id, parseInt(value))}
>
<SelectTrigger className="w-20">
<SelectValue placeholder="Rate" />
</SelectTrigger>
<SelectContent>
<SelectItem value="1">1</SelectItem>
<SelectItem value="2">2</SelectItem>
<SelectItem value="3">3</SelectItem>
<SelectItem value="4">4</SelectItem>
<SelectItem value="5">5</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="space-y-2">
<Label className="text-sm font-medium">Comments:</Label>
<Textarea
placeholder="Add your evaluation comments here..."
value={record.comments || ''}
onChange={(e) => handleCommentChange(record.id, e.target.value)}
className="min-h-[80px] resize-none text-sm"
/>
</div>
</div>
</div>
))}
</div>
{totalPages > 1 && (
<div className="flex items-center justify-between mt-4 pt-4 border-t">
<p className="text-sm text-gray-500">
Page {currentPage} of {totalPages}
</p>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="sm"
onClick={() => goToPage(currentPage - 1)}
disabled={currentPage === 1}
>
<ChevronLeft className="h-4 w-4" />
Previous
</Button>
<Button
variant="outline"
size="sm"
onClick={() => goToPage(currentPage + 1)}
disabled={currentPage === totalPages}
>
Next
<ChevronRight className="h-4 w-4" />
</Button>
</div>
</div>
)}
</CardContent>
</Card>
<div className="flex justify-between">
<Button
variant="outline"
onClick={onBackToResults}
className="flex items-center gap-2"
>
<ArrowLeft className="h-4 w-4" />
Back to Results
</Button>
</div>
</div>
)
} |