: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(command-center): embed canvases alongside tasks (#87033)
Peter Kirkhama2723fd859d0
diff --git a/products/desktop/packages/core/src/command-center/cells.test.ts b/products/desktop/packages/core/src/command-center/cells.test.tsindex 0b787cf81907..256160e9858d 100644--- a/products/desktop/packages/core/src/command-center/cells.test.ts+++ b/products/desktop/packages/core/src/command-center/cells.test.ts@@ -1,7 +1,11 @@import type { Task } from "@posthog/shared/domain-types";import { describe, expect, it } from "vitest";import { buildCommandCenterCells } from "./cells";-import { BRAINROT_CELL, makeTerminalCellValue } from "./grid";+import {+ BRAINROT_CELL,+ makeCanvasCellValue,+ makeTerminalCellValue,+} from "./grid";const EMPTY_INPUT = {taskById: new Map<string, Task>(),@@ -22,6 +26,18 @@ describe("buildCommandCenterCells", () => {status: "idle",},},+ {+ name: "canvas cell exposes its canvas id and no task",+ input: makeCanvasCellValue("canvas-1"),+ expected: {+ cellIndex: 0,+ canvasId: "canvas-1",+ isBrainrot: false,+ taskId: null,+ task: undefined,+ status: "idle",+ },+ },{name: "terminal cell exposes its terminal id and no task",input: makeTerminalCellValue("term-1"),@@ -37,7 +53,12 @@ describe("buildCommandCenterCells", () => {{name: "empty cell is a non-brainrot empty slot",input: null,- expected: { isBrainrot: false, taskId: null, terminalId: null },+ expected: {+ isBrainrot: false,+ taskId: null,+ canvasId: null,+ terminalId: null,+ },},{name: "unknown task id is a non-brainrot cell",diff --git a/products/desktop/packages/core/src/command-center/cells.ts b/products/desktop/packages/core/src/command-center/cells.tsindex d7457526bc7d..b160d663a9b5 100644--- a/products/desktop/packages/core/src/command-center/cells.ts+++ b/products/desktop/packages/core/src/command-center/cells.ts@@ -1,9 +1,11 @@import type { AgentSession, WorkspaceMode } from "@posthog/shared";import type { Task } from "@posthog/shared/domain-types";import {+ getCanvasCellId,getTerminalCellCwd,getTerminalCellId,isBrainrotCell,+ isCanvasCell,isTerminalCell,} from "./grid";import { type CellStatus, deriveStatus, getRepoName } from "./status";@@ -16,6 +18,8 @@ export interface CommandCenterCellData {status: CellStatus;repoName: string | null;workspaceMode: WorkspaceMode | null;+ // Canvas: an embedded PostHog canvas rather than a task.+ canvasId: string | null;// Brainrot: a looping video slot rather than a task.isBrainrot: boolean;// Standalone terminal slot, independent of any agent run.@@ -36,6 +40,7 @@ const EMPTY_CELL_DATA = {status: "idle" as const,repoName: null,workspaceMode: null,+ canvasId: null,isBrainrot: false,terminalId: null,terminalCwd: null,@@ -51,6 +56,14 @@ export function buildCommandCenterCells(return { ...EMPTY_CELL_DATA, cellIndex, isBrainrot: true };}+ if (isCanvasCell(cellValue)) {+ return {+ ...EMPTY_CELL_DATA,+ cellIndex,+ canvasId: getCanvasCellId(cellValue),+ };+ }+if (isTerminalCell(cellValue)) {return {...EMPTY_CELL_DATA,diff --git a/products/desktop/packages/core/src/command-center/grid.test.ts b/products/desktop/packages/core/src/command-center/grid.test.tsindex 3c9c9e5cd0d5..5e466ea3e87b 100644--- a/products/desktop/packages/core/src/command-center/grid.test.ts+++ b/products/desktop/packages/core/src/command-center/grid.test.ts@@ -3,6 +3,7 @@ import {BRAINROT_CELL,clampZoom,countActiveTaskCells,+ getCanvasCellId,getCellCount,getCellSessionId,getExpandedLayout,@@ -13,7 +14,9 @@ import {getTerminalCellCwd,getTerminalCellId,isBrainrotCell,+ isCanvasCell,isTerminalCell,+ makeCanvasCellValue,makeTerminalCellValue,reflowCells,resizeCells,@@ -188,6 +191,24 @@ describe("isBrainrotCell", () => {});});+describe("canvas cells", () => {+ it("round-trips a canvas id through the cell value", () => {+ const value = makeCanvasCellValue("canvas-1");+ expect(isCanvasCell(value)).toBe(true);+ expect(getCanvasCellId(value)).toBe("canvas-1");+ });++ it.each([+ { value: "some-task-uuid", expected: false },+ { value: BRAINROT_CELL, expected: false },+ { value: makeTerminalCellValue("abc123"), expected: false },+ { value: null, expected: false },+ ])("isCanvasCell($value) -> $expected", ({ value, expected }) => {+ expect(isCanvasCell(value)).toBe(expected);+ if (!expected) expect(getCanvasCellId(value)).toBeNull();+ });+});+describe("terminal cells", () => {it("round-trips a terminal id through the cell value", () => {const value = makeTerminalCellValue("abc123");@@ -236,6 +257,7 @@ describe("countActiveTaskCells", () => {{ name: "empty cells", cells: [null, null] },{ name: "the brainrot sentinel", cells: [BRAINROT_CELL] },{ name: "terminal cells", cells: [makeTerminalCellValue("abc123")] },+ { name: "canvas cells", cells: [makeCanvasCellValue("canvas-1")] },])("does not count $name", ({ cells }) => {expect(countActiveTaskCells(cells, live)).toBe(0);});@@ -243,7 +265,14 @@ describe("countActiveTaskCells", () => {it("counts a mixed grid correctly", () => {expect(countActiveTaskCells(- [null, BRAINROT_CELL, "task-1", "deleted", makeTerminalCellValue("t")],+ [+ null,+ BRAINROT_CELL,+ "task-1",+ "deleted",+ makeTerminalCellValue("t"),+ makeCanvasCellValue("canvas-1"),+ ],live,),).toBe(1);diff --git a/products/desktop/packages/core/src/command-center/grid.ts b/products/desktop/packages/core/src/command-center/grid.tsindex 42b8cb734fb9..163782f71d02 100644--- a/products/desktop/packages/core/src/command-center/grid.ts+++ b/products/desktop/packages/core/src/command-center/grid.ts@@ -31,6 +31,23 @@ export function isBrainrotCell(value: string | null): boolean {return value === BRAINROT_CELL;}+// Reserved prefix for canvas cells. Canvas and task ids are UUIDs, so this+// cannot collide with either kind of real id.+export const CANVAS_CELL_PREFIX = "__canvas__:";++export function isCanvasCell(value: string | null): value is string {+ return value?.startsWith(CANVAS_CELL_PREFIX) ?? false;+}++export function makeCanvasCellValue(canvasId: string): string {+ return `${CANVAS_CELL_PREFIX}${canvasId}`;+}++export function getCanvasCellId(value: string | null): string | null {+ if (!isCanvasCell(value)) return null;+ return value.slice(CANVAS_CELL_PREFIX.length) || null;+}+// Reserved prefix for standalone terminal cells. Never collides with a task id// (uuids) or with BRAINROT_CELL ("__brainrot__").export const TERMINAL_CELL_PREFIX = "__terminal__:";diff --git a/products/desktop/packages/core/src/command-center/placement.test.ts b/products/desktop/packages/core/src/command-center/placement.test.tsindex 895d9ee162c9..e7d4de71ce7c 100644--- a/products/desktop/packages/core/src/command-center/placement.test.ts+++ b/products/desktop/packages/core/src/command-center/placement.test.ts@@ -1,5 +1,9 @@import { describe, expect, it } from "vitest";-import { BRAINROT_CELL, makeTerminalCellValue } from "./grid";+import {+ BRAINROT_CELL,+ makeCanvasCellValue,+ makeTerminalCellValue,+} from "./grid";import { type PlacementInput, planCommandCenterPlacement } from "./placement";/**@@ -74,6 +78,7 @@ describe("planCommandCenterPlacement", () => {it.each([{ name: "brainrot", cell: BRAINROT_CELL },{ name: "terminal", cell: makeTerminalCellValue("abc123") },+ { name: "canvas", cell: makeCanvasCellValue("canvas-1") },])("never overwrites the $name sentinel", ({ cell }) => {// Sentinels are not tasks, so they are absent from every live task list.const result = planCommandCenterPlacement({diff --git a/products/desktop/packages/core/src/command-center/placement.ts b/products/desktop/packages/core/src/command-center/placement.tsindex eca00047e637..28fd0b27f381 100644--- a/products/desktop/packages/core/src/command-center/placement.ts+++ b/products/desktop/packages/core/src/command-center/placement.ts@@ -2,6 +2,7 @@ import {getCellCount,getLayoutToFit,isBrainrotCell,+ isCanvasCell,isTerminalCell,type LayoutPreset,reflowCells,@@ -38,8 +39,8 @@ export interface PlacementInput {* first, in display order, growing the grid when the batch outgrows them.** Occupied tiles are never overwritten, which also covers the brainrot and- * terminal sentinels — they hold something the grid draws, so they read as- * occupied like any cell holding a session.+ * terminal and canvas sentinels — they hold something the grid draws, so they+ * read as occupied like any cell holding a session.*/export function planCommandCenterPlacement(input: PlacementInput,@@ -53,6 +54,7 @@ export function planCommandCenterPlacement(cell != null &&(liveTaskIds == null ||isBrainrotCell(cell) ||+ isCanvasCell(cell) ||isTerminalCell(cell) ||liveTaskIds.has(cell) ||batch.has(cell));diff --git a/products/desktop/packages/shared/src/analytics-events.ts b/products/desktop/packages/shared/src/analytics-events.tsindex 2395d0727d67..8c83f3b0dbde 100644--- a/products/desktop/packages/shared/src/analytics-events.ts+++ b/products/desktop/packages/shared/src/analytics-events.ts@@ -1092,6 +1092,11 @@ export interface CanvasPromptSentProperties {prompt_length_chars: number;}+export interface CommandCenterCanvasViewedProperties {+ dashboard_id: string;+ canvas_kind: "freeform" | "grid" | "component";+}+export interface CanvasRenderedProperties {channel_id?: string;dashboard_id?: string;@@ -1407,6 +1412,7 @@ export const ANALYTICS_EVENTS = {COMMAND_MENU_OPENED: "Command menu opened",COMMAND_MENU_ACTION: "Command menu action",COMMAND_CENTER_VIEWED: "Command center viewed",+ COMMAND_CENTER_CANVAS_VIEWED: "Command center canvas viewed",BRAINROT_ACTIVATED: "Brainrot activated",POSTHOG_WEB_OPENED: "PostHog web opened",SIDEBAR_NAV_ITEM_CLICKED: "Sidebar nav item clicked",@@ -1596,6 +1602,7 @@ export type EventPropertyMap = {[ANALYTICS_EVENTS.COMMAND_MENU_OPENED]: never;[ANALYTICS_EVENTS.COMMAND_MENU_ACTION]: CommandMenuActionProperties;[ANALYTICS_EVENTS.COMMAND_CENTER_VIEWED]: never;+ [ANALYTICS_EVENTS.COMMAND_CENTER_CANVAS_VIEWED]: CommandCenterCanvasViewedProperties;[ANALYTICS_EVENTS.BRAINROT_ACTIVATED]: BrainrotActivatedProperties;[ANALYTICS_EVENTS.POSTHOG_WEB_OPENED]: never;[ANALYTICS_EVENTS.SIDEBAR_NAV_ITEM_CLICKED]: SidebarNavItemClickedProperties;diff --git a/products/desktop/packages/ui/src/features/canvas/canvasDrag.test.ts b/products/desktop/packages/ui/src/features/canvas/canvasDrag.test.tsnew file mode 100644index 000000000000..64c414cfd472--- /dev/null+++ b/products/desktop/packages/ui/src/features/canvas/canvasDrag.test.ts@@ -0,0 +1,28 @@+import { describe, expect, it, vi } from "vitest";+import {+ CANVAS_DRAG_TYPE,+ readCanvasDragData,+ writeCanvasDragData,+} from "./canvasDrag";++describe("canvas drag data", () => {+ it("writes and reads a canvas id", () => {+ const values = new Map<string, string>();+ const dataTransfer = {+ setData: vi.fn((type: string, value: string) => values.set(type, value)),+ getData: vi.fn((type: string) => values.get(type) ?? ""),+ };++ writeCanvasDragData(dataTransfer, "canvas-1");++ expect(dataTransfer.setData).toHaveBeenCalledWith(+ CANVAS_DRAG_TYPE,+ "canvas-1",+ );+ expect(readCanvasDragData(dataTransfer)).toBe("canvas-1");+ });++ it("returns null when the drag has no canvas", () => {+ expect(readCanvasDragData({ getData: () => "" })).toBeNull();+ });+});diff --git a/products/desktop/packages/ui/src/features/canvas/canvasDrag.ts b/products/desktop/packages/ui/src/features/canvas/canvasDrag.tsnew file mode 100644index 000000000000..52d42b81010a--- /dev/null+++ b/products/desktop/packages/ui/src/features/canvas/canvasDrag.ts@@ -0,0 +1,14 @@+export const CANVAS_DRAG_TYPE = "application/x-posthog-canvas-id";++export function writeCanvasDragData(+ dataTransfer: Pick<DataTransfer, "setData">,+ canvasId: string,+): void {+ dataTransfer.setData(CANVAS_DRAG_TYPE, canvasId);+}++export function readCanvasDragData(+ dataTransfer: Pick<DataTransfer, "getData">,+): string | null {+ return dataTransfer.getData(CANVAS_DRAG_TYPE) || null;+}diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.test.tsxindex a7e67a290a6c..3cccc0e6b804 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.test.tsx@@ -217,7 +217,7 @@ describe("ChannelFeedView", () => {for (const label of ["Pin","Rename",- "Add to Command Center",+ "Add to Command Center…","File to…","Archive",]) {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.tsxindex 157f3db05c3a..9773aa64ed7b 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@@ -1,5 +1,6 @@import type { ChannelItemModel } from "@posthog/core/canvas/channelItems";import { formatRelativeTimeShort } from "@posthog/shared";+import { CANVAS_DRAG_TYPE } from "@posthog/ui/features/canvas/canvasDrag";import type { TaskStatusInput } from "@posthog/ui/features/sidebar/components/items/taskStatusVocabulary";import {TASK_DRAG_TYPE,@@ -320,7 +321,7 @@ describe("ChannelItemRow", () => {expect(dataTransfer.effectAllowed).toBe("copyMove");});- it("does not make canvases draggable into the Command Center", () => {+ it("makes canvases draggable into the Command Center", () => {renderRow(item({key: "canvas:canvas-1",@@ -328,8 +329,13 @@ describe("ChannelItemRow", () => {id: "canvas-1",}),);+ const setData = vi.fn();+ const dataTransfer = { setData, effectAllowed: "none" };++ fireEvent.dragStart(screen.getByRole("button"), { dataTransfer });- expect(screen.getByRole("button")).not.toHaveAttribute("draggable", "true");+ expect(setData).toHaveBeenCalledWith(CANVAS_DRAG_TYPE, "canvas-1");+ expect(dataTransfer.effectAllowed).toBe("copy");});// The hover card and right-click render the same item list from one@@ -337,7 +343,7 @@ describe("ChannelItemRow", () => {const MENU_ITEMS = ["Pin","Rename",- "Add to Command Center",+ "Add to Command Center…","File to…","Archive",];@@ -427,7 +433,7 @@ describe("ChannelItemRow", () => {// Quill keeps a disabled button focusable, so the state is aria-disabled// rather than the native attribute.expect(- screen.getByRole("button", { name: "Add to Command Center" }),+ screen.getByRole("button", { name: "Add to Command Center…" }),).toHaveAttribute("aria-disabled", "true");});@@ -464,7 +470,12 @@ describe("ChannelItemRow", () => {title: "Web analytics overview",});renderInList(- <ChannelItemRow actions={actions} isActive={false} item={canvas} />,+ <ChannelItemRow+ actions={actions}+ isActive={false}+ item={canvas}+ onAddToCommandCenter={() => {}}+ />,);await userEvent.hover(screen.getByText("Web analytics overview"));@@ -473,9 +484,11 @@ describe("ChannelItemRow", () => {await screen.findByRole("button", { name: "Pin" }, { timeout: 2000 }),).not.toBeNull();expect(screen.getByRole("button", { name: "Delete…" })).not.toBeNull();- // A canvas can't be archived, filed to a space, or given a command-centre- // cell, so those items aren't drawn at all rather than drawn dead.- for (const absent of ["Archive", "File to…", "Add to Command Center"]) {+ 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();}});diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsxindex 48106eda5fbf..e76e493f417b 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx@@ -17,6 +17,7 @@ import {} from "@posthog/quill";import { formatRelativeTimeShort } from "@posthog/shared";import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser";+import { writeCanvasDragData } from "@posthog/ui/features/canvas/canvasDrag";import { ChannelItemHoverCard } from "@posthog/ui/features/canvas/components/ChannelItemHoverCard";import { iconForTemplate } from "@posthog/ui/features/canvas/components/canvasTemplateIcon";import {@@ -302,7 +303,11 @@ export function ChannelItemRow({currentUser.data?.id === item.authorUser.id;const handleDragStart = useCallback((event: DragEvent) => {- if (item.kind !== "task") return;+ if (item.kind === "canvas") {+ writeCanvasDragData(event.dataTransfer, item.id);+ event.dataTransfer.effectAllowed = "copy";+ return;+ }writeTaskDragData(event.dataTransfer, item.id);// Both, always. Command Center tiles ask for `copy` and the pinned run@@ -314,9 +319,8 @@ export function ChannelItemRow({[item.id, item.kind, onDragStart],);- // A canvas gets the same menu with the items it actually has: pin, and delete- // instead of archive. Filing and command-centre cells are task-shaped, and the- // menu drops them rather than showing them dead.+ // 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.//// 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.@@ -329,6 +333,7 @@ export function ChannelItemRow({title: item.title,isPinned: item.pinned,onTogglePin: () => actions.togglePin(item),+ onAddToCommandCenter,// Confirm first, like the canvas menus in the artifacts grid and// the canvas header: the canvas and its history go for everyone.onDelete: () => setConfirmDeleteOpen(true),@@ -374,7 +379,7 @@ export function ChannelItemRow({isActive={isActive}isSelected={isSelected}showPinBadge={showPinBadge}- draggable={item.kind === "task"}+ draggableonDragStart={handleDragStart}onDragEnd={onDragEnd}onClick={(e) => (onClick ? onClick(e) : actions.open(item))}diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsxindex 970906fff7ba..af5d9e8005f5 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx@@ -21,6 +21,7 @@ import {PINNED_SECTION_KEY,sortChannelItems,} from "@posthog/core/canvas/channelItems";+import { getCanvasCellId } from "@posthog/core/command-center/grid";import {Button,cn,@@ -56,7 +57,10 @@ import { useChannelTasksRunState } from "@posthog/ui/features/canvas/hooks/useChimport { useLocalDayStart } from "@posthog/ui/features/canvas/hooks/useLocalDayStart";import { SHORTCUTS } from "@posthog/ui/features/command/keyboard-shortcuts";import { useCommandCenterStore } from "@posthog/ui/features/command-center/commandCenterStore";-import { placeTaskInCommandCenter } from "@posthog/ui/features/command-center/placeTaskInCommandCenter";+import {+ placeCanvasInCommandCenter,+ placeTaskInCommandCenter,+} from "@posthog/ui/features/command-center/placeTaskInCommandCenter";import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";import { EditListItemAppearanceDialog } from "@posthog/ui/features/sidebar/components/EditListItemAppearanceDialog";import { SidebarKbdHint } from "@posthog/ui/features/sidebar/components/items/SidebarKbdHint";@@ -87,6 +91,27 @@ import {const RECENTS_CAP = 30;const log = logger.scope("channel-sidebar");+function commandCenterAssigner(item: ChannelItemModel): () => void {+ return () => {+ if (item.kind === "canvas") {+ placeCanvasInCommandCenter(item.id, item.title);+ } else {+ placeTaskInCommandCenter(item.id, item.title);+ }+ };+}++function isInCommandCenter(+ item: ChannelItemModel,+ commandCenterCells: readonly (string | null)[],+): boolean {+ return commandCenterCells.some((cell) =>+ item.kind === "canvas"+ ? getCanvasCellId(cell) === item.id+ : cell === item.id,+ );+}+/** The list holds two kinds of thing, and shows one of them at a time. */type ChannelTab = ChannelItemModel["kind"];@@ -524,9 +549,6 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {actions.open(item);};- const commandCenterAssigner = (taskId: string, taskTitle: string) => () =>- placeTaskInCommandCenter(taskId, taskTitle);-const rowTransition = prefersReducedMotion? { duration: 0 }: {@@ -622,12 +644,11 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {onRename={item.kind === "task" ? () => setEditingTaskId(item.id) : undefined}- // Undefined disables the menu item: a full command centre has nowhere to- // put the task, and an action that silently does nothing is worse than a- // greyed-out one.+ // Undefined disables the menu item when this item is already present;+ // duplicating the same task or canvas would make the grid ambiguous.onAddToCommandCenter={- item.kind === "task" && !commandCenterCells.includes(item.id)- ? commandCenterAssigner(item.id, item.title)+ !isInCommandCenter(item, commandCenterCells)+ ? commandCenterAssigner(item): undefined}onEditSubmit={diff --git a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsxindex 2fa5fb1f326c..e98e70c398a7 100644--- a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx@@ -44,10 +44,9 @@ import { type ComponentType, type ReactNode, useMemo, useState } from "react";* ones its list already has (pin, archive, delete, rename inline); only filing —* which needs the channel list and a mutation — belongs to the menu.*- * Canvases share this menu but not all of it: they can be pinned and deleted,- * and they can't be filed to a space or given a command-centre cell, both of- * which are task-shaped. `kind` is what decides, so a canvas gets a menu of the- * actions it has rather than a full one with half its items dead.+ * 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.*/export interface TaskRowMenuProps {kind: "task" | "canvas";@@ -147,15 +146,13 @@ function TaskRowMenuItems({Stop task</Item>)}- {isTask && (- <Item- disabled={!menu.onAddToCommandCenter}- onClick={menu.onAddToCommandCenter}- >- <SquaresFourIcon size={14} />- Add to Command Center- </Item>- )}+ <Item+ disabled={!menu.onAddToCommandCenter}+ onClick={menu.onAddToCommandCenter}+ >+ <SquaresFourIcon size={14} />+ Add to Command Center…+ </Item>{isTask && channelItems.length > 0 && (<Sub><SubTrigger>diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsxindex 199c9c0166a5..42e5380d2372 100644--- a/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx+++ b/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx@@ -154,9 +154,11 @@ function draftBadgeVariant(export function FreeformCanvasView({threadId,interactive,+ embedded = false,}: {threadId: string;interactive: boolean;+ embedded?: boolean;}) {const dashboardId = dashboardIdOf(threadId);const { runtimeError, browseVersionId } = useFreeformThread(threadId);@@ -775,6 +777,7 @@ export function FreeformCanvasView({if (effectiveTaskId) setGeneratingPanelDismissed(false);}, [effectiveTaskId]);const generatingPanelOpen =+ !embedded &&isGenerating &&!!effectiveTaskId &&!pinnedArtifact &&@@ -788,7 +791,7 @@ export function FreeformCanvasView({hasContent,hasActiveTask: !!effectiveTaskId,generatingPanelOpen,- viewOpen: panelViewOpen,+ viewOpen: embedded ? false : panelViewOpen,collapsed,hasCommentTask: !!commentTaskId,});@@ -801,7 +804,7 @@ export function FreeformCanvasView({(hasActiveCanvasBuild(lifecycle) ||!!currentHeadBuildFailure(lifecycle) ||latestFinishedCanvasBuild(lifecycle)?.buildStatus === "failed");- const showToolbar = interactive || hasBuildSignal;+ const showToolbar = !embedded && (interactive || hasBuildSignal);return (<Flex height="100%" overflow="hidden" position="relative">@@ -1249,14 +1252,16 @@ export function FreeformCanvasView({</ResizableSidebar>)}- <CanvasSelectionCommentAction- selection={textSelection}- taskId={commentTaskId}- dashboardId={dashboardId}- canvasName={dashboard?.name ?? "Canvas"}- versionId={displayedVersionId}- onDismiss={dismissTextSelection}- />+ {!embedded && (+ <CanvasSelectionCommentAction+ selection={textSelection}+ taskId={commentTaskId}+ dashboardId={dashboardId}+ canvasName={dashboard?.name ?? "Canvas"}+ versionId={displayedVersionId}+ onDismiss={dismissTextSelection}+ />+ )}{/* The empty-canvas landing: a centered composer with suggestions,overlaying the canvas area. On submit it slides down; once it's gonediff --git a/products/desktop/packages/ui/src/features/command-center/commandCenterStore.test.ts b/products/desktop/packages/ui/src/features/command-center/commandCenterStore.test.tsindex 9255c67b2980..b4f647789668 100644--- a/products/desktop/packages/ui/src/features/command-center/commandCenterStore.test.ts+++ b/products/desktop/packages/ui/src/features/command-center/commandCenterStore.test.ts@@ -1,5 +1,6 @@import {BRAINROT_CELL,+ makeCanvasCellValue,makeTerminalCellValue,} from "@posthog/core/command-center/grid";import { beforeEach, describe, expect, it, vi } from "vitest";@@ -168,6 +169,35 @@ describe("commandCenterStore", () => {});});+ describe("setCanvasCell", () => {+ it("stores one canvas once and focuses its cell", () => {+ useCommandCenterStore.getState().setCanvasCell(1, "canvas-1");+ useCommandCenterStore.getState().setCanvasCell(3, "canvas-1");++ const state = useCommandCenterStore.getState();+ expect(state.cells).toEqual([+ null,+ null,+ null,+ makeCanvasCellValue("canvas-1"),+ ]);+ expect(state.activeCellIndex).toBe(3);+ expect(state.activeTaskId).toBeNull();+ expect(state.hasAutofilled).toBe(true);+ });++ it("clears a pending canvas placement", () => {+ useCommandCenterStore.getState().requestPlacement({+ kind: "canvas",+ id: "canvas-1",+ title: "Activation overview",+ });+ useCommandCenterStore.getState().setCanvasCell(2, "canvas-1");++ expect(useCommandCenterStore.getState().pendingPlacement).toBeNull();+ });+ });+describe("hasAutofilled", () => {it("assigning a task marks the grid as curated", () => {useCommandCenterStore.getState().assignTask(0, "t1");@@ -244,10 +274,15 @@ describe("commandCenterStore", () => {describe("pending placement", () => {it("keeps the requested task available until placement is canceled", () => {- useCommandCenterStore.getState().requestPlacement("t1", "Fix signup");+ useCommandCenterStore.getState().requestPlacement({+ kind: "task",+ id: "t1",+ title: "Fix signup",+ });expect(useCommandCenterStore.getState().pendingPlacement).toEqual({- taskId: "t1",- taskTitle: "Fix signup",+ kind: "task",+ id: "t1",+ title: "Fix signup",});useCommandCenterStore.getState().cancelPlacement();@@ -255,7 +290,11 @@ describe("commandCenterStore", () => {});it("clears the request when the task is assigned", () => {- useCommandCenterStore.getState().requestPlacement("t1", "Fix signup");+ useCommandCenterStore.getState().requestPlacement({+ kind: "task",+ id: "t1",+ title: "Fix signup",+ });useCommandCenterStore.getState().assignTask(2, "t1");expect(useCommandCenterStore.getState().pendingPlacement).toBeNull();expect(useCommandCenterStore.getState().cells[2]).toBe("t1");diff --git a/products/desktop/packages/ui/src/features/command-center/commandCenterStore.ts b/products/desktop/packages/ui/src/features/command-center/commandCenterStore.tsindex d358a924f986..09518c030005 100644--- a/products/desktop/packages/ui/src/features/command-center/commandCenterStore.ts+++ b/products/desktop/packages/ui/src/features/command-center/commandCenterStore.ts@@ -4,6 +4,7 @@ import {getCellCount,getOptimalLayout,type LayoutPreset,+ makeCanvasCellValue,makeTerminalCellValue,reflowCells,resizeCells,@@ -19,6 +20,12 @@ export {getGridDimensions,} from "@posthog/core/command-center/grid";+export type CommandCenterPlacement = {+ kind: "task" | "canvas";+ id: string;+ title: string;+};+interface CommandCenterStoreState {layout: LayoutPreset;cells: (string | null)[];@@ -28,7 +35,7 @@ interface CommandCenterStoreState {creatingCells: number[];// Persisted so autofill bootstraps the grid only once, not on every remount.hasAutofilled: boolean;- pendingPlacement: { taskId: string; taskTitle: string } | null;+ pendingPlacement: CommandCenterPlacement | null;}interface CommandCenterStoreActions {@@ -36,6 +43,7 @@ interface CommandCenterStoreActions {setActiveTask: (taskId: string | null) => void;setActiveCell: (cellIndex: number | null) => void;assignTask: (cellIndex: number, taskId: string) => void;+ setCanvasCell: (cellIndex: number, canvasId: string) => void;setBrainrotCell: (cellIndex: number) => void;setTerminalCell: (cellIndex: number,@@ -57,7 +65,7 @@ interface CommandCenterStoreActions {zoomOut: () => void;startCreating: (cellIndex: number) => void;stopCreating: (cellIndex: number) => void;- requestPlacement: (taskId: string, taskTitle: string) => void;+ requestPlacement: (placement: CommandCenterPlacement) => void;cancelPlacement: () => void;}@@ -128,6 +136,26 @@ export const useCommandCenterStore = create<CommandCenterStore>()(};}),+ setCanvasCell: (cellIndex, canvasId) =>+ set((state) => {+ if (cellIndex < 0 || cellIndex >= state.cells.length) return state;+ const cellValue = makeCanvasCellValue(canvasId);+ const cells = [...state.cells];+ const existingIndex = cells.indexOf(cellValue);+ if (existingIndex !== -1) {+ cells[existingIndex] = null;+ }+ cells[cellIndex] = cellValue;+ return {+ cells,+ activeTaskId: null,+ activeCellIndex: cellIndex,+ creatingCells: state.creatingCells.filter((i) => i !== cellIndex),+ hasAutofilled: true,+ pendingPlacement: null,+ };+ }),+setBrainrotCell: (cellIndex) =>set((state) => {if (cellIndex < 0 || cellIndex >= state.cells.length) return state;@@ -277,8 +305,7 @@ export const useCommandCenterStore = create<CommandCenterStore>()(creatingCells: state.creatingCells.filter((i) => i !== cellIndex),})),- requestPlacement: (taskId, taskTitle) =>- set({ pendingPlacement: { taskId, taskTitle } }),+ requestPlacement: (placement) => set({ pendingPlacement: placement }),cancelPlacement: () => set({ pendingPlacement: null }),}),{diff --git a/products/desktop/packages/ui/src/features/command-center/components/CommandCenterGrid.tsx b/products/desktop/packages/ui/src/features/command-center/components/CommandCenterGrid.tsxindex 883d2af91c29..195f6894939e 100644--- a/products/desktop/packages/ui/src/features/command-center/components/CommandCenterGrid.tsx+++ b/products/desktop/packages/ui/src/features/command-center/components/CommandCenterGrid.tsx@@ -5,6 +5,10 @@ import {getExpansionCellIndex,} from "@posthog/core/command-center/grid";import { Button } from "@posthog/quill";+import {+ CANVAS_DRAG_TYPE,+ readCanvasDragData,+} from "@posthog/ui/features/canvas/canvasDrag";import {consumeTaskDrop,readTaskDragData,@@ -16,13 +20,16 @@ import { destroyShellTerminal } from "@posthog/ui/features/terminal/destroyShellimport { useCallback, useEffect, useRef, useState } from "react";import { FOCUSABLE_SELECTOR } from "../../../utils/overlay";import {+ type CommandCenterPlacement,getGridDimensions,type LayoutPreset,useCommandCenterStore,} from "../commandCenterStore";import type { CommandCenterCellData } from "../hooks/useCommandCenterData";import {+ expandCanvasInCommandCenterInto,expandTasksInCommandCenterInto,+ placeCanvasInCommandCenterCell,placeTasksInCommandCenterCell,} from "../placeTaskInCommandCenter";import { getTerminalCellStateKey } from "../terminalCells";@@ -35,31 +42,43 @@ import { CommandCenterPanel } from "./CommandCenterPanel";* carries whatever was dragged.*/type PlacementState =- | { mode: "pick"; taskId: string; taskTitle: string }- | { mode: "drag" };+ | ({ mode: "pick" } & CommandCenterPlacement)+ | { mode: "drag"; kind: CommandCenterPlacement["kind"] };++type DroppedItem =+ | { kind: "task"; ids: string[] }+ | { kind: "canvas"; id: string };interface CommandCenterGridProps {layout: LayoutPreset;cells: CommandCenterCellData[];}-function hasTaskDragType(types: readonly string[]): boolean {- return types.includes(TASK_IDS_DRAG_TYPE) || types.includes(TASK_DRAG_TYPE);+function draggedItemKind(+ types: readonly string[],+): CommandCenterPlacement["kind"] | null {+ if (types.includes(CANVAS_DRAG_TYPE)) return "canvas";+ if (types.includes(TASK_IDS_DRAG_TYPE) || types.includes(TASK_DRAG_TYPE)) {+ return "task";+ }+ return null;}-function useTaskDragActive() {- const [active, setActive] = useState(false);+function useCellDragActive() {+ const [active, setActive] = useState<CommandCenterPlacement["kind"] | null>(+ null,+ );useEffect(() => {const onDragStart = (e: DragEvent) => {- if (e.dataTransfer && hasTaskDragType(e.dataTransfer.types)) {- setActive(true);+ if (e.dataTransfer) {+ setActive(draggedItemKind(e.dataTransfer.types));}};- const onDragEnd = () => setActive(false);- const onDrop = () => setActive(false);+ const onDragEnd = () => setActive(null);+ const onDrop = () => setActive(null);const onDragLeave = (e: DragEvent) => {- if (!e.relatedTarget) setActive(false);+ if (!e.relatedTarget) setActive(null);};document.addEventListener("dragstart", onDragStart);@@ -77,13 +96,13 @@ function useTaskDragActive() {return active;}-function useTaskDropTarget(onTasks: (taskIds: string[]) => void) {+function useCellDropTarget(onItem: (item: DroppedItem) => void) {const [isOver, setIsOver] = useState(false);return {isOver,onDragOver: (e: React.DragEvent) => {- if (!hasTaskDragType(e.dataTransfer.types)) return;+ if (!draggedItemKind(e.dataTransfer.types)) return;e.preventDefault();e.dataTransfer.dropEffect = "copy";setIsOver(true);@@ -92,12 +111,17 @@ function useTaskDropTarget(onTasks: (taskIds: string[]) => void) {onDrop: (e: React.DragEvent) => {e.preventDefault();setIsOver(false);+ const canvasId = readCanvasDragData(e.dataTransfer);+ if (canvasId) {+ onItem({ kind: "canvas", id: canvasId });+ return;+ }const taskIds = readTaskDragData(e.dataTransfer);if (taskIds.length === 0) return;// Filing is what this drop was for, so the pin drag behind the same// gesture leaves the sessions pinned where they were.consumeTaskDrop();- onTasks(taskIds);+ onItem({ kind: "task", ids: taskIds });},};}@@ -181,26 +205,33 @@ function GridCell({const liveTaskIds = useLiveTaskIds();const placeInCell = useCallback(- (taskIds: string[]) => {+ (item: DroppedItem) => {if (cell.terminalId) {destroyShellTerminal(getTerminalCellStateKey(cell.terminalId));}- placeTasksInCommandCenterCell(taskIds, cell.cellIndex, liveTaskIds);+ if (item.kind === "canvas") {+ placeCanvasInCommandCenterCell(item.id, cell.cellIndex);+ } else {+ placeTasksInCommandCenterCell(item.ids, cell.cellIndex, liveTaskIds);+ }},[cell.cellIndex, cell.terminalId, liveTaskIds],);- const dropTarget = useTaskDropTarget(placeInCell);+ const dropTarget = useCellDropTarget(placeInCell);- const isEmpty = !cell.task && !cell.terminalId && !cell.isBrainrot;+ const isEmpty =+ !cell.task && !cell.canvasId && !cell.terminalId && !cell.isBrainrot;const targetLabel = cell.terminalId? "Replace terminal": cell.isBrainrot? "Replace Brainrot"- : cell.task?.title- ? `Replace ${cell.task.title}`- : "Use this tile";+ : cell.canvasId+ ? "Replace canvas"+ : cell.task?.title+ ? `Replace ${cell.task.title}`+ : "Use this tile";return (// biome-ignore lint/a11y/useKeyWithClickEvents lint/a11y/noStaticElementInteractions: click delegates focus to ActionSelector within@@ -231,7 +262,12 @@ function GridCell({className={`absolute inset-0 z-10 p-4 ${TARGET_CLASSES} ${targetOutline(dropTarget.isOver)}`}onClick={placement.mode === "pick"- ? () => placeInCell([placement.taskId])+ ? () =>+ placeInCell(+ placement.kind === "canvas"+ ? { kind: "canvas", id: placement.id }+ : { kind: "task", ids: [placement.id] },+ ): undefined}onDragOver={dropTarget.onDragOver}@@ -239,7 +275,7 @@ function GridCell({onDrop={dropTarget.onDrop}aria-label={placement.mode === "pick"- ? `${targetLabel} with ${placement.taskTitle}`+ ? `${targetLabel} with ${placement.title}`: targetLabel}>@@ -263,11 +299,16 @@ function ExpandSlot({}) {const liveTaskIds = useLiveTaskIds();const expand = useCallback(- (taskIds: string[]) =>- expandTasksInCommandCenterInto(direction, slot, taskIds, liveTaskIds),+ (item: DroppedItem) => {+ if (item.kind === "canvas") {+ expandCanvasInCommandCenterInto(direction, slot, item.id);+ } else {+ expandTasksInCommandCenterInto(direction, slot, item.ids, liveTaskIds);+ }+ },[direction, liveTaskIds, slot],);- const dropTarget = useTaskDropTarget(expand);+ const dropTarget = useCellDropTarget(expand);const { cols, rows } = getGridDimensions(expanded);return (@@ -275,7 +316,14 @@ function ExpandSlot({type="button"className={`flex-1 p-1 text-accent-11 ${TARGET_CLASSES} ${targetOutline(dropTarget.isOver)}`}onClick={- placement.mode === "pick" ? () => expand([placement.taskId]) : undefined+ placement.mode === "pick"+ ? () =>+ expand(+ placement.kind === "canvas"+ ? { kind: "canvas", id: placement.id }+ : { kind: "task", ids: [placement.id] },+ )+ : undefined}onDragOver={dropTarget.onDragOver}onDragLeave={dropTarget.onDragLeave}@@ -344,14 +392,14 @@ export function CommandCenterGrid({ layout, cells }: CommandCenterGridProps) {const { cols, rows } = getGridDimensions(layout);const zoom = useCommandCenterStore((s) => s.zoom);const activeCellIndex = useCommandCenterStore((s) => s.activeCellIndex);- const isDragActive = useTaskDragActive();+ const draggedKind = useCellDragActive();const pendingPlacement = useCommandCenterStore((s) => s.pendingPlacement);const cancelPlacement = useCommandCenterStore((s) => s.cancelPlacement);const placement: PlacementState | null = pendingPlacement? { mode: "pick", ...pendingPlacement }- : isDragActive- ? { mode: "drag" }+ : draggedKind+ ? { mode: "drag", kind: draggedKind }: null;useEffect(() => {@@ -370,7 +418,7 @@ export function CommandCenterGrid({ layout, cells }: CommandCenterGridProps) {// floating over the grid.<div className="-translate-x-1/2 absolute top-3 left-1/2 z-20 flex items-center gap-3 rounded-full border border-accent-7 bg-accent-3 px-3 py-1.5 shadow-md"><span className="whitespace-nowrap text-[12px] text-accent-12">- Choose a tile for {pendingPlacement.taskTitle}+ Choose a tile for {pendingPlacement.title}</span><Button variant="link-muted" size="xs" onClick={cancelPlacement}>Canceldiff --git a/products/desktop/packages/ui/src/features/command-center/components/CommandCenterPanel.tsx b/products/desktop/packages/ui/src/features/command-center/components/CommandCenterPanel.tsxindex a6db853c90d5..6cc5a7aef597 100644--- a/products/desktop/packages/ui/src/features/command-center/components/CommandCenterPanel.tsx+++ b/products/desktop/packages/ui/src/features/command-center/components/CommandCenterPanel.tsx@@ -6,13 +6,25 @@ import {GitFork,Lightning,Plus,+ Shapes,Terminal,X,} from "@phosphor-icons/react";import { isBrainrotCell } from "@posthog/core/command-center/grid";-import { Spinner as QuillSpinner, Text as QuillText } from "@posthog/quill";+import {+ Empty,+ EmptyDescription,+ EmptyHeader,+ EmptyMedia,+ EmptyTitle,+ Spinner as QuillSpinner,+ Text as QuillText,+} from "@posthog/quill";import { ANALYTICS_EVENTS, type WorkspaceMode } from "@posthog/shared";import type { Task } from "@posthog/shared/domain-types";+import { FreeformCanvasView } from "@posthog/ui/features/canvas/freeform/FreeformCanvasView";+import { GridCanvasView } from "@posthog/ui/features/canvas/grid/GridCanvasView";+import { useDashboard } from "@posthog/ui/features/canvas/hooks/useDashboards";import { useSettingsStore } from "@posthog/ui/features/settings/settingsStore";import { destroyShellTerminal } from "@posthog/ui/features/terminal/destroyShellTerminal";import { ShellTerminal } from "@posthog/ui/features/terminal/ShellTerminal";@@ -21,6 +33,7 @@ import { track } from "@posthog/ui/shell/analytics";import { useHostCapabilities } from "@posthog/ui/shell/useHostCapabilities";import { secureRandomString } from "@posthog/ui/utils/random";import { Flex, Text } from "@radix-ui/themes";+import { useNavigate } from "@tanstack/react-router";import { useCallback, useEffect, useRef, useState } from "react";import { useFolders } from "../../folders/useFolders";import { useCloudPrUrl } from "../../git-interaction/useCloudPrUrl";@@ -390,6 +403,95 @@ function TerminalCell({);}+function CanvasCell({+ cellIndex,+ canvasId,+}: {+ cellIndex: number;+ canvasId: string;+}) {+ const clearCell = useCommandCenterStore((s) => s.clearCell);+ const { dashboard, isLoading } = useDashboard(canvasId);+ const navigate = useNavigate();+ const canvasKind = dashboard?.kind;++ useEffect(() => {+ if (!canvasKind) return;+ track(ANALYTICS_EVENTS.COMMAND_CENTER_CANVAS_VIEWED, {+ dashboard_id: canvasId,+ canvas_kind: canvasKind,+ });+ }, [canvasId, canvasKind]);++ const handleOpen = useCallback(() => {+ if (!dashboard) return;+ void navigate({+ to: "/website/$channelId/dashboards/$dashboardId",+ params: { channelId: dashboard.channelId, dashboardId: canvasId },+ });+ }, [canvasId, dashboard, navigate]);++ return (+ <div className="flex h-full flex-col">+ <div className="flex shrink-0 items-center gap-2 border-gray-6 border-b px-2 py-1">+ <Shapes size={12} className="shrink-0 text-violet-9" />+ <QuillText+ className="min-w-0 flex-1 truncate font-medium text-[12px]"+ title={dashboard?.name}+ >+ {dashboard?.name ??+ (isLoading ? "Loading canvas…" : "Canvas unavailable")}+ </QuillText>+ {dashboard && (+ <button+ type="button"+ onClick={handleOpen}+ className="flex h-5 w-5 items-center justify-center rounded text-gray-10 transition-colors hover:bg-gray-4 hover:text-gray-12"+ title="Open canvas"+ >+ <ArrowsOut size={12} />+ </button>+ )}+ <button+ type="button"+ onClick={() => clearCell(cellIndex)}+ className="flex h-5 w-5 items-center justify-center rounded text-gray-10 transition-colors hover:bg-gray-4 hover:text-gray-12"+ title="Remove from grid"+ >+ <X size={12} />+ </button>+ </div>+ <div className="min-h-0 flex-1">+ {isLoading ? (+ <div className="flex h-full items-center justify-center">+ <QuillSpinner className="h-6 w-6" />+ </div>+ ) : dashboard?.kind === "grid" ? (+ <GridCanvasView canvasId={canvasId} interactive={false} />+ ) : dashboard ? (+ <FreeformCanvasView+ threadId={`dashboard:${canvasId}`}+ interactive={false}+ embedded+ />+ ) : (+ <Empty className="h-full border-0">+ <EmptyHeader>+ <EmptyMedia variant="icon">+ <Shapes size={20} />+ </EmptyMedia>+ <EmptyTitle>Canvas unavailable</EmptyTitle>+ <EmptyDescription>+ This canvas is no longer available.+ </EmptyDescription>+ </EmptyHeader>+ </Empty>+ )}+ </div>+ </div>+ );+}+function PopulatedCell({cell,isActiveSession,@@ -472,6 +574,10 @@ export function CommandCenterPanel({return <BrainrotCell cellIndex={cell.cellIndex} />;}+ if (cell.canvasId) {+ return <CanvasCell cellIndex={cell.cellIndex} canvasId={cell.canvasId} />;+ }+if (cell.terminalId) {return (<TerminalCelldiff --git a/products/desktop/packages/ui/src/features/command-center/components/CommandCenterView.tsx b/products/desktop/packages/ui/src/features/command-center/components/CommandCenterView.tsxindex a3e84763686a..c8f40759c064 100644--- a/products/desktop/packages/ui/src/features/command-center/components/CommandCenterView.tsx+++ b/products/desktop/packages/ui/src/features/command-center/components/CommandCenterView.tsx@@ -17,13 +17,15 @@ export function CommandCenterView() {// A cell whose task has been deleted holds a dead id, so occupancy is judged// on what actually renders — Optimize then packs the grid and drops the rest.- const occupiedCellIndices = useMemo(- () =>- cells- .filter((cell) => cell.task || cell.terminalId || cell.isBrainrot)- .map((cell) => cell.cellIndex),- [cells],- );+ const occupiedCellIndices = useMemo(() => {+ const indices: number[] = [];+ for (const cell of cells) {+ if (cell.task || cell.canvasId || cell.terminalId || cell.isBrainrot) {+ indices.push(cell.cellIndex);+ }+ }+ return indices;+ }, [cells]);const visibleTaskIdsKey = cells.map((c) => c.taskId)diff --git a/products/desktop/packages/ui/src/features/command-center/placeTaskInCommandCenter.test.ts b/products/desktop/packages/ui/src/features/command-center/placeTaskInCommandCenter.test.tsindex c136e516ec7b..2ab3956c5a1b 100644--- a/products/desktop/packages/ui/src/features/command-center/placeTaskInCommandCenter.test.ts+++ b/products/desktop/packages/ui/src/features/command-center/placeTaskInCommandCenter.test.ts@@ -1,14 +1,43 @@+import { makeCanvasCellValue } from "@posthog/core/command-center/grid";import { beforeEach, describe, expect, it, vi } from "vitest";import {COMMAND_CENTER_INITIAL_STATE,useCommandCenterStore,} from "./commandCenterStore";-import { placeTasksInCommandCenterCell } from "./placeTaskInCommandCenter";+import {+ placeCanvasInCommandCenter,+ placeCanvasInCommandCenterCell,+ placeTasksInCommandCenterCell,+} from "./placeTaskInCommandCenter";vi.mock("@posthog/ui/router/navigationBridge", () => ({navigateToCommandCenter: vi.fn(),}));+describe("canvas placement", () => {+ beforeEach(() => {+ useCommandCenterStore.setState(COMMAND_CENTER_INITIAL_STATE);+ });++ it("opens the tile picker for a canvas", () => {+ placeCanvasInCommandCenter("canvas-1", "Activation overview");++ expect(useCommandCenterStore.getState().pendingPlacement).toEqual({+ kind: "canvas",+ id: "canvas-1",+ title: "Activation overview",+ });+ });++ it("places a canvas in the selected cell", () => {+ placeCanvasInCommandCenterCell("canvas-1", 1);++ expect(useCommandCenterStore.getState().cells[1]).toBe(+ makeCanvasCellValue("canvas-1"),+ );+ });+});+describe("placeTasksInCommandCenterCell", () => {beforeEach(() => {useCommandCenterStore.setState({diff --git a/products/desktop/packages/ui/src/features/command-center/placeTaskInCommandCenter.ts b/products/desktop/packages/ui/src/features/command-center/placeTaskInCommandCenter.tsindex 28ca160a6bea..997bfd8f10e2 100644--- a/products/desktop/packages/ui/src/features/command-center/placeTaskInCommandCenter.ts+++ b/products/desktop/packages/ui/src/features/command-center/placeTaskInCommandCenter.ts@@ -16,7 +16,23 @@ export function placeTaskInCommandCenter(taskId: string,taskTitle: string,): void {- useCommandCenterStore.getState().requestPlacement(taskId, taskTitle);+ useCommandCenterStore.getState().requestPlacement({+ kind: "task",+ id: taskId,+ title: taskTitle,+ });+ navigateToCommandCenter();+}++export function placeCanvasInCommandCenter(+ canvasId: string,+ canvasTitle: string,+): void {+ useCommandCenterStore.getState().requestPlacement({+ kind: "canvas",+ id: canvasId,+ title: canvasTitle,+ });navigateToCommandCenter();}@@ -85,6 +101,28 @@ export function placeTasksInCommandCenterCell(}}+export function placeCanvasInCommandCenterCell(+ canvasId: string,+ cellIndex: number,+): void {+ useCommandCenterStore.getState().setCanvasCell(cellIndex, canvasId);+}++export function expandCanvasInCommandCenterInto(+ direction: ExpandDirection,+ slot: number,+ canvasId: string,+): void {+ const state = useCommandCenterStore.getState();+ const expanded = getExpandedLayout(state.layout, direction);+ if (!expanded) return;++ state.setLayout(expanded);+ useCommandCenterStore+ .getState()+ .setCanvasCell(getExpansionCellIndex(expanded, direction, slot), canvasId);+}+export function expandTasksInCommandCenterInto(direction: ExpandDirection,slot: number,