Skip to content

Commit bc3e395

Browse files
author
Dylan Huang
committed
Implement row expansion management in GlobalState and Dashboard
- Added functionality to manage expanded rows in GlobalState, including methods to toggle individual row expansion and set all rows expanded or collapsed. - Updated Dashboard component to include buttons for expanding and collapsing all rows, and display the count of currently expanded rows. - Refactored Row component to utilize GlobalState for determining and toggling row expansion state.
1 parent 18306f7 commit bc3e395

3 files changed

Lines changed: 73 additions & 10 deletions

File tree

vite-app/src/GlobalState.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,44 @@ import type { EvaluationRow } from "./types/eval-protocol";
44
export class GlobalState {
55
isConnected: boolean = false;
66
dataset: EvaluationRow[] = [];
7+
expandedRows: Set<string> = new Set();
8+
79
constructor() {
810
makeAutoObservable(this);
911
}
1012

1113
setDataset(dataset: EvaluationRow[]) {
14+
// Preserve expansion state for existing rows
15+
const newExpandedRows = new Set<string>();
16+
dataset.forEach((row) => {
17+
if (this.expandedRows.has(row.input_metadata.row_id)) {
18+
newExpandedRows.add(row.input_metadata.row_id);
19+
}
20+
});
21+
this.expandedRows = newExpandedRows;
1222
this.dataset = dataset;
1323
}
24+
25+
toggleRowExpansion(rowId: string) {
26+
if (this.expandedRows.has(rowId)) {
27+
this.expandedRows.delete(rowId);
28+
} else {
29+
this.expandedRows.add(rowId);
30+
}
31+
}
32+
33+
isRowExpanded(rowId: string): boolean {
34+
return this.expandedRows.has(rowId);
35+
}
36+
37+
// Method to expand/collapse all rows
38+
setAllRowsExpanded(expanded: boolean) {
39+
if (expanded) {
40+
this.dataset.forEach((row) => {
41+
this.expandedRows.add(row.input_metadata.row_id);
42+
});
43+
} else {
44+
this.expandedRows.clear();
45+
}
46+
}
1447
}

vite-app/src/components/Dashboard.tsx

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,41 @@ const EmptyState = ({ onRefresh }: { onRefresh: () => void }) => {
4646
};
4747

4848
const Dashboard = observer(({ onRefresh }: DashboardProps) => {
49+
const expandAll = () => state.setAllRowsExpanded(true);
50+
const collapseAll = () => state.setAllRowsExpanded(false);
51+
52+
const expandedCount = state.expandedRows.size;
53+
4954
return (
5055
<div className="text-sm">
5156
{/* Summary Stats */}
5257
<div className="mb-4 bg-white border border-gray-200 p-3">
53-
<h2 className="text-sm font-semibold text-gray-900 mb-2">
54-
Dataset Summary
55-
</h2>
56-
<div className="text-xs">
57-
<span className="font-semibold text-gray-700">Total Rows:</span>{" "}
58-
{state.dataset.length}
58+
<div className="flex justify-between items-center mb-2">
59+
<h2 className="text-sm font-semibold text-gray-900">
60+
Dataset Summary
61+
</h2>
62+
{state.dataset.length > 0 && (
63+
<div className="flex gap-2">
64+
<Button onClick={expandAll} size="sm" variant="secondary">
65+
Expand All
66+
</Button>
67+
<Button onClick={collapseAll} size="sm" variant="secondary">
68+
Collapse All
69+
</Button>
70+
</div>
71+
)}
72+
</div>
73+
<div className="text-xs space-y-1">
74+
<div>
75+
<span className="font-semibold text-gray-700">Total Rows:</span>{" "}
76+
{state.dataset.length}
77+
</div>
78+
{state.dataset.length > 0 && (
79+
<div>
80+
<span className="font-semibold text-gray-700">Expanded:</span>{" "}
81+
{expandedCount} of {state.dataset.length}
82+
</div>
83+
)}
5984
</div>
6085
</div>
6186

@@ -102,7 +127,11 @@ const Dashboard = observer(({ onRefresh }: DashboardProps) => {
102127
new Date(a.created_at).getTime()
103128
)
104129
.map((row, index) => (
105-
<Row key={index} row={row} index={index} />
130+
<Row
131+
key={row.input_metadata.row_id}
132+
row={row}
133+
index={index}
134+
/>
106135
))}
107136
</tbody>
108137
</table>

vite-app/src/components/Row.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { observer } from "mobx-react";
2-
import { useState } from "react";
32
import type { EvaluationRow } from "../types/eval-protocol";
43
import { ChatInterface } from "./ChatInterface";
54
import { MetadataSection } from "./MetadataSection";
65
import StatusIndicator from "./StatusIndicator";
6+
import { state } from "../App";
77

88
export const Row = observer(
99
({ row }: { row: EvaluationRow; index: number }) => {
10-
const [isExpanded, setIsExpanded] = useState(false);
10+
const rowId = row.input_metadata.row_id;
11+
const isExpanded = state.isRowExpanded(rowId);
1112

12-
const toggleExpanded = () => setIsExpanded(!isExpanded);
13+
const toggleExpanded = () => state.toggleRowExpansion(rowId);
1314

1415
return (
1516
<>

0 commit comments

Comments
 (0)