2import { useSearchParams } from "react-router-dom";
4 flexRender,
5 getCoreRowModel,
6 useReactTable,
7 getSortedRowModel,
9import { BenchmarkResult } from "../../../types";
10import { columns } from "./columns";
11import { BenchmarkCharts } from "../charts/BenchmarkCharts";
12import { exportToCsv } from "../export/csvExport";
eacabc8test real dataJeremy Magland 13
15 results: BenchmarkResult[];
16}
eacabc8test real dataJeremy Magland 17
19 const [searchParams, setSearchParams] = useSearchParams();
20 const selectedDataset = searchParams.get("dataset") || "";
21 const availableDatasets = useMemo(() => {
22 return Array.from(new Set(results.map((result) => result.dataset))).sort();
23 }, [results]);
eacabc8test real dataJeremy Magland 24
25 // Memoize filtered data to prevent unnecessary recalculations
26 const filteredData = useMemo(() => {
28 return results.filter((row) => row.dataset === selectedDataset);
29 }, [results, selectedDataset]);
eacabc8test real dataJeremy Magland 30
31 const table = useReactTable({
32 data: filteredData || [],
33 columns,
34 getCoreRowModel: getCoreRowModel(),
35 getSortedRowModel: getSortedRowModel(),
36 });
38 // Prepare data for bar charts when a dataset is selected
39 const chartData = useMemo(() => {
40 if (!selectedDataset) return [];
42 .filter((row: BenchmarkResult) => row.dataset === selectedDataset)
43 .map((row: BenchmarkResult) => ({
45 compression_ratio: row.compression_ratio,
46 encode_speed: row.encode_mb_per_sec,
eacabc8test real dataJeremy Magland 50
51 return (
52 <div className="table-container">
54 style={{
55 marginBottom: "20px",
56 display: "flex",
57 alignItems: "center",
58 gap: "10px",
59 justifyContent: "space-between",
60 }}
61 >
62 <div style={{ display: "flex", alignItems: "center", gap: "10px" }}>
8a6e869delta encoding for other algsJeremy Magland 63 <label htmlFor="dataset-select">Dataset:</label>
65 id="dataset-select"
66 value={selectedDataset}
68 if (e.target.value) {
69 setSearchParams({ dataset: e.target.value });
70 } else {
71 setSearchParams({});
72 }
73 }}
76 borderRadius: "4px",
77 border: "1px solid #ccc",
78 minWidth: "200px",
79 backgroundColor: "#fff",
81 >
82 <option value="">All Datasets</option>
85 {dataset}
86 </option>
87 ))}
88 </select>
89 </div>
90 <button
91 onClick={() => exportToCsv(filteredData, selectedDataset)}
92 style={{
94 backgroundColor: "#4CAF50",
95 color: "white",
96 border: "none",
97 borderRadius: "4px",
98 cursor: "pointer",
99 display: "flex",
100 alignItems: "center",
101 gap: "8px",
103 >
105 width="16"
106 height="16"
107 viewBox="0 0 16 16"
108 fill="none"
109 xmlns="http://www.w3.org/2000/svg"
110 >
111 <path d="M8 12L3 7H6V1H10V7H13L8 12Z" fill="currentColor" />
112 <path d="M2 14V15H14V14H2Z" fill="currentColor" />
114 Download CSV
115 </button>
116 </div>
118 {selectedDataset && chartData.length > 0 && (
119 <BenchmarkCharts chartData={chartData} />
120 )}
122 <table>
123 <thead>
128 key={header.id}
129 onClick={header.column.getToggleSortingHandler()}
132 {flexRender(
133 header.column.columnDef.header,
136 {header.column.getIsSorted() && (
138 {header.column.getIsSorted() === "asc" ? "↑" : "↓"}
140 )}
141 </th>
142 ))}
143 </tr>
144 ))}
145 </thead>
146 <tbody>
151 {flexRender(cell.column.columnDef.cell, cell.getContext())}
152 </td>
153 ))}
154 </tr>
155 ))}
156 </tbody>
157 </table>
158 </div>
159 );
160}