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): file canvases to other spaces (#87312)

Peter Kirkhame6ec4b53de9d
diff --git a/products/desktop/packages/core/src/canvas/dashboardSchemas.ts b/products/desktop/packages/core/src/canvas/dashboardSchemas.ts
index 90b9df677d3d..14281ee27941 100644
--- a/products/desktop/packages/core/src/canvas/dashboardSchemas.ts
+++ b/products/desktop/packages/core/src/canvas/dashboardSchemas.ts
@@ -145,6 +145,11 @@ export const renameDashboardInput = z.object({
name: z.string().min(1),
});
+export const fileDashboardInput = z.object({
+ id: z.string().min(1),
+ channelId: z.string().min(1),
+});
+
// Set (or clear, when taskId is null) the canvas's generation-task association.
export const setGenerationTaskInput = z.object({
id: z.string().min(1),
diff --git a/products/desktop/packages/core/src/canvas/dashboardsService.test.ts b/products/desktop/packages/core/src/canvas/dashboardsService.test.ts
index fac1b52b0d56..75ffb40537f3 100644
--- a/products/desktop/packages/core/src/canvas/dashboardsService.test.ts
+++ b/products/desktop/packages/core/src/canvas/dashboardsService.test.ts
@@ -104,3 +104,20 @@ describe("DashboardsService.getBuilds", () => {
expect(lifecycle.builds[0].buildStatus).toBe("ready");
});
});
+
+describe("DashboardsService.file", () => {
+ it("patches the canvas channel", async () => {
+ const { api, calls } = fakeApi({
+ "canvases/c1/": apiCanvas({ channel: "chan-2" }),
+ });
+ const service = new DashboardsService(api);
+
+ const canvas = await service.file({ id: "c1", channelId: "chan-2" });
+
+ expect(canvas.channelId).toBe("chan-2");
+ expect(calls[0]).toMatchObject({ path: "canvases/c1/" });
+ expect(JSON.parse(calls[0].init?.body as string)).toEqual({
+ channel_id: "chan-2",
+ });
+ });
+});
diff --git a/products/desktop/packages/core/src/canvas/dashboardsService.ts b/products/desktop/packages/core/src/canvas/dashboardsService.ts
index 13708f327180..f642e03995e8 100644
--- a/products/desktop/packages/core/src/canvas/dashboardsService.ts
+++ b/products/desktop/packages/core/src/canvas/dashboardsService.ts
@@ -331,6 +331,14 @@ export class DashboardsService {
return this.patch(input.id, { pinned: input.pinned }, "set pin");
}
+ file(input: { id: string; channelId: string }): Promise<DashboardRecord> {
+ return this.patch(
+ input.id,
+ { channel_id: input.channelId },
+ "file canvas to space",
+ );
+ }
+
// File a rendering error in the canvas's authoring-task thread (the server
// dedupes per build and error type). Best-effort: a report must never affect
// the render, and backends without the endpoint just refuse it, so every
diff --git a/products/desktop/packages/core/src/canvas/services.ts b/products/desktop/packages/core/src/canvas/services.ts
index 939ed69fec22..fba96306f1ed 100644
--- a/products/desktop/packages/core/src/canvas/services.ts
+++ b/products/desktop/packages/core/src/canvas/services.ts
@@ -75,6 +75,7 @@ export interface IDashboardsService {
taskId: string | null;
}): Promise<DashboardRecord>;
setPinned(input: { id: string; pinned: boolean }): Promise<DashboardRecord>;
+ file(input: { id: string; channelId: string }): Promise<DashboardRecord>;
// File a rendering error against the build that threw it (best-effort).
reportError(input: {
id: string;
diff --git a/products/desktop/packages/host-router/src/routers/dashboards.router.ts b/products/desktop/packages/host-router/src/routers/dashboards.router.ts
index 6ed8175ad12e..93e973a130c3 100644
--- a/products/desktop/packages/host-router/src/routers/dashboards.router.ts
+++ b/products/desktop/packages/host-router/src/routers/dashboards.router.ts
@@ -18,6 +18,7 @@ import {
createDashboardInput,
dashboardIdInput,
dashboardRecordSchema,
+ fileDashboardInput,
listComponentsInput,
listDashboardsInput,
promoteCanvasInput,
@@ -180,6 +181,12 @@ export const dashboardsRouter = router({
.get<IDashboardsService>(DASHBOARDS_SERVICE)
.setPinned(input),
),
+ file: publicProcedure
+ .input(fileDashboardInput)
+ .output(dashboardRecordSchema)
+ .mutation(({ ctx, input }) =>
+ ctx.container.get<IDashboardsService>(DASHBOARDS_SERVICE).file(input),
+ ),
reportError: publicProcedure
.input(reportCanvasErrorInput)
.mutation(({ ctx, input }) =>
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx
index e2c3e00bd7ae..1c55cedca0c2 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx
@@ -68,6 +68,7 @@ const actions = {
setPinned: () => {},
archive: () => {},
remove: () => {},
+ fileCanvas: () => {},
};
function item(overrides: Partial<ChannelItemModel> = {}): ChannelItemModel {
@@ -507,12 +508,13 @@ describe("ChannelItemRow", () => {
expect(screen.queryByRole("img", { name: "All caught up" })).toBeNull();
});
- it("gives a canvas the actions it has: pin and delete, not archive or filing", async () => {
+ it("lets a canvas be filed to another space", async () => {
const canvas = item({
key: "canvas:c1",
kind: "canvas",
id: "c1",
title: "Web analytics overview",
+ authorUser: { id: 999, uuid: "u-1", email: "[email protected]" },
});
renderInList(
<ChannelItemRow
@@ -532,10 +534,28 @@ describe("ChannelItemRow", () => {
expect(
screen.getByRole("button", { name: "Add to Command Center…" }),
).not.toBeNull();
- // A canvas can't be archived or filed to another space.
- for (const absent of ["Archive", "File to…"]) {
- expect(screen.queryByRole("button", { name: absent })).toBeNull();
- }
+ expect(screen.getByRole("button", { name: "File to…" })).not.toBeNull();
+ expect(screen.queryByRole("button", { name: "Archive" })).toBeNull();
+ });
+
+ it("does not offer filing for another user's canvas", async () => {
+ const canvas = item({
+ key: "canvas:c1",
+ kind: "canvas",
+ id: "c1",
+ title: "Web analytics overview",
+ authorUser: { id: 7, uuid: "u-2", email: "[email protected]" },
+ });
+ renderInList(
+ <ChannelItemRow actions={actions} isActive={false} item={canvas} />,
+ );
+
+ await userEvent.hover(screen.getByText("Web analytics overview"));
+
+ expect(
+ await screen.findByRole("button", { name: "Pin" }, { timeout: 2000 }),
+ ).not.toBeNull();
+ expect(screen.queryByRole("button", { name: "File to…" })).toBeNull();
});
it("confirms before deleting a canvas — it goes for the whole space", async () => {
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx
index 8df9e7e82cc4..ee7651c39951 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx
@@ -64,6 +64,7 @@ export interface ChannelItemActions {
archive: (item: ChannelItemModel) => void;
/** Canvases only — a task is archived, not deleted. */
remove: (item: ChannelItemModel) => void;
+ fileCanvas: (item: ChannelItemModel, channelId: string) => void;
}
// The channel sidebar's own chrome. Deliberately not shared with the Code
@@ -301,6 +302,10 @@ export function ChannelItemRow({
item.task != null &&
item.authorUser?.id != null &&
currentUser.data?.id === item.authorUser.id;
+ const canFileCanvas =
+ item.kind === "canvas" &&
+ item.authorUser?.id != null &&
+ currentUser.data?.id === item.authorUser.id;
const handleDragStart = useCallback(
(event: DragEvent) => {
if (item.kind === "canvas") {
@@ -320,7 +325,7 @@ export function ChannelItemRow({
);
// A canvas gets the same menu with the items it actually has: command-centre
- // placement, pin, and delete instead of archive. Filing remains task-only.
+ // placement, pin, filing, and delete instead of archive.
//
// Memoized because it travels to the shared preview card as the trigger's
// payload, which is written to the card's store whenever its identity changes.
@@ -332,6 +337,13 @@ export function ChannelItemRow({
id: item.id,
title: item.title,
isPinned: item.pinned,
+ channelId,
+ ...(canFileCanvas
+ ? {
+ onFile: (targetChannelId: string) =>
+ actions.fileCanvas(item, targetChannelId),
+ }
+ : {}),
onTogglePin: () => actions.togglePin(item),
onAddToCommandCenter,
// Confirm first, like the canvas menus in the artifacts grid and
@@ -353,7 +365,15 @@ export function ChannelItemRow({
},
// canHandoff rides on the currentUser query, so it belongs in deps for a
// sign-in refresh to re-evaluate.
- [item, channelId, actions, onAddToCommandCenter, onRename, canHandoff],
+ [
+ item,
+ channelId,
+ actions,
+ onAddToCommandCenter,
+ onRename,
+ canHandoff,
+ canFileCanvas,
+ ],
);
if (isEditing) {
diff --git a/products/desktop/packages/ui/src/features/canvas/components/TaskFeedPane.tsx b/products/desktop/packages/ui/src/features/canvas/components/TaskFeedPane.tsx
index b5e6a59b37ee..33984cc8d4b5 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/TaskFeedPane.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/TaskFeedPane.tsx
@@ -104,6 +104,7 @@ export function TaskFeedPane({
void archiveTask({ taskId: item.id });
},
remove: () => undefined,
+ fileCanvas: () => undefined,
}),
[feedId, select, togglePin, setPinnedMany, archiveTask],
);
diff --git a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx
index 5940f5553a4c..c1252724707f 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx
@@ -54,8 +54,8 @@ import {
* which needs the channel list and a mutation — belongs to the menu.
*
* Canvases share this menu but not all of it: they can be added to the command
- * centre, pinned, and deleted, but they can't be filed to another space.
- * `kind` decides which remaining actions apply.
+ * centre, pinned, filed, and deleted. `kind` decides which remaining actions
+ * apply.
*/
export interface TaskRowMenuProps {
kind: "task" | "canvas";
@@ -63,7 +63,7 @@ export interface TaskRowMenuProps {
title: string;
isPinned: boolean;
task?: Task;
- /** The channel this task is already filed to, ticked in "File to…". */
+ /** The channel this item is already filed to, ticked in "File to…". */
channelId?: string;
/** Absent when the command centre is full, which disables the item. */
onAddToCommandCenter?: () => void;
@@ -71,6 +71,8 @@ export interface TaskRowMenuProps {
onRename?: () => void;
onStop?: () => void;
onTogglePin: () => void;
+ /** Canvases supply their own filing mutation; task filing is shared here. */
+ onFile?: (channelId: string) => void;
/** Tasks are archived; canvases are deleted (with an undo window). */
onArchive?: () => void;
onDelete?: () => void;
@@ -143,7 +145,7 @@ function TaskRowMenuItems({
);
const isTask = menu.kind === "task";
const analysisTask = isTask && menu.task?.latest_run ? menu.task : null;
- const { channels } = useChannels({ enabled: bluebirdEnabled && isTask });
+ const { channels } = useChannels({ enabled: bluebirdEnabled });
const fileToChannel = useFileTaskToChannel();
const channelItems: MenuFlyoutItem[] = channels.map((channel) => ({
@@ -183,7 +185,7 @@ function TaskRowMenuItems({
<SquaresFourIcon size={14} />
Add to Command Center…
</Item>
- {isTask && channelItems.length > 0 && (
+ {channelItems.length > 0 && (isTask || menu.onFile) && (
<Sub>
<SubTrigger>
<FolderSimpleIcon size={14} />
@@ -195,7 +197,9 @@ function TaskRowMenuItems({
placeholder="Search spaces…"
emptyLabel="No spaces"
onSelect={(channelId) =>
- fileToChannel(channelId, menu.id, menu.title)
+ menu.kind === "canvas"
+ ? menu.onFile?.(channelId)
+ : fileToChannel(channelId, menu.id, menu.title)
}
/>
</MenuSubFlyout>
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useChannelItems.tsx b/products/desktop/packages/ui/src/features/canvas/hooks/useChannelItems.tsx
index 93850ff45a96..5c01257968b9 100644
--- a/products/desktop/packages/ui/src/features/canvas/hooks/useChannelItems.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useChannelItems.tsx
@@ -94,9 +94,12 @@ export function useChannelItems(channelId: string): {
});
const archivedTaskIds = useArchivedTaskIds();
const { pinnedTaskIds, togglePin, setPinnedMany } = usePinnedTasks();
- const { archiveTask } = useArchiveTask();
- const { setPinned: setCanvasPinned, invalidateDashboards } =
- useDashboardMutations();
+ const { archiveTask } = useArchiveTask({ navigateUnscoped: true });
+ const {
+ setPinned: setCanvasPinned,
+ fileDashboard,
+ invalidateDashboards,
+ } = useDashboardMutations();
const client = useOptionalAuthenticatedClient();
const { data: currentUser, isLoading: viewerLoading } = useCurrentUser({
client,
@@ -214,6 +217,19 @@ export function useChannelItems(channelId: string): {
archive: (item) => {
void archiveTask({ taskId: item.id });
},
+ fileCanvas: async (item, targetChannelId) => {
+ try {
+ await fileDashboard(item.id, targetChannelId);
+ const targetName = channels.find(
+ (candidate) => candidate.id === targetChannelId,
+ )?.name;
+ toast.success(targetName ? `Filed to ${targetName}` : "Canvas filed");
+ } catch (error) {
+ toast.error("Couldn't file canvas", {
+ description: error instanceof Error ? error.message : String(error),
+ });
+ }
+ },
// Canvases only, and through the shared undo window: the row disappears at
// once and the host isn't told until the toast expires, so an accidental
// delete costs nothing.
@@ -235,6 +251,8 @@ export function useChannelItems(channelId: string): {
togglePin,
setPinnedMany,
archiveTask,
+ fileDashboard,
+ channels,
invalidateDashboards,
],
);
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useDashboards.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useDashboards.ts
index 620349c2aecb..a078769b220b 100644
--- a/products/desktop/packages/ui/src/features/canvas/hooks/useDashboards.ts
+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useDashboards.ts
@@ -196,6 +196,9 @@ export function useDashboardMutations() {
const setPinned = useMutation(
trpc.dashboards.setPinned.mutationOptions({ onSuccess: invalidate }),
);
+ const file = useMutation(
+ trpc.dashboards.file.mutationOptions({ onSuccess: invalidate }),
+ );
return {
// Refresh the canvas queries after a mutation that didn't go through this
@@ -232,6 +235,8 @@ export function useDashboardMutations() {
// shows in the channel's Pinned menu for every member.
setPinned: (id: string, pinned: boolean) =>
setPinned.mutateAsync({ id, pinned }),
+ fileDashboard: (id: string, channelId: string) =>
+ file.mutateAsync({ id, channelId }),
isCreating: create.isPending,
isDeleting: remove.isPending,
isSavingContext: saveContext.isPending,