Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions components/Home/HomeRunRow.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import Link from "next/link";
import { cn } from "@/lib/utils";
import type { TaskRunItem } from "@/lib/tasks/getTaskRuns";
import { getTaskDisplayName } from "@/lib/tasks/getTaskDisplayName";
import { getRunDisplayName } from "@/lib/tasks/getRunDisplayName";
import { getStatusColor } from "@/lib/tasks/getStatusColor";
import { getStatusLabel } from "@/lib/tasks/getStatusLabel";
import { formatTimestamp } from "@/lib/tasks/formatTimestamp";

/**
* Compact task-run row for the homepage tasks module. Links to the
* existing run detail page. Per-run sent-email subjects are not exposed
* by `GET /api/tasks/runs` yet, so this shows what is available: run
* name, status, and finished-at (recoupable/chat#1850).
* existing run detail page. Renders the originating scheduled task's
* title when the api resolves one, falling back to the generic
* per-taskIdentifier label. Per-run sent-email subjects are not exposed
* by `GET /api/tasks/runs` yet (recoupable/chat#1850).
*/
const HomeRunRow = ({ run }: { run: TaskRunItem }) => (
<Link
Expand All @@ -19,7 +20,7 @@ const HomeRunRow = ({ run }: { run: TaskRunItem }) => (
>
<div className="min-w-0">
<p className="truncate text-sm font-medium text-foreground">
{getTaskDisplayName(run.taskIdentifier)}
{getRunDisplayName(run)}
</p>
<p className="text-xs text-muted-foreground">
{formatTimestamp(run.finishedAt ?? run.createdAt)}
Expand Down
40 changes: 40 additions & 0 deletions lib/tasks/__tests__/getRunDisplayName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, it, expect } from "vitest";
import { getRunDisplayName } from "../getRunDisplayName";

describe("getRunDisplayName", () => {
it("returns the run title when present", () => {
expect(
getRunDisplayName({
title: "Weekly valuation + streams report",
taskIdentifier: "customer-prompt-task",
}),
).toBe("Weekly valuation + streams report");
});

it("falls back to the task display name when title is null", () => {
expect(
getRunDisplayName({
title: null,
taskIdentifier: "customer-prompt-task",
}),
).toBe("Scheduled Task");
});

it("falls back to the task display name when title is absent (pre-title api)", () => {
expect(getRunDisplayName({ taskIdentifier: "customer-prompt-task" })).toBe(
"Scheduled Task",
);
});

it("falls back to the task display name when title is empty", () => {
expect(
getRunDisplayName({ title: "", taskIdentifier: "setup-sandbox" }),
).toBe("Setup Sandbox");
});

it("falls back to the raw identifier for unmapped tasks without a title", () => {
expect(
getRunDisplayName({ title: null, taskIdentifier: "unknown-task" }),
).toBe("unknown-task");
});
});
13 changes: 13 additions & 0 deletions lib/tasks/getRunDisplayName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { TaskRunItem } from "@/lib/tasks/getTaskRuns";
import { getTaskDisplayName } from "@/lib/tasks/getTaskDisplayName";

/**
* Display name for a task run row: the originating scheduled task's title
* when the api resolved one, otherwise the generic per-taskIdentifier label
* (today's behavior — also the fallback until the api ships titles).
*/
export function getRunDisplayName(
run: Pick<TaskRunItem, "title" | "taskIdentifier">,
): string {
return run.title || getTaskDisplayName(run.taskIdentifier);
}
2 changes: 2 additions & 0 deletions lib/tasks/getTaskRuns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface TaskRunItem {
error?: string;
metadata?: Record<string, unknown> | null;
taskIdentifier: string;
/** Originating scheduled task's title; null or absent when unresolvable. */
title?: string | null;
createdAt: string;
startedAt: string | null;
finishedAt: string | null;
Expand Down
Loading