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): enable canvas comments without a task (#106919)

Shy Alterb24b452da18b
diff --git a/products/desktop/docs/DEEP-LINKS.md b/products/desktop/docs/DEEP-LINKS.md
index 2bce67ef8c94..a8e92fbe2554 100644
--- a/products/desktop/docs/DEEP-LINKS.md
+++ b/products/desktop/docs/DEEP-LINKS.md
@@ -89,13 +89,13 @@ Open an existing task. Optionally jump to a specific run, or focus a comment thr
| `<taskId>` | Yes | Task ID |
| `run/<taskRunId>` | No | Specific run to open |
| `comment` | No | Comment thread (root comment id) to focus after the task opens |
-| `scope` | No | Comment target scope when the thread lives on a sub-resource: `desktop_canvas` or `task_artifact`. Defaults to the task itself. |
+| `scope` | No | Comment target scope when the thread lives on a sub-resource: `canvas` or `task_artifact`. Defaults to the task itself. The app also accepts the old name `desktop_canvas`. |
| `item` | No | Row id of the canvas/artifact the thread lives on; required alongside `scope` |
```
posthog-code://task/abc123
posthog-code://task/abc123/run/xyz789
-posthog-code://task/abc123?comment=thread-1&scope=desktop_canvas&item=canvas-9
+posthog-code://task/abc123?comment=thread-1&scope=canvas&item=canvas-9
```
An **https** bridge also exists for links sent outside the app (e.g. comment Slack DMs): `<instance>/code/task/<taskId>` resolves to a web interstitial in PostHog Cloud, which fires this scheme — forwarding the `comment`, `scope`, and `item` params — or offers the desktop-app download.
diff --git a/products/desktop/packages/api-client/src/posthog-client.ts b/products/desktop/packages/api-client/src/posthog-client.ts
index 178f3188687d..c16e864b1613 100644
--- a/products/desktop/packages/api-client/src/posthog-client.ts
+++ b/products/desktop/packages/api-client/src/posthog-client.ts
@@ -415,7 +415,8 @@ export interface TaskSessionStorageAccess {
* free-form column on the backend `Comment` model, so adding a resource is a
* new member here plus a caller — no migration and no endpoint.
*/
-export type CommentScope = "task_artifact" | "desktop_canvas" | "task";
+export const COMMENT_SCOPES = ["task_artifact", "canvas", "task"] as const;
+export type CommentScope = (typeof COMMENT_SCOPES)[number];
/** Named `Resource*` so it never collides with the DOM's global `Comment`.
* Optimistic rows do not have a server version yet, while item_context is a
diff --git a/products/desktop/packages/core/src/canvas/taskActivity.ts b/products/desktop/packages/core/src/canvas/taskActivity.ts
index d06c30bb3c26..f73b805a3369 100644
--- a/products/desktop/packages/core/src/canvas/taskActivity.ts
+++ b/products/desktop/packages/core/src/canvas/taskActivity.ts
@@ -3,7 +3,7 @@ import type {
TaskActivityKind,
UserBasic,
} from "@posthog/shared/domain-types";
-import type { CommentTarget } from "../comments/anchors";
+import { type CommentTarget, commentScopeFromWire } from "../comments/anchors";
import { channelDisplayName } from "./channelName";
/**
@@ -15,7 +15,7 @@ import { channelDisplayName } from "./channelName";
export interface TaskActivityItem {
id: string;
- taskId: string;
+ taskId: string | null;
taskTitle: string;
/** Backend channel (tasks product Channel UUID); null for channel-less tasks. */
channelId: string | null;
@@ -39,7 +39,7 @@ export interface TaskActivityItem {
* space, or one the reader can't open.
*/
export function activityCanvasId(item: TaskActivityItem): string | null {
- return item.commentTarget?.scope === "desktop_canvas"
+ return item.commentTarget?.scope === "canvas"
? item.commentTarget.itemId
: null;
}
@@ -48,25 +48,25 @@ export function activityCanvasId(item: TaskActivityItem): string | null {
export function toTaskActivityItems(
activity: readonly TaskActivity[],
): TaskActivityItem[] {
- return activity.map((row) => ({
- id: row.id,
- taskId: row.task_id,
- taskTitle: row.task_title || "Untitled task",
- channelId: row.channel_id ?? null,
- channelName: channelDisplayName(row.channel_name ?? null),
- activityAt: row.activity_at,
- activityKind: row.activity_kind,
- snippet: row.snippet,
- author: row.latest_author ?? null,
- messageId: row.latest_message_id ?? null,
- commentId: row.latest_comment_id ?? null,
- commentTarget:
- row.latest_comment_scope && row.latest_comment_item_id
- ? {
- scope: row.latest_comment_scope as CommentTarget["scope"],
- itemId: row.latest_comment_item_id,
- }
- : null,
- isUnread: row.is_unread,
- }));
+ return activity.map((row) => {
+ const scope = commentScopeFromWire(row.latest_comment_scope);
+ return {
+ id: row.id,
+ taskId: row.task_id,
+ taskTitle: row.task_title || "Untitled task",
+ channelId: row.channel_id ?? null,
+ channelName: channelDisplayName(row.channel_name ?? null),
+ activityAt: row.activity_at,
+ activityKind: row.activity_kind,
+ snippet: row.snippet,
+ author: row.latest_author ?? null,
+ messageId: row.latest_message_id ?? null,
+ commentId: row.latest_comment_id ?? null,
+ commentTarget:
+ scope && row.latest_comment_item_id
+ ? { scope, itemId: row.latest_comment_item_id }
+ : null,
+ isUnread: row.is_unread,
+ };
+ });
}
diff --git a/products/desktop/packages/core/src/comments/anchors.test.ts b/products/desktop/packages/core/src/comments/anchors.test.ts
index 2da4660705ec..d423bd7c000a 100644
--- a/products/desktop/packages/core/src/comments/anchors.test.ts
+++ b/products/desktop/packages/core/src/comments/anchors.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import {
+ commentScopeFromWire,
createTextCommentAnchor,
isThreadResolved,
parseCommentContext,
@@ -7,6 +8,16 @@ import {
} from "./anchors";
describe("artifact text anchors", () => {
+ it.each([
+ ["canvas", "canvas"],
+ ["desktop_canvas", "canvas"],
+ ["task_artifact", "task_artifact"],
+ ["Insight", null],
+ [undefined, null],
+ ])("reads comment scope %s as %s", (scope, expected) => {
+ expect(commentScopeFromWire(scope)).toBe(expected);
+ });
+
it("creates and resolves a verified positional anchor", () => {
const text = "Before selected words after";
const anchor = createTextCommentAnchor(text, 7, 21);
diff --git a/products/desktop/packages/core/src/comments/anchors.ts b/products/desktop/packages/core/src/comments/anchors.ts
index ff3458986a00..21cd5648108d 100644
--- a/products/desktop/packages/core/src/comments/anchors.ts
+++ b/products/desktop/packages/core/src/comments/anchors.ts
@@ -1,4 +1,7 @@
-import type { CommentScope } from "@posthog/api-client/posthog-client";
+import {
+ COMMENT_SCOPES,
+ type CommentScope,
+} from "@posthog/api-client/posthog-client";
import { z } from "zod";
const CONTEXT_LENGTH = 32;
@@ -14,6 +17,13 @@ export type CommentTarget = {
itemId: string;
};
+export function commentScopeFromWire(
+ scope: string | null | undefined,
+): CommentScope | null {
+ const canonical = scope === "desktop_canvas" ? "canvas" : scope;
+ return COMMENT_SCOPES.find((known) => known === canonical) ?? null;
+}
+
/** The target as one string, for map keys and cache-key membership tests. */
export function commentTargetKey(target: CommentTarget): string {
return `${target.scope}:${target.itemId}`;
diff --git a/products/desktop/packages/core/src/links/task-link.test.ts b/products/desktop/packages/core/src/links/task-link.test.ts
index 53a5d643d358..70f9f5a1ed12 100644
--- a/products/desktop/packages/core/src/links/task-link.test.ts
+++ b/products/desktop/packages/core/src/links/task-link.test.ts
@@ -109,8 +109,8 @@ describe("TaskLinkService", () => {
it.each([
[
"with target params",
- "comment=thread-1&scope=desktop_canvas&item=canvas-9",
- { threadId: "thread-1", scope: "desktop_canvas", itemId: "canvas-9" },
+ "comment=thread-1&scope=canvas&item=canvas-9",
+ { threadId: "thread-1", scope: "canvas", itemId: "canvas-9" },
],
[
"bare",
diff --git a/products/desktop/packages/shared/src/domain-types.ts b/products/desktop/packages/shared/src/domain-types.ts
index 32009619ec85..9d715d54d0d0 100644
--- a/products/desktop/packages/shared/src/domain-types.ts
+++ b/products/desktop/packages/shared/src/domain-types.ts
@@ -276,7 +276,7 @@ export type TaskActivityKind =
*/
export interface TaskActivity {
id: string;
- task_id: string;
+ task_id: string | null;
task_title: string;
channel_id?: string | null;
channel_name?: string | null;
@@ -300,7 +300,7 @@ export interface TaskActivityPage {
}
export interface TaskActivityReadMarker {
- task_id: string;
+ task_id: string | null;
seen_before: string;
activity_id?: string;
}
diff --git a/products/desktop/packages/shared/src/feature-flag-keys.json b/products/desktop/packages/shared/src/feature-flag-keys.json
index 74d2f456118d..951aa1312a77 100644
--- a/products/desktop/packages/shared/src/feature-flag-keys.json
+++ b/products/desktop/packages/shared/src/feature-flag-keys.json
@@ -4,6 +4,7 @@
"BACKGROUND_AGENT_LOGS_FLAG": "posthog-code-background-agent-logs",
"BEDROCK_LLM_GATEWAY_FLAG": "bedrock-llm-gateway",
"BILLING_FLAG": "posthog-code-billing",
+ "CANVAS_COMMENTS_FLAG": "posthog-desktop-canvas-comments",
"CHANNEL_REPORTS_FLAG": "posthog-desktop-channel-reports",
"CHANNELS_LAYOUT_FLAG": "code-spaces-layout",
"CLAUDE_OWN_SUBSCRIPTION_FLAG": "posthog-code-claude-own-subscription",
diff --git a/products/desktop/packages/shared/src/flags.ts b/products/desktop/packages/shared/src/flags.ts
index e0476543643b..1a1e5da0f253 100644
--- a/products/desktop/packages/shared/src/flags.ts
+++ b/products/desktop/packages/shared/src/flags.ts
@@ -13,6 +13,7 @@ export const ONBOARDING_TEST_TOOLS_FLAG =
// Gates the entire canvas feature: the app rail's Channels space, the /website
// routes, channels and dashboards.
export const PROJECT_BLUEBIRD_FLAG = featureFlagKeys.PROJECT_BLUEBIRD_FLAG;
+export const CANVAS_COMMENTS_FLAG = featureFlagKeys.CANVAS_COMMENTS_FLAG;
/**
* Gates the new channels layout (channel-scoped sidebar + task Activity panel).
* Off keeps the previous experience and its "Enable channels" toggle. Requires
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityRow.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityRow.test.tsx
index f863a4871d5d..f1930e762740 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityRow.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityRow.test.tsx
@@ -39,9 +39,12 @@ vi.mock("@posthog/ui/features/canvas/utils/copyChannelLink", () => ({
copyChannelLink: links.copyChannelLink,
}));
-import { useCommentNavigationStore } from "@posthog/ui/features/sessions/commentNavigationStore";
+import {
+ canvasCommentFocusKey,
+ useCommentNavigationStore,
+} from "@posthog/ui/features/sessions/commentNavigationStore";
import { ActivityRow } from "./ActivityRow";
-import { openActivityItem } from "./openActivityItem";
+import { openActivityItem, openActivityItemInRail } from "./openActivityItem";
import type { TaskRowMenuProps } from "./TaskRowMenu";
function item(overrides: Partial<TaskActivityItem>): TaskActivityItem {
@@ -215,48 +218,74 @@ describe("ActivityRow", () => {
expect(onArchive).toHaveBeenCalledOnce();
});
- it("opens an activity mention at its exact comment thread", () => {
- const activity = item({
- activityKind: "mention",
- channelId: "channel-1",
- commentId: "comment-1",
- commentTarget: { scope: "desktop_canvas", itemId: "canvas-1" },
- author: {
- id: 2,
- uuid: "author",
- email: "[email protected]",
- first_name: "Ann",
- },
- });
+ it.each([
+ [
+ "the feed",
+ openActivityItem,
+ "task-1",
+ canvasCommentFocusKey("canvas-1"),
+ true,
+ ],
+ ["the rail", openActivityItemInRail, "task-1", "task-1", false],
+ [
+ "the rail without a task",
+ openActivityItemInRail,
+ null,
+ canvasCommentFocusKey("canvas-1"),
+ true,
+ ],
+ ])(
+ "opens an activity mention from %s at its exact comment thread",
+ (_where, activate, taskId, focusKey, opensCanvas) => {
+ const activity = item({
+ activityKind: "mention",
+ taskId,
+ channelId: "channel-1",
+ commentId: "comment-1",
+ commentTarget: { scope: "canvas", itemId: "canvas-1" },
+ author: {
+ id: 2,
+ uuid: "author",
+ email: "[email protected]",
+ first_name: "Ann",
+ },
+ });
- render(
- <ActivityRow
- item={activity}
- menu={taskMenu()}
- onMarkRead={vi.fn()}
- onActivate={openActivityItem}
- blockedTaskIds={NO_BLOCKED_TASKS}
- />,
- );
- const activityButton = screen
- .getByText("Ann mentioned you")
- .closest("button");
- if (!activityButton) throw new Error("Expected activity row button");
- fireEvent.click(activityButton);
+ render(
+ <ActivityRow
+ item={activity}
+ menu={taskMenu()}
+ onMarkRead={vi.fn()}
+ onActivate={activate}
+ blockedTaskIds={NO_BLOCKED_TASKS}
+ />,
+ );
+ const activityButton = screen
+ .getByText("Ann mentioned you")
+ .closest("button");
+ if (!activityButton) throw new Error("Expected activity row button");
+ fireEvent.click(activityButton);
- expect(navigation.toChannelDashboard).toHaveBeenCalledWith(
- "channel-1",
- "canvas-1",
- );
- expect(navigation.toChannelTask).not.toHaveBeenCalled();
- expect(useCommentNavigationStore.getState().focusByTask["task-1"]).toEqual({
- target: { scope: "desktop_canvas", itemId: "canvas-1" },
- threadId: "comment-1",
- nonce: expect.any(Number),
- openCommentsTab: true,
- intent: "navigate",
- });
- });
+ if (opensCanvas) {
+ expect(navigation.toChannelDashboard).toHaveBeenCalledWith(
+ "channel-1",
+ "canvas-1",
+ );
+ } else {
+ expect(navigation.toChannelDashboard).not.toHaveBeenCalled();
+ }
+ expect(navigation.toChannelTask).not.toHaveBeenCalled();
+ expect(
+ useCommentNavigationStore.getState().focusByTask[focusKey],
+ ).toEqual({
+ target: { scope: "canvas", itemId: "canvas-1" },
+ threadId: "comment-1",
+ nonce: expect.any(Number),
+ openCommentsTab: true,
+ intent: "navigate",
+ });
+ },
+ );
it("copies a canvas link, not a task link, for a canvas comment row", () => {
render(
@@ -264,7 +293,7 @@ describe("ActivityRow", () => {
item={item({
channelId: "channel-1",
commentId: "comment-1",
- commentTarget: { scope: "desktop_canvas", itemId: "canvas-1" },
+ commentTarget: { scope: "canvas", itemId: "canvas-1" },
})}
menu={taskMenu()}
onMarkRead={vi.fn()}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityRow.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityRow.tsx
index fc5eaf56f24f..4da2fcdffb7b 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityRow.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityRow.tsx
@@ -25,7 +25,6 @@ import {
} from "@posthog/ui/features/canvas/components/TaskRowMenu";
import { copyCanvasLink } from "@posthog/ui/features/canvas/utils/copyCanvasLink";
import { copyChannelLink } from "@posthog/ui/features/canvas/utils/copyChannelLink";
-import { useCommentNavigationStore } from "@posthog/ui/features/sessions/commentNavigationStore";
import { track } from "@posthog/ui/shell/analytics";
import type { ReactElement } from "react";
@@ -88,7 +87,9 @@ export function ActivityRow({
// The event records a past prompt; only the live session says whether it
// still needs a reply after the row was created.
const awaitsReply =
- item.activityKind === "awaiting_input" && blockedTaskIds.has(item.taskId);
+ item.activityKind === "awaiting_input" &&
+ item.taskId !== null &&
+ blockedTaskIds.has(item.taskId);
const agentIconClassName = awaitsReply ? "text-(--blue-11)" : undefined;
const agentIconWrapperClassName =
item.isUnread && !awaitsReply
@@ -101,7 +102,7 @@ export function ActivityRow({
if (canvasId) {
void copyCanvasLink(channelId, canvasId, "activity");
} else {
- void copyChannelLink(channelId, "activity", item.taskId);
+ void copyChannelLink(channelId, "activity", item.taskId ?? undefined);
}
};
const actionCount = 1 + (item.isUnread ? 1 : 0) + (canCopyLink ? 1 : 0);
@@ -110,14 +111,9 @@ export function ActivityRow({
action_type: "open_task",
surface,
channel_id: channelId ?? undefined,
- task_id: item.taskId,
+ task_id: item.taskId ?? undefined,
});
onMarkRead(item);
- if (item.commentId && item.commentTarget) {
- useCommentNavigationStore
- .getState()
- .requestCommentFocus(item.taskId, item.commentTarget, item.commentId);
- }
onActivate(item);
};
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.tsx
index 4373d77694d4..aa2d27cdc65e 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.tsx
@@ -12,6 +12,7 @@ import {
type UserMessageLike,
} from "@posthog/core/canvas/activityTimeline";
import type { ThreadTimelineRow } from "@posthog/core/canvas/threadTimeline";
+import { commentScopeFromWire } from "@posthog/core/comments/anchors";
import { DEFAULT_TAB_IDS } from "@posthog/core/panels/panelConstants";
import { findTabInTree } from "@posthog/core/panels/panelTree";
import {
@@ -253,9 +254,7 @@ export function ActivityTimeline({
? { scope: "task", itemId: task.id }
: {
scope:
- thread.target.type === "canvas"
- ? "desktop_canvas"
- : "task_artifact",
+ thread.target.type === "canvas" ? "canvas" : "task_artifact",
itemId: thread.target.id,
},
thread.id,
@@ -279,14 +278,8 @@ export function ActivityTimeline({
const openCommentThread = (payload: CommentEventPayload) => {
if (!canOpenInPlace) return undefined;
- const scope = payload.scope;
- if (
- scope !== "task" &&
- scope !== "task_artifact" &&
- scope !== "desktop_canvas"
- ) {
- return undefined;
- }
+ const scope = commentScopeFromWire(payload.scope);
+ if (!scope) return undefined;
const itemId = scope === "task" ? task.id : payload.itemId;
if (!itemId) return undefined;
return () =>
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx
index abbe0ba93429..697723e8557e 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx
@@ -9,6 +9,7 @@ import { ChannelSidebar } from "@posthog/ui/features/canvas/components/ChannelSi
import { ChannelsFab } from "@posthog/ui/features/canvas/components/ChannelsFab";
import { ChannelsList } from "@posthog/ui/features/canvas/components/ChannelsList";
import { useChannelsSidebarStore } from "@posthog/ui/features/canvas/components/channelsSidebarStore";
+import { openActivityItemInRail } from "@posthog/ui/features/canvas/components/openActivityItem";
import { TaskFeedPane } from "@posthog/ui/features/canvas/components/TaskFeedPane";
import { WorkActivityColumn } from "@posthog/ui/features/canvas/components/work/WorkActivityColumn";
import { WorkColumn } from "@posthog/ui/features/canvas/components/work/WorkColumn";
@@ -25,7 +26,6 @@ import {
railPaneFoldsIntoWork,
} from "@posthog/ui/features/canvas/railPane";
import {
- selectActivityItem,
selectActivityReport,
useActivitySelection,
} from "@posthog/ui/features/canvas/stores/activityDetailStore";
@@ -361,7 +361,7 @@ function ChannelsSidebarImpl() {
workActivityOpen={workActivityOpen}
showsActivityDetail={showsActivityDetail}
selectedActivityId={selectedActivityId}
- onActivityActivate={selectActivityItem}
+ onActivityActivate={openActivityItemInRail}
onActivityReportActivate={selectActivityReport}
feedId={feedId}
channelId={presentedChannelId}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.test.tsx
index 3fc4e2c359e7..26957b656a8e 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.test.tsx
@@ -10,6 +10,9 @@ vi.mock("@posthog/ui/features/canvas/hooks/useChannelsLayout", () => ({
useChannelsLayout: () => false,
}));
vi.mock("@posthog/ui/shell/analytics", () => ({ track: vi.fn() }));
+vi.mock("@posthog/ui/features/feature-flags/useFeatureFlag", () => ({
+ useFeatureFlag: () => false,
+}));
vi.mock("@posthog/ui/features/canvas/hooks/useSelectedCanvasId", () => ({
useSelectedCanvasId: () => useSelectedCanvasId(),
}));
@@ -94,7 +97,7 @@ vi.mock("@posthog/ui/features/sessions/components/useComments", () => ({
content: "First",
item_id: "canvas-1",
item_context: { anchor: { kind: "document" } },
- scope: "desktop_canvas",
+ scope: "canvas",
source_comment: null,
completed_at: null,
},
@@ -104,7 +107,7 @@ vi.mock("@posthog/ui/features/sessions/components/useComments", () => ({
content: "Second",
item_id: "canvas-1",
item_context: { anchor: { kind: "document" } },
- scope: "desktop_canvas",
+ scope: "canvas",
source_comment: null,
completed_at: null,
},
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.tsx b/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.tsx
index 56b748942d64..9c2a584a0e94 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.tsx
@@ -33,6 +33,7 @@ import { CanvasFrameHost } from "@posthog/ui/features/canvas/freeform/CanvasFram
import { canvasCommentTaskId } from "@posthog/ui/features/canvas/freeform/canvasCommentTask";
import { useCanvasFrameStore } from "@posthog/ui/features/canvas/freeform/canvasFrameStore";
import { CANVAS_QUERY_KEY } from "@posthog/ui/features/canvas/freeform/freeformDataBridge";
+import { useCanvasCommentsEnabled } from "@posthog/ui/features/canvas/hooks/useCanvasCommentsEnabled";
import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";
import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";
import { useChannelTasks } from "@posthog/ui/features/canvas/hooks/useChannelTasks";
@@ -287,15 +288,16 @@ function CanvasBreadcrumb({
const openComments = useCanvasChatPanelStore((state) => state.openComments);
const name = dashboard?.name ?? "Canvas";
const commentTarget = {
- scope: "desktop_canvas" as const,
+ scope: "canvas" as const,
itemId: dashboardId,
};
const commentTaskId = canvasCommentTaskId(
dashboard?.generationTaskId,
versions,
);
+ const commentsEnabled = useCanvasCommentsEnabled(commentTaskId);
const comments = useCommentsQuery(
- commentTaskId ? commentTarget : null,
+ commentsEnabled ? commentTarget : null,
commentTaskId ?? "",
{ live: true },
);
@@ -321,7 +323,7 @@ function CanvasBreadcrumb({
}
trailing={
<>
- {commentTaskId && (
+ {commentsEnabled && (
<Button size="sm" variant="outline" onClick={openComments}>
<ChatCircleIcon />
Comments
diff --git a/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx
index 76fcdb089611..0b66ebc9c7c9 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx
@@ -13,6 +13,9 @@ const activityMocks = vi.hoisted(() => ({
} | null,
}));
+vi.mock("@posthog/ui/features/feature-flags/useFeatureFlag", () => ({
+ useFeatureFlag: () => false,
+}));
vi.mock("@posthog/ui/features/canvas/hooks/useWorkLayout", () => ({
useWorkLayout: () => false,
}));
diff --git a/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.test.tsx
index 4316d1dd84f9..50ecaf70231a 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.test.tsx
@@ -147,7 +147,10 @@ vi.mock("@posthog/ui/features/sessions/components/useComments", () => ({
},
}));
-import { useCommentNavigationStore } from "@posthog/ui/features/sessions/commentNavigationStore";
+import {
+ canvasCommentFocusKey,
+ useCommentNavigationStore,
+} from "@posthog/ui/features/sessions/commentNavigationStore";
import { TaskCommentsList } from "./TaskCommentsList";
const task = { id: "task-1", latest_run: null } as unknown as Task;
@@ -282,7 +285,7 @@ describe("TaskCommentsList", () => {
mocks.comments = [
comment({
item_id: "canvas-1",
- scope: "desktop_canvas",
+ scope: "canvas",
content: "Canvas feedback",
item_context: {
anchor: {
@@ -306,7 +309,7 @@ describe("TaskCommentsList", () => {
onlySource={{
kind: "canvas",
name: "Launch canvas",
- target: { scope: "desktop_canvas", itemId: "canvas-1" },
+ target: { scope: "canvas", itemId: "canvas-1" },
url: null,
}}
canvasVersionId="version-2"
@@ -316,7 +319,7 @@ describe("TaskCommentsList", () => {
);
expect(mocks.queriedTargets.at(-1)).toEqual([
- { scope: "desktop_canvas", itemId: "canvas-1" },
+ { scope: "canvas", itemId: "canvas-1" },
]);
expect(screen.getByText("Canvas feedback")).toBeInTheDocument();
expect(screen.getByText("important copy")).toBeInTheDocument();
@@ -326,7 +329,7 @@ describe("TaskCommentsList", () => {
expect(screen.queryByLabelText("Filter by source")).not.toBeInTheDocument();
expect(screen.queryByText("Launch canvas")).not.toBeInTheDocument();
expect(mocks.createdFor.at(-1)).toEqual({
- scope: "desktop_canvas",
+ scope: "canvas",
itemId: "canvas-1",
});
@@ -373,7 +376,7 @@ describe("TaskCommentsList", () => {
mocks.comments = [
comment({
item_id: "canvas-1",
- scope: "desktop_canvas",
+ scope: "canvas",
content: "Linked canvas feedback",
}),
];
@@ -396,10 +399,21 @@ describe("TaskCommentsList", () => {
);
expect(mocks.queriedTargets.at(-1)).toContainEqual({
- scope: "desktop_canvas",
+ scope: "canvas",
itemId: "canvas-1",
});
expect(screen.getByText("Linked canvas feedback")).toBeInTheDocument();
+
+ openThread("Linked canvas feedback");
+
+ expect(
+ useCommentNavigationStore.getState().focusByTask[
+ canvasCommentFocusKey("canvas-1")
+ ],
+ ).toMatchObject({
+ target: { scope: "canvas", itemId: "canvas-1" },
+ threadId: "comment-1",
+ });
});
// The tab is the one place to see every thread the task produced, so each row
@@ -503,7 +517,7 @@ describe("TaskCommentsList", () => {
mocks.comments = [
comment({
item_id: "canvas-1",
- scope: "desktop_canvas",
+ scope: "canvas",
content: "Historical canvas feedback",
item_context: {
anchor: { kind: "document" },
@@ -520,7 +534,7 @@ describe("TaskCommentsList", () => {
onlySource={{
kind: "canvas",
name: "Launch canvas",
- target: { scope: "desktop_canvas", itemId: "canvas-1" },
+ target: { scope: "canvas", itemId: "canvas-1" },
url: null,
}}
canvasVersionId="version-3"
@@ -532,8 +546,8 @@ describe("TaskCommentsList", () => {
useCommentNavigationStore
.getState()
.requestCommentFocus(
- "task-1",
- { scope: "desktop_canvas", itemId: "canvas-1" },
+ canvasCommentFocusKey("canvas-1"),
+ { scope: "canvas", itemId: "canvas-1" },
"comment-1",
);
});
diff --git a/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.tsx b/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.tsx
index af8dfdb143e6..76351ce46969 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.tsx
@@ -50,7 +50,10 @@ import {
type CommentResource,
commentAgentContext,
} from "@posthog/ui/features/sessions/commentAgentContext";
-import { useCommentNavigationStore } from "@posthog/ui/features/sessions/commentNavigationStore";
+import {
+ canvasCommentFocusKey,
+ useCommentNavigationStore,
+} from "@posthog/ui/features/sessions/commentNavigationStore";
import { CommentComposer } from "@posthog/ui/features/sessions/components/CommentComposer";
import { CommentThreadCard } from "@posthog/ui/features/sessions/components/CommentThreadCard";
import type { HighlightResolution } from "@posthog/ui/features/sessions/components/commentViewTypes";
@@ -165,7 +168,7 @@ function ResourceThreadRow({
thread: TaskCommentThread;
source: CommentSource;
root: ResourceComment;
- taskId: string;
+ taskId: string | null;
members: UserBasic[];
selected: boolean;
pulsing: boolean;
@@ -173,7 +176,7 @@ function ResourceThreadRow({
onOpen: () => void;
commentVersionLabel?: (versionId: string) => string | null;
}) {
- const createComment = useCreateComment(source.target, taskId);
+ const createComment = useCreateComment(source.target, taskId ?? undefined);
const setResolved = useSetCommentResolved(source.target);
const rootPending = isOptimisticComment(root);
@@ -204,8 +207,10 @@ function ResourceThreadRow({
onResolve={async (resolved) => {
await setResolved.mutateAsync({ root, resolved });
}}
- onSendReplyToAgent={(content) =>
- sendSourceCommentToAgent(taskId, source, root, content)
+ onSendReplyToAgent={
+ taskId
+ ? (content) => sendSourceCommentToAgent(taskId, source, root, content)
+ : undefined
}
/>
);
@@ -296,7 +301,7 @@ export function TaskCommentsList({
commentVersionLabel,
onCanvasCommentOpen,
}: {
- taskId: string;
+ taskId: string | null;
task?: Task;
timeline?: ThreadTimelineRow<TaskThreadMessage>[];
/** Restricts the pane to one resource known by its host, without relying on
@@ -306,14 +311,18 @@ export function TaskCommentsList({
commentVersionLabel?: (versionId: string) => string | null;
onCanvasCommentOpen?: (versionId: string | null) => void;
}) {
- const { runs } = useTaskRuns(onlySource ? undefined : taskId);
+ const taskKey = taskId ?? "";
+ const focusKey = onlySource ? commentTargetKey(onlySource.target) : taskKey;
+ const { runs } = useTaskRuns(onlySource ? undefined : (taskId ?? undefined));
const { members } = useOrgMembers();
const openArtifactTab = usePanelLayoutStore((state) => state.openArtifactTab);
- const activeArtifactId = useActiveArtifactId(taskId);
+ const activeArtifactId = useActiveArtifactId(taskKey);
const requestCommentFocus = useCommentNavigationStore(
(state) => state.requestCommentFocus,
);
- const focus = useCommentNavigationStore((state) => state.focusByTask[taskId]);
+ const focus = useCommentNavigationStore(
+ (state) => state.focusByTask[focusKey],
+ );
const resolutionsByTarget = useCommentNavigationStore(
(state) => state.resolutionsByTarget,
);
@@ -323,23 +332,23 @@ export function TaskCommentsList({
const [draft, setDraft] = useState("");
const threadListRef = useRef<HTMLDivElement>(null);
const sourceFilterTouched = useRef(false);
- const previousTaskId = useRef(taskId);
+ const previousFocusKey = useRef(focusKey);
useEffect(() => {
- if (previousTaskId.current === taskId) return;
- previousTaskId.current = taskId;
+ if (previousFocusKey.current === focusKey) return;
+ previousFocusKey.current = focusKey;
sourceFilterTouched.current = false;
setSourceFilter(ALL_SOURCES);
setDraft("");
- }, [taskId]);
+ }, [focusKey]);
const rows = useMemo(
() => (task ? buildRows(task, timeline ?? [], runs) : []),
[task, timeline, runs],
);
const sources = useMemo(
- () => (onlySource ? [onlySource] : commentSources(taskId, rows)),
- [taskId, rows, onlySource],
+ () => (onlySource ? [onlySource] : commentSources(taskKey, rows)),
+ [taskKey, rows, onlySource],
);
const targets = useMemo(
() =>
@@ -353,11 +362,11 @@ export function TaskCommentsList({
);
const singleSourceComments = useCommentsQuery(
onlySource?.target ?? null,
- taskId,
+ taskId ?? "",
);
const taskComments = useCommentsForTargetsQuery(
onlySource ? [] : targets,
- taskId,
+ taskKey,
{
live: true,
intervalMs: POLL_INTERVAL_MS,
@@ -409,9 +418,9 @@ export function TaskCommentsList({
prUrls.length,
]);
- const taskTarget = useMemo(() => taskCommentTarget(taskId), [taskId]);
+ const taskTarget = useMemo(() => taskCommentTarget(taskKey), [taskKey]);
const composerTarget = onlySource?.target ?? taskTarget;
- const createComment = useCreateComment(composerTarget, taskId);
+ const createComment = useCreateComment(composerTarget, taskId ?? undefined);
const threads = useMemo(() => {
const reviewByUrl = new Map(prReviews.byUrl);
@@ -505,42 +514,53 @@ export function TaskCommentsList({
(thread: TaskCommentThread, requestThreadFocus = true) => {
const origin = thread.origin;
if (origin.kind === "pr-review" || origin.kind === "pr-conversation") {
- openPrInReview(taskId, origin.prUrl);
+ openPrInReview(taskKey, origin.prUrl);
if (origin.kind === "pr-review") {
// The review pane scrolls by file; a specific comment is as close as it
// gets until it grows a per-thread target.
useReviewNavigationStore
.getState()
- .requestScrollToFile(taskId, origin.filePath);
+ .requestScrollToFile(taskKey, origin.filePath);
}
return;
}
const { source, root } = origin;
if (source.kind === "canvas") {
- if (requestThreadFocus) {
- requestCommentFocus(taskId, source.target, root.id);
- }
if (onCanvasCommentOpen) {
+ if (requestThreadFocus) {
+ requestCommentFocus(focusKey, source.target, root.id);
+ }
onCanvasCommentOpen(
readCommentContext(root)?.canvasVersionId ?? null,
);
return;
}
+ requestCommentFocus(
+ canvasCommentFocusKey(source.target.itemId),
+ source.target,
+ root.id,
+ );
canvasArtifactOpenHandler(source.url)?.();
return;
}
// A thread on the task itself has nowhere else to open because it lives here.
if (source.kind === "task" || !source.runId) return;
- openArtifactTab(taskId, {
+ openArtifactTab(taskKey, {
runId: source.runId,
artifactId: source.target.itemId,
name: source.name,
});
if (requestThreadFocus) {
- requestCommentFocus(taskId, source.target, root.id);
+ requestCommentFocus(focusKey, source.target, root.id);
}
},
- [onCanvasCommentOpen, openArtifactTab, requestCommentFocus, taskId],
+ [
+ onCanvasCommentOpen,
+ openArtifactTab,
+ requestCommentFocus,
+ focusKey,
+ taskKey,
+ ],
);
// A thread picked on the artifact itself has to surface here, even when a
@@ -549,12 +569,12 @@ export function TaskCommentsList({
const focusedThreadId = focus?.threadId ?? null;
const handledFocusRef = useRef<string | null>(null);
useEffect(() => {
- const focusKey = focus ? `${taskId}:${focus.nonce}` : null;
- if (!focus || handledFocusRef.current === focusKey) return;
+ const handledKey = focus ? `${focusKey}:${focus.nonce}` : null;
+ if (!focus || handledFocusRef.current === handledKey) return;
const focused = threads.find((thread) => thread.id === focus.threadId);
// The thread may still be loading, so wait rather than guess its filters.
if (!focused) return;
- handledFocusRef.current = focusKey;
+ handledFocusRef.current = handledKey;
setStateFilter(focused.resolved ? "resolved" : "open");
setSourceFilter((current) =>
current === ALL_SOURCES || current === focused.sourceKey
@@ -571,7 +591,7 @@ export function TaskCommentsList({
);
if (pane && thread) scrollThreadInPane(pane, thread);
});
- }, [focus, openThread, threads, taskId]);
+ }, [focus, openThread, threads, focusKey]);
// The pulse fades on its own; owning the timer in its own effect keeps it
// cleaned up on the next pulse or on unmount, without a stray ref.
useEffect(() => {
@@ -690,7 +710,7 @@ export function TaskCommentsList({
mentions,
});
setDraft("");
- requestCommentFocus(taskId, composerTarget, created.id, {
+ requestCommentFocus(focusKey, composerTarget, created.id, {
intent: "focus-only",
});
}}
@@ -699,17 +719,20 @@ export function TaskCommentsList({
rows={1}
disabled={createComment.isPending}
compact
- onSendToAgent={(content) =>
- sendSourceCommentToAgent(
- taskId,
- onlySource ?? {
- kind: "task",
- target: composerTarget,
- name: "This task",
- },
- null,
- content,
- )
+ onSendToAgent={
+ taskId
+ ? (content) =>
+ sendSourceCommentToAgent(
+ taskId,
+ onlySource ?? {
+ kind: "task",
+ target: composerTarget,
+ name: "This task",
+ },
+ null,
+ content,
+ )
+ : undefined
}
/>
</footer>
diff --git a/products/desktop/packages/ui/src/features/canvas/components/activityFeed.test.ts b/products/desktop/packages/ui/src/features/canvas/components/activityFeed.test.ts
index ac3d8ae5ab06..9bf418d239fd 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/activityFeed.test.ts
+++ b/products/desktop/packages/ui/src/features/canvas/components/activityFeed.test.ts
@@ -109,7 +109,7 @@ describe("activityFeed", () => {
const canvasActivity: TaskActivityItem = {
...activity("canvas", "task-2"),
- commentTarget: { scope: "desktop_canvas", itemId: "canvas-1" },
+ commentTarget: { scope: "canvas", itemId: "canvas-1" },
};
const content = deriveActivityFeedContent({
diff --git a/products/desktop/packages/ui/src/features/canvas/components/activityFeed.ts b/products/desktop/packages/ui/src/features/canvas/components/activityFeed.ts
index f90236fe66b2..c16a464a8175 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/activityFeed.ts
+++ b/products/desktop/packages/ui/src/features/canvas/components/activityFeed.ts
@@ -58,7 +58,9 @@ export function deriveActivityFeedContent({
// open, and the backend keeps counting the row as unread.
const shownItems = taskItems.filter(
(item) =>
- activityCanvasId(item) !== null || !archivedTaskIds.has(item.taskId),
+ activityCanvasId(item) !== null ||
+ item.taskId === null ||
+ !archivedTaskIds.has(item.taskId),
);
const visibleReports = unreadsOnly ? [] : reports;
const visibleTaskItems = mentionsIncluded
diff --git a/products/desktop/packages/ui/src/features/canvas/components/activityPresentation.test.ts b/products/desktop/packages/ui/src/features/canvas/components/activityPresentation.test.ts
index 1a35366ac973..fb28528432dc 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/activityPresentation.test.ts
+++ b/products/desktop/packages/ui/src/features/canvas/components/activityPresentation.test.ts
@@ -83,7 +83,7 @@ describe("activityPresentation", () => {
"canvas owner comment",
item({
activityKind: "owned_item_comment",
- commentTarget: { scope: "desktop_canvas", itemId: "canvas-1" },
+ commentTarget: { scope: "canvas", itemId: "canvas-1" },
author: AUTHOR,
}),
"just now · Ann commented on your canvas",
diff --git a/products/desktop/packages/ui/src/features/canvas/components/activityPresentation.ts b/products/desktop/packages/ui/src/features/canvas/components/activityPresentation.ts
index 2e66f9eecc2b..cef8dbab4c28 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/activityPresentation.ts
+++ b/products/desktop/packages/ui/src/features/canvas/components/activityPresentation.ts
@@ -24,7 +24,7 @@ interface ActivityEventPresentation {
function ownedItemName(item: TaskActivityItem): string {
switch (item.commentTarget?.scope) {
- case "desktop_canvas":
+ case "canvas":
return "canvas";
case "task_artifact":
return "artifact";
diff --git a/products/desktop/packages/ui/src/features/canvas/components/activityRows.tsx b/products/desktop/packages/ui/src/features/canvas/components/activityRows.tsx
index 286fa1631f83..e21e9d39d60f 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/activityRows.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/activityRows.tsx
@@ -21,7 +21,6 @@ import {
UserSwitchIcon,
XIcon,
} from "@phosphor-icons/react";
-import type { CommentScope } from "@posthog/api-client/posthog-client";
import {
type ActivityEvent,
type ArtifactPayload,
@@ -31,6 +30,7 @@ import {
prLabel,
} from "@posthog/core/canvas/activityEvents";
import type { GroupableActivityEvent } from "@posthog/core/canvas/activityGrouping";
+import { commentScopeFromWire } from "@posthog/core/comments/anchors";
import type { ChangedFile } from "@posthog/core/git/router-schemas";
import { xmlToContent } from "@posthog/core/message-editor/content";
import {
@@ -1086,12 +1086,6 @@ export function CommentEventRow({
);
}
-const COMMENT_EVENT_SCOPES: readonly string[] = [
- "task",
- "task_artifact",
- "desktop_canvas",
-];
-
function CommentEventDetail({
taskId,
payload,
@@ -1101,10 +1095,9 @@ function CommentEventDetail({
payload: CommentEventPayload;
onOpenThread?: () => void;
}) {
+ const scope = commentScopeFromWire(payload.scope);
const target =
- COMMENT_EVENT_SCOPES.includes(payload.scope) && payload.itemId
- ? { scope: payload.scope as CommentScope, itemId: payload.itemId }
- : null;
+ scope && payload.itemId ? { scope, itemId: payload.itemId } : null;
const { data, isLoading } = useCommentsQuery(target, taskId, {
live: false,
});
diff --git a/products/desktop/packages/ui/src/features/canvas/components/openActivityItem.ts b/products/desktop/packages/ui/src/features/canvas/components/openActivityItem.ts
index 00975b7213cb..cab40bc31769 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/openActivityItem.ts
+++ b/products/desktop/packages/ui/src/features/canvas/components/openActivityItem.ts
@@ -1,6 +1,11 @@
import type { TaskActivityItem } from "@posthog/core/canvas/taskActivity";
+import { selectActivityItem } from "@posthog/ui/features/canvas/stores/activityDetailStore";
import { useCanvasChatPanelStore } from "@posthog/ui/features/canvas/stores/canvasChatPanelStore";
import { useThreadPanelStore } from "@posthog/ui/features/canvas/stores/threadPanelStore";
+import {
+ canvasCommentFocusKey,
+ useCommentNavigationStore,
+} from "@posthog/ui/features/sessions/commentNavigationStore";
import {
navigateToChannelDashboard,
navigateToChannelTask,
@@ -9,14 +14,27 @@ import {
/** Where a feed row goes on a surface that navigates. The rail's docked feed
* reads its row in place instead, so the row hands activation out. */
+function focusActivityComment(item: TaskActivityItem, ownerKey: string): void {
+ if (!item.commentId || !item.commentTarget) return;
+ useCommentNavigationStore
+ .getState()
+ .requestCommentFocus(ownerKey, item.commentTarget, item.commentId);
+}
+
export function openActivityItem(item: TaskActivityItem): void {
const { channelId } = item;
- if (channelId && item.commentTarget?.scope === "desktop_canvas") {
+ if (channelId && item.commentTarget?.scope === "canvas") {
+ focusActivityComment(
+ item,
+ canvasCommentFocusKey(item.commentTarget.itemId),
+ );
useCanvasChatPanelStore.getState().openComments();
navigateToChannelDashboard(channelId, item.commentTarget.itemId);
return;
}
+ if (!item.taskId) return;
+ focusActivityComment(item, item.taskId);
// The channel thread route is the deep-link target; unfiled tasks fall back
// to the plain task view.
if (channelId) {
@@ -28,3 +46,12 @@ export function openActivityItem(item: TaskActivityItem): void {
}
navigateToTaskDetail(item.taskId);
}
+
+export function openActivityItemInRail(item: TaskActivityItem): void {
+ if (!item.taskId) {
+ openActivityItem(item);
+ return;
+ }
+ focusActivityComment(item, item.taskId);
+ selectActivityItem(item);
+}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/taskArtifactRows.ts b/products/desktop/packages/ui/src/features/canvas/components/taskArtifactRows.ts
index 105b899c47bd..a0068a657a21 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/taskArtifactRows.ts
+++ b/products/desktop/packages/ui/src/features/canvas/components/taskArtifactRows.ts
@@ -137,7 +137,7 @@ function targetForRow(row: ArtifactRow): CommentTarget | null {
return { scope: "task_artifact", itemId: row.artifactId };
}
if (row.kind === "canvas" && row.dashboardId) {
- return { scope: "desktop_canvas", itemId: row.dashboardId };
+ return { scope: "canvas", itemId: row.dashboardId };
}
return null;
}
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSelectionCommentAction.test.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSelectionCommentAction.test.tsx
index 4370f006d48b..189f8998d4bc 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSelectionCommentAction.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSelectionCommentAction.test.tsx
@@ -1,5 +1,8 @@
import { useCanvasChatPanelStore } from "@posthog/ui/features/canvas/stores/canvasChatPanelStore";
-import { useCommentNavigationStore } from "@posthog/ui/features/sessions/commentNavigationStore";
+import {
+ canvasCommentFocusKey,
+ useCommentNavigationStore,
+} from "@posthog/ui/features/sessions/commentNavigationStore";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { CanvasSelectionCommentAction } from "./CanvasSelectionCommentAction";
@@ -48,54 +51,59 @@ describe("CanvasSelectionCommentAction", () => {
});
});
- it("creates the text-anchored comment and opens the comments tab", async () => {
- mutateAsync.mockResolvedValue({ id: "comment-1" });
- render(
- <CanvasSelectionCommentAction
- selection={{
- quote: "selected text",
- prefix: "before ",
- suffix: " after",
- start: 7,
- end: 20,
- rect: { top: 10, right: 80, bottom: 30, left: 20 },
- }}
- taskId="task-1"
- dashboardId="canvas-1"
- canvasName="Launch canvas"
- versionId="version-2"
- onDismiss={vi.fn()}
- />,
- );
+ it.each([["task-1"], [null]])(
+ "creates the text-anchored comment and opens the comments tab with task %s",
+ async (taskId) => {
+ mutateAsync.mockResolvedValue({ id: "comment-1" });
+ render(
+ <CanvasSelectionCommentAction
+ selection={{
+ quote: "selected text",
+ prefix: "before ",
+ suffix: " after",
+ start: 7,
+ end: 20,
+ rect: { top: 10, right: 80, bottom: 30, left: 20 },
+ }}
+ taskId={taskId}
+ dashboardId="canvas-1"
+ canvasName="Launch canvas"
+ versionId="version-2"
+ onDismiss={vi.fn()}
+ />,
+ );
- fireEvent.click(screen.getByText("Submit selection comment"));
+ fireEvent.click(screen.getByText("Submit selection comment"));
- expect(useCanvasChatPanelStore.getState()).toMatchObject({
- collapsed: false,
- tab: "comments",
- });
- expect(mutateAsync).toHaveBeenCalledWith({
- content: "Please revise this",
- context: {
- anchor: {
- kind: "text",
- quote: "selected text",
- prefix: "before ",
- suffix: " after",
- start: 7,
- end: 20,
+ expect(useCanvasChatPanelStore.getState()).toMatchObject({
+ collapsed: false,
+ tab: "comments",
+ });
+ expect(mutateAsync).toHaveBeenCalledWith({
+ content: "Please revise this",
+ context: {
+ anchor: {
+ kind: "text",
+ quote: "selected text",
+ prefix: "before ",
+ suffix: " after",
+ start: 7,
+ end: 20,
+ },
+ canvasVersionId: "version-2",
},
- canvasVersionId: "version-2",
- },
- mentions: [4],
- });
- await waitFor(() =>
- expect(
- useCommentNavigationStore.getState().focusByTask["task-1"],
- ).toMatchObject({
- threadId: "comment-1",
- intent: "focus-only",
- }),
- );
- });
+ mentions: [4],
+ });
+ await waitFor(() =>
+ expect(
+ useCommentNavigationStore.getState().focusByTask[
+ canvasCommentFocusKey("canvas-1")
+ ],
+ ).toMatchObject({
+ threadId: "comment-1",
+ intent: "focus-only",
+ }),
+ );
+ },
+ );
});
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSelectionCommentAction.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSelectionCommentAction.tsx
index f8dd7c9937d1..fd408e35bc3d 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSelectionCommentAction.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSelectionCommentAction.tsx
@@ -6,7 +6,10 @@ import {
commentAgentContext,
withScreenshot,
} from "@posthog/ui/features/sessions/commentAgentContext";
-import { useCommentNavigationStore } from "@posthog/ui/features/sessions/commentNavigationStore";
+import {
+ canvasCommentFocusKey,
+ useCommentNavigationStore,
+} from "@posthog/ui/features/sessions/commentNavigationStore";
import { useCreateComment } from "@posthog/ui/features/sessions/components/useComments";
import { sendCommentToAgent } from "@posthog/ui/features/sessions/sendCommentToAgent";
import type { HostCanvasTextSelection } from "./canvasSelection";
@@ -28,7 +31,7 @@ export function CanvasSelectionCommentAction({
}) {
const { members } = useOrgMembers();
const openComments = useCanvasChatPanelStore((state) => state.openComments);
- const target = { scope: "desktop_canvas" as const, itemId: dashboardId };
+ const target = { scope: "canvas" as const, itemId: dashboardId };
const createComment = useCreateComment(target, taskId ?? undefined);
const anchor: TextCommentAnchor | null = selection
@@ -59,7 +62,7 @@ export function CanvasSelectionCommentAction({
}
: null
}
- open={!!selection && !!taskId}
+ open={!!selection}
filePath={canvasName}
actionLabel="Add comment"
placeholder="Add a comment about this selection"
@@ -84,7 +87,7 @@ export function CanvasSelectionCommentAction({
: undefined
}
onSubmit={async (_start, _end, content, mentions) => {
- if (!anchor || !taskId) return;
+ if (!anchor) return;
openComments();
const comment = await createComment.mutateAsync({
content,
@@ -96,9 +99,14 @@ export function CanvasSelectionCommentAction({
});
useCommentNavigationStore
.getState()
- .requestCommentFocus(taskId, target, comment.id, {
- intent: "focus-only",
- });
+ .requestCommentFocus(
+ canvasCommentFocusKey(dashboardId),
+ target,
+ comment.id,
+ {
+ intent: "focus-only",
+ },
+ );
}}
/>
);
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx
index 4adba608a2a9..921698f80c9b 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx
@@ -16,7 +16,7 @@ vi.mock("@posthog/ui/features/canvas/components/TaskCommentsList", () => ({
taskId,
onlySource,
}: {
- taskId: string;
+ taskId: string | null;
onlySource: { target: { itemId: string } };
}) => (
<div data-testid="task-comments">
@@ -42,6 +42,7 @@ describe("CanvasSidePanel", () => {
<CanvasSidePanel
chatTaskId="task-1"
commentTaskId="task-1"
+ commentsEnabled
onMinimize={vi.fn()}
dashboardId="canvas-1"
channelId="channel-1"
@@ -66,6 +67,7 @@ describe("CanvasSidePanel", () => {
useCanvasChatPanelStore.setState({ tab: "comments", collapsed: false });
const props = {
commentTaskId: "task-1",
+ commentsEnabled: true,
interactive,
onMinimize: vi.fn(),
dashboardId: "canvas-1",
@@ -94,14 +96,18 @@ describe("CanvasSidePanel", () => {
}
});
- it("opens comments when the generating run is not readable", () => {
+ it.each([
+ ["the generating run is not readable", "task-1", "task-1:canvas-1"],
+ ["no task backs the canvas", null, ":canvas-1"],
+ ])("opens comments when %s", (_name, commentTaskId, expected) => {
mocks.task = undefined;
useCanvasChatPanelStore.setState({ tab: "comments", collapsed: false });
render(
<CanvasSidePanel
chatTaskId={null}
- commentTaskId="task-1"
+ commentTaskId={commentTaskId}
+ commentsEnabled
onMinimize={vi.fn()}
dashboardId="canvas-1"
channelId="channel-1"
@@ -115,8 +121,38 @@ describe("CanvasSidePanel", () => {
/>,
);
- expect(screen.getByTestId("task-comments")).toHaveTextContent(
- "task-1:canvas-1",
+ expect(screen.getByLabelText("Comments")).not.toHaveAttribute(
+ "aria-disabled",
+ "true",
+ );
+ expect(screen.getByTestId("task-comments")).toHaveTextContent(expected);
+ });
+
+ it("disables comments when they are off for the canvas", () => {
+ useCanvasChatPanelStore.setState({ tab: "comments", collapsed: false });
+
+ render(
+ <CanvasSidePanel
+ chatTaskId="task-1"
+ commentTaskId={null}
+ commentsEnabled={false}
+ onMinimize={vi.fn()}
+ dashboardId="canvas-1"
+ channelId="channel-1"
+ channelName="General"
+ name="Launch canvas"
+ displayedVersionId="version-2"
+ liveVersionId="version-2"
+ onAskAgent={vi.fn()}
+ commentVersionLabel={(versionId) => versionId}
+ onCommentOpen={vi.fn()}
+ />,
+ );
+
+ expect(screen.getByLabelText("Comments")).toHaveAttribute(
+ "aria-disabled",
+ "true",
);
+ expect(screen.queryByTestId("task-comments")).not.toBeInTheDocument();
});
});
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx
index db22a27e3d0a..49d34d498fdc 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx
@@ -90,6 +90,7 @@ function PanelTabButton({
export function CanvasSidePanel({
chatTaskId,
commentTaskId,
+ commentsEnabled,
interactive,
onMinimize,
dashboardId,
@@ -111,6 +112,7 @@ export function CanvasSidePanel({
* here, even while it is in flight. */
chatTaskId: string | null;
commentTaskId: string | null;
+ commentsEnabled: boolean;
/** Whether the canvas is being edited. The composer is an edit affordance, so
* view mode shows an empty chat when this person has no run. */
interactive?: boolean;
@@ -162,7 +164,7 @@ export function CanvasSidePanel({
tab={option}
active={visibleTab === option}
disabled={
- (option === "comments" && !commentTaskId) ||
+ (option === "comments" && !commentsEnabled) ||
(option === "blocks" && firstBuildRunning)
}
onSelect={setTab}
@@ -205,7 +207,7 @@ export function CanvasSidePanel({
versionLabel={commentVersionLabel}
onOpen={onCommentOpen}
/>
- ) : visibleTab === "comments" && commentTaskId ? (
+ ) : visibleTab === "comments" && commentsEnabled ? (
<CanvasComments
taskId={commentTaskId}
dashboardId={dashboardId}
@@ -269,7 +271,7 @@ function CanvasComments({
commentVersionLabel,
onCommentOpen,
}: {
- taskId: string;
+ taskId: string | null;
dashboardId: string;
name: string;
displayedVersionId: string | null;
@@ -282,7 +284,7 @@ function CanvasComments({
onlySource={{
kind: "canvas",
name,
- target: { scope: "desktop_canvas", itemId: dashboardId },
+ target: { scope: "canvas", itemId: dashboardId },
url: null,
}}
canvasVersionId={displayedVersionId}
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx
index aa312888f73e..53fba32f880b 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx
@@ -67,6 +67,7 @@ import {
} from "@posthog/ui/features/canvas/freeform/canvasGenerationStatus";
import { invalidateCanvasLifecycle } from "@posthog/ui/features/canvas/hooks/invalidateCanvasLifecycle";
import { useCanvasBuilds } from "@posthog/ui/features/canvas/hooks/useCanvasBuilds";
+import { useCanvasCommentsEnabled } from "@posthog/ui/features/canvas/hooks/useCanvasCommentsEnabled";
import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";
import {
useCanvasDrafts,
@@ -83,7 +84,10 @@ import {
} from "@posthog/ui/features/canvas/stores/freeformChatStore";
import { useDraftStore } from "@posthog/ui/features/message-editor/draftStore";
import type { EditorHandle } from "@posthog/ui/features/message-editor/types";
-import { useCommentNavigationStore } from "@posthog/ui/features/sessions/commentNavigationStore";
+import {
+ canvasCommentFocusKey,
+ useCommentNavigationStore,
+} from "@posthog/ui/features/sessions/commentNavigationStore";
import {
buildCommentThreads,
readCommentContext,
@@ -352,6 +356,7 @@ export function FreeformCanvasView({
interactive ? dashboardId : undefined,
);
const commentTaskId = canvasCommentTaskId(genTaskId, versions);
+ const commentsEnabled = useCanvasCommentsEnabled(commentTaskId);
// The run whose chat the panel shows: this person's own run on the canvas,
// found through the record's task or the versions they published. Another
// person's run never shows, so each editor keeps their own conversation.
@@ -526,27 +531,31 @@ export function FreeformCanvasView({
? browseVersionId
: (publishedBuild?.sourceVersionId ?? headVersionId);
const commentTarget = useMemo(
- () => ({ scope: "desktop_canvas" as const, itemId: dashboardId }),
+ () => ({ scope: "canvas" as const, itemId: dashboardId }),
[dashboardId],
);
const commentsQuery = useCommentsQuery(
- commentTaskId ? commentTarget : null,
+ commentsEnabled ? commentTarget : null,
commentTaskId ?? "",
);
const focusedCommentId = useCommentNavigationStore(
- (state) => state.focusByTask[commentTaskId ?? ""]?.threadId ?? null,
+ (state) =>
+ state.focusByTask[canvasCommentFocusKey(dashboardId)]?.threadId ?? null,
);
const activateComment = useCallback(
(id: string) => {
- if (!commentTaskId) return;
+ if (!commentsEnabled) return;
useCanvasChatPanelStore.getState().openComments();
useCommentNavigationStore
.getState()
- .requestCommentFocus(commentTaskId, commentTarget, id, {
- intent: "reveal-thread",
- });
+ .requestCommentFocus(
+ canvasCommentFocusKey(dashboardId),
+ commentTarget,
+ id,
+ { intent: "reveal-thread" },
+ );
},
- [commentTaskId, commentTarget],
+ [commentsEnabled, commentTarget, dashboardId],
);
const commentHighlights = useMemo<CanvasCommentHighlight[]>(() => {
const threads = buildCommentThreads(commentsQuery.data ?? []);
@@ -853,7 +862,7 @@ export function FreeformCanvasView({
generatingPanelOpen,
viewOpen: embedded ? false : panelViewOpen,
collapsed,
- hasCommentTask: !!commentTaskId,
+ commentsEnabled,
});
const showPanel = panelVisibility.editing;
// Build failures/progress surface in view mode too — the toolbar renders
@@ -1349,6 +1358,7 @@ export function FreeformCanvasView({
<CanvasSidePanel
chatTaskId={chatTaskId}
commentTaskId={commentTaskId}
+ commentsEnabled={commentsEnabled}
interactive={interactive}
onMinimize={() => {
setCollapsed(true);
@@ -1376,7 +1386,7 @@ export function FreeformCanvasView({
</ResizableSidebar>
)}
- {!embedded && (
+ {!embedded && commentsEnabled && (
<CanvasSelectionCommentAction
selection={textSelection}
taskId={commentTaskId}
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.test.ts b/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.test.ts
index 29a127b1e7ad..9d90923b2848 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.test.ts
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.test.ts
@@ -8,7 +8,7 @@ const base = {
generatingPanelOpen: false,
viewOpen: false,
collapsed: false,
- hasCommentTask: true,
+ commentsEnabled: true,
};
describe("canvasSidePanelVisibility", () => {
@@ -40,8 +40,8 @@ describe("canvasSidePanelVisibility", () => {
false,
],
[
- "viewing a canvas no task backs",
- { viewOpen: true, hasCommentTask: false },
+ "viewing a canvas with comments off",
+ { viewOpen: true, commentsEnabled: false },
false,
false,
],
diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.ts b/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.ts
index f38a1a922bdb..69308b8fde87 100644
--- a/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.ts
+++ b/products/desktop/packages/ui/src/features/canvas/freeform/canvasSidePanelVisibility.ts
@@ -25,13 +25,13 @@ export function canvasSidePanelVisibility(args: {
viewOpen: boolean;
/** Whether the dock is minimized to the rail. */
collapsed: boolean;
- /** Whether a task backs this canvas's comments and agent chat. */
- hasCommentTask: boolean;
+ /** Whether this canvas's comments are available. */
+ commentsEnabled: boolean;
}): CanvasSidePanelVisibility {
return {
editing:
(args.interactive && (args.hasContent || args.hasActiveTask)) ||
args.generatingPanelOpen,
- viewing: args.viewOpen && !args.collapsed && args.hasCommentTask,
+ viewing: args.viewOpen && !args.collapsed && args.commentsEnabled,
};
}
diff --git a/products/desktop/packages/ui/src/features/canvas/grid/GridCanvasView.tsx b/products/desktop/packages/ui/src/features/canvas/grid/GridCanvasView.tsx
index e66426b0f363..0a15b9ceb94b 100644
--- a/products/desktop/packages/ui/src/features/canvas/grid/GridCanvasView.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/grid/GridCanvasView.tsx
@@ -5,6 +5,7 @@ import type {
} from "@posthog/core/canvas/gridLayoutSchemas";
import { Button, Text } from "@posthog/quill";
import { canvasCommentTaskId } from "@posthog/ui/features/canvas/freeform/canvasCommentTask";
+import { useCanvasCommentsEnabled } from "@posthog/ui/features/canvas/hooks/useCanvasCommentsEnabled";
import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";
import {
useCanvasVersions,
@@ -73,6 +74,11 @@ export function GridCanvasView({
// The layout version the grid is on, in the freeform toolbar's vocabulary.
const { versions } = useCanvasVersions(canvasId);
+ const commentTaskId = canvasCommentTaskId(
+ dashboard?.generationTaskId ?? startedCanvasTaskId,
+ versions,
+ );
+ const commentsEnabled = useCanvasCommentsEnabled(commentTaskId);
const versionText = useMemo(() => {
if (!currentVersionId || versions.length === 0) return null;
const index = versions.findIndex(
@@ -254,10 +260,8 @@ export function GridCanvasView({
<GridChatPanel
target={widgetTarget}
canvasTaskId={dashboard.generationTaskId ?? startedCanvasTaskId}
- commentTaskId={canvasCommentTaskId(
- dashboard.generationTaskId ?? startedCanvasTaskId,
- versions,
- )}
+ commentTaskId={commentTaskId}
+ commentsEnabled={commentsEnabled}
canvasVersionId={currentVersionId ?? null}
commentVersionLabel={commentVersionLabel}
canvasId={canvasId}
diff --git a/products/desktop/packages/ui/src/features/canvas/grid/GridChatPanel.tsx b/products/desktop/packages/ui/src/features/canvas/grid/GridChatPanel.tsx
index 60163890a2a2..c74635203def 100644
--- a/products/desktop/packages/ui/src/features/canvas/grid/GridChatPanel.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/grid/GridChatPanel.tsx
@@ -34,6 +34,7 @@ export function GridChatPanel({
target,
canvasTaskId,
commentTaskId,
+ commentsEnabled,
canvasVersionId,
commentVersionLabel,
canvasId,
@@ -49,8 +50,9 @@ export function GridChatPanel({
/** The recorded canvas-wide conversation, if one has been started. */
canvasTaskId: string | null;
/** The task canvas comments anchor to (the canvas conversation, or the run
- * that produced the current layout). Null disables the comments tab. */
+ * that produced the current layout). */
commentTaskId: string | null;
+ commentsEnabled: boolean;
/** The layout version currently shown, for labeling new comments. */
canvasVersionId: string | null;
commentVersionLabel: (versionId: string) => string | null;
@@ -118,7 +120,7 @@ export function GridChatPanel({
</TabsTrigger>
<TabsTrigger
value="comments"
- disabled={!commentTaskId}
+ disabled={!commentsEnabled}
className="px-2.5"
>
Comments
@@ -126,7 +128,7 @@ export function GridChatPanel({
</TabsList>
</Tabs>
</ChromeBar>
- {tab === "comments" && commentTaskId ? (
+ {tab === "comments" && commentsEnabled ? (
<CanvasComments
taskId={commentTaskId}
canvasId={canvasId}
@@ -175,7 +177,7 @@ function CanvasComments({
canvasVersionId,
commentVersionLabel,
}: {
- taskId: string;
+ taskId: string | null;
canvasId: string;
canvasName: string;
canvasVersionId: string | null;
@@ -188,7 +190,7 @@ function CanvasComments({
onlySource={{
kind: "canvas",
name: canvasName,
- target: { scope: "desktop_canvas", itemId: canvasId },
+ target: { scope: "canvas", itemId: canvasId },
url: null,
}}
canvasVersionId={canvasVersionId}
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useActivityTaskMenu.test.tsx b/products/desktop/packages/ui/src/features/canvas/hooks/useActivityTaskMenu.test.tsx
index 67aefc9d46d5..bd0e40ff4331 100644
--- a/products/desktop/packages/ui/src/features/canvas/hooks/useActivityTaskMenu.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useActivityTaskMenu.test.tsx
@@ -58,7 +58,7 @@ describe("useActivityTaskMenu", () => {
item({
taskTitle: "Launch canvas",
commentId: "comment-1",
- commentTarget: { scope: "desktop_canvas", itemId: "canvas-1" },
+ commentTarget: { scope: "canvas", itemId: "canvas-1" },
}),
);
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useActivityTaskMenu.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useActivityTaskMenu.ts
index bcab79597000..d431d0fd5401 100644
--- a/products/desktop/packages/ui/src/features/canvas/hooks/useActivityTaskMenu.ts
+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useActivityTaskMenu.ts
@@ -66,23 +66,24 @@ export function useActivityTaskMenu(): (
},
};
}
+ const taskId = item.taskId ?? "";
return {
kind: "task",
- id: item.taskId,
+ id: taskId,
title: item.taskTitle,
- isPinned: pinnedTaskIds.has(item.taskId),
+ isPinned: pinnedTaskIds.has(taskId),
// Ticks the space the task is already filed to, inside "File to…".
channelId: item.channelId ?? undefined,
- onAddToCommandCenter: cells.includes(item.taskId)
+ onAddToCommandCenter: cells.includes(taskId)
? undefined
- : () => placeTaskInCommandCenter(item.taskId, item.taskTitle),
+ : () => placeTaskInCommandCenter(taskId, item.taskTitle),
onTogglePin: () => {
- togglePin(item.taskId).catch(() => {
+ togglePin(taskId).catch(() => {
toast.error("Couldn't update pin");
});
},
onArchive: () => {
- archiveRef.current({ taskId: item.taskId }).catch(() => {
+ archiveRef.current({ taskId }).catch(() => {
toast.error("Couldn't archive task");
});
},
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useCanvasCommentsEnabled.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useCanvasCommentsEnabled.ts
new file mode 100644
index 000000000000..7b6e157bb1bb
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useCanvasCommentsEnabled.ts
@@ -0,0 +1,8 @@
+import { CANVAS_COMMENTS_FLAG } from "@posthog/shared";
+import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
+
+export function useCanvasCommentsEnabled(
+ commentTaskId: string | null,
+): boolean {
+ return useFeatureFlag(CANVAS_COMMENTS_FLAG) || !!commentTaskId;
+}
diff --git a/products/desktop/packages/ui/src/features/canvas/stores/activityDetailStore.ts b/products/desktop/packages/ui/src/features/canvas/stores/activityDetailStore.ts
index c84ff08909a2..57737cbeb239 100644
--- a/products/desktop/packages/ui/src/features/canvas/stores/activityDetailStore.ts
+++ b/products/desktop/packages/ui/src/features/canvas/stores/activityDetailStore.ts
@@ -110,7 +110,7 @@ export function selectActivityItem(item: TaskActivityItem): void {
to: "/activity",
search: {
item: item.id,
- session: item.taskId,
+ session: item.taskId ?? undefined,
...(item.channelId ? { space: item.channelId } : {}),
},
});
diff --git a/products/desktop/packages/ui/src/features/deep-links/useHandleOpenTask.ts b/products/desktop/packages/ui/src/features/deep-links/useHandleOpenTask.ts
index bb7fb47ba03d..b9ac24f96c49 100644
--- a/products/desktop/packages/ui/src/features/deep-links/useHandleOpenTask.ts
+++ b/products/desktop/packages/ui/src/features/deep-links/useHandleOpenTask.ts
@@ -1,4 +1,7 @@
-import type { CommentTarget } from "@posthog/core/comments/anchors";
+import {
+ type CommentTarget,
+ commentScopeFromWire,
+} from "@posthog/core/comments/anchors";
import type { TaskLinkCommentAnchor } from "@posthog/core/links/task-link";
import {
TASK_SERVICE,
@@ -30,11 +33,9 @@ function commentTargetFromAnchor(
taskId: string,
anchor: TaskLinkCommentAnchor,
): CommentTarget {
- if (
- (anchor.scope === "desktop_canvas" || anchor.scope === "task_artifact") &&
- anchor.itemId
- ) {
- return { scope: anchor.scope, itemId: anchor.itemId };
+ const scope = commentScopeFromWire(anchor.scope);
+ if ((scope === "canvas" || scope === "task_artifact") && anchor.itemId) {
+ return { scope, itemId: anchor.itemId };
}
return { scope: "task", itemId: taskId };
}
diff --git a/products/desktop/packages/ui/src/features/sessions/commentNavigationStore.test.ts b/products/desktop/packages/ui/src/features/sessions/commentNavigationStore.test.ts
index 0dd2fa09e557..b86626d5125c 100644
--- a/products/desktop/packages/ui/src/features/sessions/commentNavigationStore.test.ts
+++ b/products/desktop/packages/ui/src/features/sessions/commentNavigationStore.test.ts
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it } from "vitest";
import { useCommentNavigationStore } from "./commentNavigationStore";
const artifact = { scope: "task_artifact", itemId: "a" } as const;
-const canvas = { scope: "desktop_canvas", itemId: "c" } as const;
+const canvas = { scope: "canvas", itemId: "c" } as const;
describe("commentNavigationStore", () => {
beforeEach(() => {
diff --git a/products/desktop/packages/ui/src/features/sessions/commentNavigationStore.ts b/products/desktop/packages/ui/src/features/sessions/commentNavigationStore.ts
index 493376033a3b..b42bad848b02 100644
--- a/products/desktop/packages/ui/src/features/sessions/commentNavigationStore.ts
+++ b/products/desktop/packages/ui/src/features/sessions/commentNavigationStore.ts
@@ -46,6 +46,10 @@ type CommentNavigationStore = CommentNavigationStoreState &
let nonce = 0;
+export function canvasCommentFocusKey(canvasId: string): string {
+ return commentTargetKey({ scope: "canvas", itemId: canvasId });
+}
+
function sameResolutions(
current: Map<string, HighlightResolution> | undefined,
next: Map<string, HighlightResolution>,
diff --git a/products/desktop/packages/ui/src/features/sessions/components/useComments.test.ts b/products/desktop/packages/ui/src/features/sessions/components/useComments.test.ts
index 654147f6562c..0e576d81e74a 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/useComments.test.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/useComments.test.ts
@@ -19,7 +19,7 @@ describe("commentCacheCoversTarget", () => {
},
{
what: "the same id under another scope",
- key: ["comments", "identity", "task-1", "desktop_canvas", "a"],
+ key: ["comments", "identity", "task-1", "canvas", "a"],
covers: false,
},
{
@@ -29,7 +29,7 @@ describe("commentCacheCoversTarget", () => {
"targets",
"identity",
"task-1",
- "desktop_canvas:c,task_artifact:a",
+ "canvas:c,task_artifact:a",
],
covers: true,
},
diff --git a/products/desktop/packages/ui/src/features/sessions/components/useComments.ts b/products/desktop/packages/ui/src/features/sessions/components/useComments.ts
index 0f9acf66112b..5766b0e3bee6 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/useComments.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/useComments.ts
@@ -114,11 +114,12 @@ export function useCommentsQuery(
) {
const service = useService<SessionService>(SESSION_SERVICE);
const authIdentity = useAuthStateValue(getAuthIdentity);
+ const listTaskId = target?.scope === "canvas" ? "" : taskId;
return useQuery({
- queryKey: commentsQueryKey(authIdentity, target, taskId),
+ queryKey: commentsQueryKey(authIdentity, target, listTaskId),
queryFn: () =>
target
- ? service.getResourceComments(target, taskId)
+ ? service.getResourceComments(target, listTaskId)
: Promise.resolve([]),
enabled: options.enabled !== false && authIdentity !== null && !!target,
staleTime: 3_000,