Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): collapse the session "Files" artifact box (#78681)

Shy Alter205b95bfc8e1
diff --git a/products/desktop/packages/ui/src/features/sessions/components/CloudArtifactDownloads.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/CloudArtifactDownloads.test.tsx
index 156ee1854b7f..dbb8282e9ee3 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/CloudArtifactDownloads.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/CloudArtifactDownloads.test.tsx
@@ -118,4 +118,50 @@ describe("CloudArtifactDownloads", () => {
name: "report.pdf",
});
});
+
+ it("starts expanded and collapses when the header is clicked", () => {
+ render(
+ <Theme>
+ <CloudArtifactDownloads taskId="task-1" task={task} />
+ </Theme>,
+ );
+
+ const trigger = screen.getByRole("button", { name: "Files (1)" });
+ expect(trigger).toHaveAttribute("aria-expanded", "true");
+ expect(screen.getByText("report.pdf")).toBeVisible();
+
+ fireEvent.click(trigger);
+
+ expect(trigger).toHaveAttribute("aria-expanded", "false");
+ expect(screen.queryByText("report.pdf")).not.toBeInTheDocument();
+
+ fireEvent.click(trigger);
+
+ expect(trigger).toHaveAttribute("aria-expanded", "true");
+ expect(screen.getByText("report.pdf")).toBeVisible();
+ });
+
+ it("remembers collapse state per task", () => {
+ const { unmount } = render(
+ <Theme>
+ <CloudArtifactDownloads taskId="task-1" task={task} />
+ </Theme>,
+ );
+
+ fireEvent.click(screen.getByRole("button", { name: "Files (1)" }));
+ expect(screen.queryByText("report.pdf")).not.toBeInTheDocument();
+ unmount();
+
+ render(
+ <Theme>
+ <CloudArtifactDownloads taskId="task-1" task={task} />
+ </Theme>,
+ );
+
+ expect(screen.getByRole("button", { name: "Files (1)" })).toHaveAttribute(
+ "aria-expanded",
+ "false",
+ );
+ expect(screen.queryByText("report.pdf")).not.toBeInTheDocument();
+ });
});
diff --git a/products/desktop/packages/ui/src/features/sessions/components/CloudArtifactDownloads.tsx b/products/desktop/packages/ui/src/features/sessions/components/CloudArtifactDownloads.tsx
index 75f599c362e1..7c47ef4e3948 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/CloudArtifactDownloads.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/CloudArtifactDownloads.tsx
@@ -1,10 +1,11 @@
-import { DownloadSimple } from "@phosphor-icons/react";
+import { Collapsible } from "@base-ui/react/collapsible";
+import { CaretDown, CaretRight, DownloadSimple } from "@phosphor-icons/react";
import {
SESSION_SERVICE,
type SessionService,
} from "@posthog/core/sessions/sessionService";
import { useService } from "@posthog/di/react";
-import { Button } from "@posthog/quill";
+import { Button, Text } from "@posthog/quill";
import type { TaskRunArtifact } from "@posthog/shared";
import { isTerminalStatus, type Task } from "@posthog/shared/domain-types";
import {
@@ -13,10 +14,13 @@ import {
} from "@posthog/ui/features/auth/store";
import { usePanelLayoutStore } from "@posthog/ui/features/panels/panelLayoutStore";
import { useSessionSelector } from "@posthog/ui/features/sessions/sessionStore";
+import {
+ useArtifactFilesCollapsed,
+ useSessionViewActions,
+} from "@posthog/ui/features/sessions/sessionViewStore";
import { FileIcon } from "@posthog/ui/primitives/FileIcon";
import { toast } from "@posthog/ui/primitives/toast";
import { formatFileSize } from "@posthog/ui/utils/formatFileSize";
-import { Box, Flex, Text } from "@radix-ui/themes";
import { useQuery } from "@tanstack/react-query";
import { useCallback, useMemo, useState } from "react";
@@ -37,6 +41,8 @@ export function CloudArtifactDownloads({
taskId,
(session) => session?.cloudStatus,
);
+ const collapsed = useArtifactFilesCollapsed(taskId);
+ const { setArtifactFilesCollapsed } = useSessionViewActions();
const authIdentity = useAuthStateValue(getAuthIdentity);
const [downloadingId, setDownloadingId] = useState<string | null>(null);
const runId = task?.latest_run?.id;
@@ -97,54 +103,66 @@ export function CloudArtifactDownloads({
if (!runId || artifacts.length === 0) return null;
return (
- <Box className="mb-3 rounded-lg border border-gray-4 bg-gray-2 p-3">
- <Text className="mb-2 block font-medium text-[13px]">Files</Text>
- <Flex direction="column" gap="1">
- {artifacts.map((artifact) => {
- const size = formatFileSize(artifact.size);
- const canDownload = Boolean(artifact.id);
- return (
- <Flex
- key={artifact.id ?? artifact.storage_path ?? artifact.name}
- align="center"
- justify="between"
- gap="3"
- className="min-w-0 rounded-md bg-background px-2 py-1.5"
- >
- <button
- type="button"
- className="flex min-w-0 flex-1 cursor-pointer items-center gap-2 text-left"
- disabled={!canDownload}
- onClick={() => {
- if (!taskId || !artifact.id) return;
- openArtifactTab(taskId, {
- runId,
- artifactId: artifact.id,
- name: artifact.name,
- });
- }}
- >
- <FileIcon filename={artifact.name} size={16} />
- <Text className="truncate text-[13px]">{artifact.name}</Text>
- {size !== null && (
- <Text color="gray" className="shrink-0 text-[12px]">
- {size}
- </Text>
- )}
- </button>
- <Button
- size="sm"
- variant="outline"
- disabled={!canDownload || downloadingId === artifact.id}
- onClick={() => void downloadArtifact(artifact)}
+ // Base UI rather than quill's Collapsible: quill styles the root/trigger
+ // as a standalone disclosure row (hover/selected fills on the whole
+ // padded header), which reads as a misplaced selected block inside this
+ // already-bordered card — see ChannelsList for the same call.
+ <Collapsible.Root
+ open={!collapsed}
+ onOpenChange={(open) => {
+ if (taskId) setArtifactFilesCollapsed(taskId, !open);
+ }}
+ className="mb-3 rounded-lg border border-gray-4 bg-gray-2 p-3"
+ >
+ <Collapsible.Trigger className="flex w-full cursor-pointer items-center gap-1.5 text-left font-medium text-[13px]">
+ {collapsed ? <CaretRight size={12} /> : <CaretDown size={12} />}
+ Files ({artifacts.length})
+ </Collapsible.Trigger>
+ <Collapsible.Panel className="mt-2">
+ <div className="flex flex-col gap-1">
+ {artifacts.map((artifact) => {
+ const size = formatFileSize(artifact.size);
+ const canDownload = Boolean(artifact.id);
+ return (
+ <div
+ key={artifact.id ?? artifact.storage_path ?? artifact.name}
+ className="flex min-w-0 items-center justify-between gap-3 rounded-md bg-background px-2 py-1.5"
>
- <DownloadSimple size={14} />
- {downloadingId === artifact.id ? "Opening..." : "Download"}
- </Button>
- </Flex>
- );
- })}
- </Flex>
- </Box>
+ <button
+ type="button"
+ className="flex min-w-0 flex-1 cursor-pointer items-center gap-2 text-left"
+ disabled={!canDownload}
+ onClick={() => {
+ if (!taskId || !artifact.id) return;
+ openArtifactTab(taskId, {
+ runId,
+ artifactId: artifact.id,
+ name: artifact.name,
+ });
+ }}
+ >
+ <FileIcon filename={artifact.name} size={16} />
+ <Text className="truncate text-[13px]">{artifact.name}</Text>
+ {size !== null && (
+ <Text className="shrink-0 text-[12px] text-gray-10">
+ {size}
+ </Text>
+ )}
+ </button>
+ <Button
+ size="sm"
+ variant="outline"
+ disabled={!canDownload || downloadingId === artifact.id}
+ onClick={() => void downloadArtifact(artifact)}
+ >
+ <DownloadSimple size={14} />
+ {downloadingId === artifact.id ? "Opening..." : "Download"}
+ </Button>
+ </div>
+ );
+ })}
+ </div>
+ </Collapsible.Panel>
+ </Collapsible.Root>
);
}
diff --git a/products/desktop/packages/ui/src/features/sessions/sessionViewStore.ts b/products/desktop/packages/ui/src/features/sessions/sessionViewStore.ts
index ac876397455a..984f5aecb543 100644
--- a/products/desktop/packages/ui/src/features/sessions/sessionViewStore.ts
+++ b/products/desktop/packages/ui/src/features/sessions/sessionViewStore.ts
@@ -16,6 +16,12 @@ interface SessionViewState {
* resets to expanded on app restart.
*/
queueCollapsedByTaskId: Record<string, boolean>;
+ /**
+ * Ephemeral per-task collapse of the artifact "Files" box in the chat
+ * thread, keyed by taskId. `true` = collapsed; absent/`false` = expanded
+ * (the default — the box never collapses on its own). Not persisted.
+ */
+ artifactFilesCollapsedByTaskId: Record<string, boolean>;
}
interface SessionViewActions {
@@ -25,6 +31,7 @@ interface SessionViewActions {
setGroupOverride: (id: string, expanded: boolean) => void;
clearGroupOverrides: () => void;
setQueueCollapsed: (taskId: string, collapsed: boolean) => void;
+ setArtifactFilesCollapsed: (taskId: string, collapsed: boolean) => void;
}
type SessionViewStore = SessionViewState & { actions: SessionViewActions };
@@ -35,6 +42,7 @@ const useStore = create<SessionViewStore>((set) => ({
showSearch: false,
groupOverrides: {},
queueCollapsedByTaskId: {},
+ artifactFilesCollapsedByTaskId: {},
actions: {
setShowRawLogs: (show) => set({ showRawLogs: show }),
setSearchQuery: (query) => set({ searchQuery: query }),
@@ -60,6 +68,13 @@ const useStore = create<SessionViewStore>((set) => ({
[taskId]: collapsed,
},
})),
+ setArtifactFilesCollapsed: (taskId, collapsed) =>
+ set((state) => ({
+ artifactFilesCollapsedByTaskId: {
+ ...state.artifactFilesCollapsedByTaskId,
+ [taskId]: collapsed,
+ },
+ })),
},
}));
@@ -69,4 +84,10 @@ export const useShowSearch = () => useStore((s) => s.showSearch);
export const useGroupOverrides = () => useStore((s) => s.groupOverrides);
export const useQueueCollapsed = (taskId: string) =>
useStore((s) => s.queueCollapsedByTaskId[taskId] ?? false);
+export const useArtifactFilesCollapsed = (taskId: string | undefined) =>
+ useStore((s) =>
+ taskId === undefined
+ ? false
+ : (s.artifactFilesCollapsedByTaskId[taskId] ?? false),
+ );
export const useSessionViewActions = () => useStore((s) => s.actions);