Skip to content

Commit cb464bc

Browse files
committed
Handle empty snapshots
1 parent 5677947 commit cb464bc

2 files changed

Lines changed: 54 additions & 33 deletions

File tree

‎site/src/pages/TaskPage/TaskPage.stories.tsx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,23 @@ export const TaskPausedNoSnapshot: Story = {
310310
},
311311
};
312312

313+
export const TaskPausedEmptySnapshot: Story = {
314+
beforeEach: () => {
315+
spyOn(API, "getTask").mockResolvedValue({
316+
...MockTask,
317+
status: "paused",
318+
});
319+
spyOn(API, "getWorkspaceByOwnerAndName").mockResolvedValue(
320+
MockStoppedWorkspace,
321+
);
322+
spyOn(API, "getTaskLogs").mockResolvedValue({
323+
snapshot: true,
324+
snapshot_at: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString(),
325+
logs: [],
326+
});
327+
},
328+
};
329+
313330
export const TaskPausedSingleMessage: Story = {
314331
beforeEach: () => {
315332
spyOn(API, "getTask").mockResolvedValue({

‎site/src/pages/TaskPage/TaskPage.tsx‎

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ const TaskLogPreview: FC<TaskLogPreviewProps> = ({
324324
headerAction,
325325
snapshotAt,
326326
}) => {
327-
const hasLogs = logs.length > 0;
328-
329327
// Scroll to the bottom on mount since snapshot logs are static.
330328
const scrollToBottom = useCallback((el: HTMLDivElement | null) => {
331329
if (!isChromatic() && el) {
@@ -348,37 +346,43 @@ const TaskLogPreview: FC<TaskLogPreviewProps> = ({
348346
</span>
349347
{headerAction}
350348
</div>
351-
{hasLogs ? (
352-
<ScrollArea className="h-96">
353-
<div
354-
ref={scrollToBottom}
355-
className="p-4 font-mono text-xs text-content-secondary leading-relaxed whitespace-pre-wrap break-words"
356-
>
357-
{logs.map((entry, index) => {
358-
const prev = index === 0 ? undefined : logs[index - 1];
359-
const isNewGroup = !prev || prev.type !== entry.type;
360-
return (
361-
<div
362-
key={entry.id}
363-
className={cn(
364-
"pl-3 border-0 border-l-2 border-solid",
365-
entry.type === "input"
366-
? "border-l-border-pending"
367-
: "border-l-border-purple",
368-
isNewGroup && index > 0 && "mt-4",
369-
)}
370-
>
371-
{isNewGroup && (
372-
<div className="text-content-primary font-semibold mb-1">
373-
{entry.type === "input" ? "[user]" : "[agent]"}
374-
</div>
375-
)}
376-
{entry.content || "\u00A0"}
377-
</div>
378-
);
379-
})}
380-
</div>
381-
</ScrollArea>
349+
{snapshotAt ? (
350+
logs.length > 0 ? (
351+
<ScrollArea className="h-96">
352+
<div
353+
ref={scrollToBottom}
354+
className="p-4 font-mono text-xs text-content-secondary leading-relaxed whitespace-pre-wrap break-words"
355+
>
356+
{logs.map((entry, index) => {
357+
const prev = index === 0 ? undefined : logs[index - 1];
358+
const isNewGroup = !prev || prev.type !== entry.type;
359+
return (
360+
<div
361+
key={entry.id}
362+
className={cn(
363+
"pl-3 border-0 border-l-2 border-solid",
364+
entry.type === "input"
365+
? "border-l-border-pending"
366+
: "border-l-border-purple",
367+
isNewGroup && index > 0 && "mt-4",
368+
)}
369+
>
370+
{isNewGroup && (
371+
<div className="text-content-primary font-semibold mb-1">
372+
{entry.type === "input" ? "[user]" : "[agent]"}
373+
</div>
374+
)}
375+
{entry.content || "\u00A0"}
376+
</div>
377+
);
378+
})}
379+
</div>
380+
</ScrollArea>
381+
) : (
382+
<p className="px-4 py-3 text-sm text-content-secondary m-0">
383+
No log messages in this snapshot.
384+
</p>
385+
)
382386
) : (
383387
<p className="px-4 py-3 text-sm text-content-secondary m-0">
384388
No log snapshot available. Resume your task to view logs.

0 commit comments

Comments
 (0)