Skip to content

Commit 1c72503

Browse files
committed
Show all runs, not just completed
1 parent 21e619c commit 1c72503

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

evals/apps/web/src/app/home.tsx

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import { useCallback, useMemo, useState } from "react"
3+
import { useCallback, useState, useRef } from "react"
44
import { useRouter } from "next/navigation"
55
import Link from "next/link"
66
import { Ellipsis, Rocket } from "lucide-react"
@@ -35,8 +35,7 @@ export function Home({ runs }: { runs: (Run & { taskMetrics: TaskMetrics | null
3535
const router = useRouter()
3636

3737
const [deleteRunId, setDeleteRunId] = useState<number>()
38-
39-
const visibleRuns = useMemo(() => runs.filter((run) => run.taskMetrics !== null), [runs])
38+
const continueRef = useRef<HTMLButtonElement>(null)
4039

4140
const onConfirmDelete = useCallback(async () => {
4241
if (!deleteRunId) {
@@ -67,33 +66,43 @@ export function Home({ runs }: { runs: (Run & { taskMetrics: TaskMetrics | null
6766
</TableRow>
6867
</TableHeader>
6968
<TableBody>
70-
{visibleRuns.length ? (
71-
visibleRuns.map(({ taskMetrics, ...run }) => (
69+
{runs.length ? (
70+
runs.map(({ taskMetrics, ...run }) => (
7271
<TableRow key={run.id}>
7372
<TableCell>{run.model}</TableCell>
7473
<TableCell>{run.passed}</TableCell>
7574
<TableCell>{run.failed}</TableCell>
76-
<TableCell>{((run.passed / (run.passed + run.failed)) * 100).toFixed(1)}%</TableCell>
7775
<TableCell>
78-
<div className="flex items-center justify-evenly">
79-
<div>{formatTokens(taskMetrics!.tokensIn)}</div>/
80-
<div>{formatTokens(taskMetrics!.tokensOut)}</div>
81-
</div>
76+
{run.passed + run.failed > 0 && (
77+
<span>{((run.passed / (run.passed + run.failed)) * 100).toFixed(1)}%</span>
78+
)}
79+
</TableCell>
80+
<TableCell>
81+
{taskMetrics && (
82+
<div className="flex items-center justify-evenly">
83+
<div>{formatTokens(taskMetrics.tokensIn)}</div>/
84+
<div>{formatTokens(taskMetrics.tokensOut)}</div>
85+
</div>
86+
)}
8287
</TableCell>
83-
<TableCell>{formatCurrency(taskMetrics!.cost)}</TableCell>
84-
<TableCell>{formatDuration(taskMetrics!.duration)}</TableCell>
88+
<TableCell>{taskMetrics && formatCurrency(taskMetrics.cost)}</TableCell>
89+
<TableCell>{taskMetrics && formatDuration(taskMetrics.duration)}</TableCell>
8590
<TableCell>
8691
<DropdownMenu>
8792
<Button variant="ghost" size="icon" asChild>
8893
<DropdownMenuTrigger>
8994
<Ellipsis />
9095
</DropdownMenuTrigger>
9196
</Button>
92-
<DropdownMenuContent>
97+
<DropdownMenuContent align="end">
9398
<DropdownMenuItem asChild>
9499
<Link href={`/runs/${run.id}`}>View Tasks</Link>
95100
</DropdownMenuItem>
96-
<DropdownMenuItem onClick={() => setDeleteRunId(run.id)}>
101+
<DropdownMenuItem
102+
onClick={() => {
103+
setDeleteRunId(run.id)
104+
setTimeout(() => continueRef.current?.focus(), 0)
105+
}}>
97106
Delete
98107
</DropdownMenuItem>
99108
</DropdownMenuContent>
@@ -128,7 +137,9 @@ export function Home({ runs }: { runs: (Run & { taskMetrics: TaskMetrics | null
128137
</AlertDialogHeader>
129138
<AlertDialogFooter>
130139
<AlertDialogCancel>Cancel</AlertDialogCancel>
131-
<AlertDialogAction onClick={onConfirmDelete}>Continue</AlertDialogAction>
140+
<AlertDialogAction ref={continueRef} onClick={onConfirmDelete}>
141+
Continue
142+
</AlertDialogAction>
132143
</AlertDialogFooter>
133144
</AlertDialogContent>
134145
</AlertDialog>

evals/packages/db/src/queries/runs.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { desc, eq, sql, sum } from "drizzle-orm"
1+
import { desc, eq, inArray, sql, sum } from "drizzle-orm"
22

33
import { RecordNotFoundError, RecordNotCreatedError } from "./errors.js"
44
import type { InsertRun, UpdateRun } from "../schema.js"
@@ -85,21 +85,6 @@ export const finishRun = async (runId: number) => {
8585
}
8686

8787
export const deleteRun = async (runId: number) => {
88-
const tasks = await db.query.tasks.findMany({
89-
where: eq(schema.tasks.runId, runId),
90-
columns: { id: true, taskMetricsId: true },
91-
})
92-
93-
const taskMetricsIds = tasks
94-
.map(({ taskMetricsId }) => taskMetricsId)
95-
.filter((id): id is number => id !== null && id !== undefined)
96-
97-
await db.delete(schema.tasks).where(eq(schema.tasks.runId, runId))
98-
99-
if (taskMetricsIds.length > 0) {
100-
await db.delete(schema.taskMetrics).where(sql`${schema.taskMetrics.id} in (${sql.join(taskMetricsIds)})`)
101-
}
102-
10388
const run = await db.query.runs.findFirst({
10489
where: eq(schema.runs.id, runId),
10590
columns: { taskMetricsId: true },
@@ -109,9 +94,19 @@ export const deleteRun = async (runId: number) => {
10994
throw new RecordNotFoundError()
11095
}
11196

97+
const tasks = await db.query.tasks.findMany({
98+
where: eq(schema.tasks.runId, runId),
99+
columns: { id: true, taskMetricsId: true },
100+
})
101+
102+
await db.delete(schema.tasks).where(eq(schema.tasks.runId, runId))
112103
await db.delete(schema.runs).where(eq(schema.runs.id, runId))
113104

114-
if (run.taskMetricsId) {
115-
await db.delete(schema.taskMetrics).where(eq(schema.taskMetrics.id, run.taskMetricsId))
116-
}
105+
const taskMetricsIds = tasks
106+
.map(({ taskMetricsId }) => taskMetricsId)
107+
.filter((id): id is number => id !== null && id !== undefined)
108+
109+
taskMetricsIds.push(run.taskMetricsId ?? -1)
110+
111+
await db.delete(schema.taskMetrics).where(inArray(schema.taskMetrics.id, taskMetricsIds))
117112
}

0 commit comments

Comments
 (0)