Skip to content

Commit 841d071

Browse files
t3dotggclaude
andcommitted
fix(web): arrow through the images an agent viewed
The viewed-images row was not marked as a gallery, so each image opened alone and the preview had no previous or next. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 21a9aa1 commit 841d071

2 files changed

Lines changed: 46 additions & 6 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ import {
4444
deriveTimelineEntriesFromVisibleTurnItems,
4545
} from "../../session-logic";
4646
import type { Root } from "mdast";
47+
import { ViewedImagesTimelineRow } from "./TimelineWorkEntryRow";
4748
import { remarkThoughtPreview, THOUGHT_PREVIEW_MAX_LENGTH } from "./TimelineWorkEntryRow.logic";
49+
import { TimelineRowCtx } from "./timelineRowContext";
4850
import { parseMarkdownWithMath } from "@t3tools/shared/markdownMath";
4951
import { collectThreadFindRanges } from "./threadFindHighlights";
5052
import { toastManager } from "../ui/toast";
@@ -74,14 +76,14 @@ vi.mock(import("~/state/query"), async (original) => ({
7476
})) as never,
7577
}));
7678

77-
const audioAsset = vi.hoisted(() => ({ url: "" }));
79+
const stubbedAsset = vi.hoisted(() => ({ url: "" }));
7880
vi.mock(import("~/assets/assetUrls"), async (original) => {
7981
const actual = await original();
8082
return {
8183
...actual,
8284
useAssetUrlState: ((...args: Parameters<typeof actual.useAssetUrlState>) =>
83-
audioAsset.url
84-
? { _tag: "Success", url: audioAsset.url }
85+
stubbedAsset.url
86+
? { _tag: "Success", url: stubbedAsset.url }
8587
: actual.useAssetUrlState(...args)) as typeof actual.useAssetUrlState,
8688
};
8789
});
@@ -1457,9 +1459,9 @@ describe("MessagesTimeline attachments", () => {
14571459
);
14581460
const src =
14591461
"data:audio/wav;base64,UklGRiUAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQEAAACA";
1460-
audioAsset.url = src;
1462+
stubbedAsset.url = src;
14611463
onTestFinished(() => {
1462-
audioAsset.url = "";
1464+
stubbedAsset.url = "";
14631465
});
14641466
const props = baseProps();
14651467
await using screen = await renderTimeline(
@@ -1527,6 +1529,44 @@ describe("MessagesTimeline attachments", () => {
15271529
});
15281530
await vi.waitFor(() => expect(one!.isConnected).toBe(false));
15291531
});
1532+
1533+
it("opens a viewed image as a gallery of the images beside it", async () => {
1534+
stubbedAsset.url =
1535+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
1536+
onTestFinished(() => {
1537+
stubbedAsset.url = "";
1538+
});
1539+
const onImageExpand = vi.fn<ComponentProps<typeof MessagesTimeline>["onImageExpand"]>();
1540+
await using screen = await renderElement(
1541+
<TimelineRowCtx
1542+
value={
1543+
{
1544+
threadRef: { environmentId: ENVIRONMENT_ID, threadId: ThreadId.make("thread-1") },
1545+
workspaceRoot: "/repo",
1546+
onImageExpand,
1547+
} as never
1548+
}
1549+
>
1550+
<ViewedImagesTimelineRow
1551+
row={{
1552+
kind: "viewed-images",
1553+
id: "viewed",
1554+
createdAt: CREATED_AT,
1555+
paths: ["/repo/first.png", "/repo/second.png", "/repo/third.png"],
1556+
}}
1557+
/>
1558+
</TimelineRowCtx>,
1559+
);
1560+
await screen.getByRole("button", { name: "Preview second.png" }).click();
1561+
expect(onImageExpand).toHaveBeenCalledExactlyOnceWith(
1562+
expect.objectContaining({
1563+
index: 1,
1564+
images: ["first.png", "second.png", "third.png"].map((name) =>
1565+
expect.objectContaining({ name }),
1566+
),
1567+
}),
1568+
);
1569+
});
15301570
});
15311571

15321572
describe("MessagesTimeline thread find", () => {

‎apps/web/src/components/chat/TimelineWorkEntryRow.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export function ViewedImagesTimelineRow({
182182
const { threadRef, workspaceRoot, onImageExpand } = use(TimelineRowCtx);
183183
if (!threadRef) return null;
184184
return (
185-
<div className="flex flex-wrap items-start gap-2 px-0.5">
185+
<div className="flex flex-wrap items-start gap-2 px-0.5" data-image-gallery>
186186
{row.paths.map((path) => {
187187
const image = resolveViewedImageAsset(path, {
188188
threadId: threadRef.threadId,

0 commit comments

Comments
 (0)