()
| 20 | import type { BenchmarkRecord } from '../api/types'; |
| 21 | |
| 22 | export function Benchmarks() { |
| 23 | const [searchQuery, setSearchQuery] = useState(''); |
| 24 | |
| 25 | const { data, isLoading, error, refetch, isFetching } = useBenchmarks(); |
| 26 | const deleteBenchmark = useDeleteBenchmark(); |
| 27 | const runBenchmark = useRunBenchmark(); |
| 28 | |
| 29 | const benchmarks = data?.benchmarks || []; |
| 30 | |
| 31 | // Filter by search |
| 32 | const filteredBenchmarks = benchmarks.filter((benchmark) => { |
| 33 | if (searchQuery) { |
| 34 | const searchLower = searchQuery.toLowerCase(); |
| 35 | if ( |
| 36 | !benchmark.name.toLowerCase().includes(searchLower) && |
| 37 | !benchmark.id.toLowerCase().includes(searchLower) |
| 38 | ) { |
| 39 | return false; |
| 40 | } |
| 41 | } |
| 42 | return true; |
| 43 | }); |
| 44 | |
| 45 | const handleDelete = async (benchmark: BenchmarkRecord) => { |
| 46 | if (confirm(`确定要删除 Benchmark "${benchmark.name}" 吗?`)) { |
| 47 | try { |
| 48 | await deleteBenchmark.mutateAsync(benchmark.id); |
| 49 | } catch (e) { |
| 50 | console.error('Failed to delete benchmark:', e); |
| 51 | } |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | const handleRun = async (benchmark: BenchmarkRecord) => { |
| 56 | try { |
| 57 | await runBenchmark.mutateAsync({ id: benchmark.id }); |
| 58 | } catch (e) { |
| 59 | console.error('Failed to run benchmark:', e); |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | return ( |
| 64 | <div className="flex flex-col h-full"> |
| 65 | <Header |
| 66 | title="Benchmarks" |
| 67 | subtitle="基准测试管理" |
| 68 | isRefreshing={isFetching} |
| 69 | onRefresh={() => refetch()} |
| 70 | /> |
| 71 | |
| 72 | <div className="flex-1 overflow-auto"> |
| 73 | {/* Toolbar */} |
| 74 | <div className="flex items-center justify-between p-4 border-b border-[var(--color-border)]"> |
| 75 | <div className="flex items-center gap-4"> |
| 76 | {/* Search */} |
| 77 | <div className="relative"> |
| 78 | <Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--color-text-muted)]" /> |
| 79 | <input |
nothing calls this directly
no test coverage detected