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): group comment threads by source in a lighter list (#107392)

Shy Alter79f3afefcf95
diff --git a/products/desktop/packages/ui/src/features/canvas/components/CommentListHeader.tsx b/products/desktop/packages/ui/src/features/canvas/components/CommentListHeader.tsx
new file mode 100644
index 000000000000..44a37a73df9d
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/canvas/components/CommentListHeader.tsx
@@ -0,0 +1,113 @@
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ Tabs,
+ TabsList,
+ TabsTrigger,
+} from "@posthog/quill";
+import { SourceIcon } from "@posthog/ui/features/canvas/components/CommentThreadGroups";
+import type { ThreadSourceOption } from "@posthog/ui/features/canvas/components/taskCommentThreads";
+import { ChromeBar } from "@posthog/ui/primitives/ChromeBar";
+import {
+ FilterMenuTrigger,
+ FilterRadioSubMenu,
+} from "@posthog/ui/primitives/FilterMenu";
+import type { ReactElement } from "react";
+
+export const ALL_SOURCES = "all";
+const SOURCE_SEARCH_THRESHOLD = 8;
+
+export type CommentStateFilter = "open" | "resolved";
+
+export function CommentListHeader({
+ stateFilter,
+ openCount,
+ resolvedCount,
+ onStateFilterChange,
+ sourceFilter,
+}: {
+ stateFilter: CommentStateFilter;
+ openCount: number;
+ resolvedCount: number;
+ onStateFilterChange: (filter: CommentStateFilter) => void;
+ sourceFilter?: {
+ value: string;
+ valueLabel: string;
+ options: readonly ThreadSourceOption[];
+ onChange: (value: string) => void;
+ };
+}): ReactElement {
+ return (
+ <ChromeBar
+ inset="even"
+ actions={
+ sourceFilter && (
+ <DropdownMenu>
+ <FilterMenuTrigger
+ active={sourceFilter.value !== ALL_SOURCES}
+ label="Filter by source"
+ dataAttr="task-comments-source-filter"
+ />
+ <DropdownMenuContent
+ align="end"
+ side="bottom"
+ sideOffset={6}
+ className="w-64"
+ aria-label="Filter by source"
+ >
+ <FilterRadioSubMenu
+ label="Source"
+ options={[
+ { value: ALL_SOURCES, label: "All sources" },
+ ...sourceFilter.options.map((option) => ({
+ value: option.key,
+ label: option.label,
+ icon: (
+ <SourceIcon kind={option.kind} label={option.label} />
+ ),
+ })),
+ ]}
+ value={sourceFilter.value}
+ defaultValue={ALL_SOURCES}
+ valueLabel={sourceFilter.valueLabel}
+ onChange={sourceFilter.onChange}
+ searchPlaceholder={
+ sourceFilter.options.length > SOURCE_SEARCH_THRESHOLD
+ ? "Search sources…"
+ : undefined
+ }
+ />
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )
+ }
+ >
+ <Tabs
+ className="self-stretch"
+ value={stateFilter}
+ onValueChange={(value: string) =>
+ onStateFilterChange(value as CommentStateFilter)
+ }
+ >
+ <TabsList
+ variant="line"
+ className="!h-full"
+ aria-label="Filter comments"
+ >
+ <TabsTrigger value="open">
+ Open
+ <span className="text-muted-foreground tabular-nums">
+ {openCount}
+ </span>
+ </TabsTrigger>
+ <TabsTrigger value="resolved">
+ Resolved
+ <span className="text-muted-foreground tabular-nums">
+ {resolvedCount}
+ </span>
+ </TabsTrigger>
+ </TabsList>
+ </Tabs>
+ </ChromeBar>
+ );
+}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/CommentThreadGroups.tsx b/products/desktop/packages/ui/src/features/canvas/components/CommentThreadGroups.tsx
new file mode 100644
index 000000000000..8fd1abaea23a
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/canvas/components/CommentThreadGroups.tsx
@@ -0,0 +1,123 @@
+import {
+ CaretDownIcon,
+ ChatCircleIcon,
+ GitPullRequestIcon,
+} from "@phosphor-icons/react";
+import { Button, cn } from "@posthog/quill";
+import { iconForTemplate } from "@posthog/ui/features/canvas/components/canvasTemplateIcon";
+import type {
+ SourceKind,
+ TaskCommentThread,
+} from "@posthog/ui/features/canvas/components/taskCommentThreads";
+import { moveThreadFocus } from "@posthog/ui/features/sessions/components/threadListFocus";
+import { FileIcon } from "@posthog/ui/primitives/FileIcon";
+import {
+ type ReactElement,
+ type ReactNode,
+ useLayoutEffect,
+ useMemo,
+ useState,
+} from "react";
+
+/** The icon a source shows wherever it's named — the card label and the
+ * filter menu — so the two always agree. */
+export function SourceIcon({
+ kind,
+ label,
+ size = 12,
+}: {
+ kind: SourceKind;
+ label: string;
+ size?: number;
+}) {
+ switch (kind) {
+ case "pr":
+ return (
+ <GitPullRequestIcon size={size} className="shrink-0 text-gray-11" />
+ );
+ case "canvas":
+ return iconForTemplate("", { size, className: "text-violet-9" });
+ case "task":
+ return <ChatCircleIcon size={size} className="shrink-0 text-gray-11" />;
+ default:
+ return <FileIcon filename={label} size={size} />;
+ }
+}
+
+export function CommentThreadGroups({
+ threads,
+ grouped,
+ revealThreadId,
+ renderThread,
+}: {
+ threads: TaskCommentThread[];
+ grouped: boolean;
+ revealThreadId?: string | null;
+ renderThread: (thread: TaskCommentThread) => ReactNode;
+}): ReactElement {
+ const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(
+ () => new Set(),
+ );
+ const groups = useMemo(
+ () => [...Map.groupBy(threads, (thread) => thread.sourceKey).values()],
+ [threads],
+ );
+ const revealKey = revealThreadId
+ ? threads.find((thread) => thread.id === revealThreadId)?.sourceKey
+ : undefined;
+
+ useLayoutEffect(() => {
+ if (!revealKey) return;
+ setCollapsed((current) => {
+ if (!current.has(revealKey)) return current;
+ const next = new Set(current);
+ next.delete(revealKey);
+ return next;
+ });
+ }, [revealKey]);
+
+ const toggle = (key: string) =>
+ setCollapsed((current) => {
+ const next = new Set(current);
+ if (!next.delete(key)) next.add(key);
+ return next;
+ });
+
+ return (
+ <div data-comment-thread-list>
+ {groups.map((group) => {
+ const { sourceKey, sourceLabel, sourceKind } = group[0];
+ const open = !collapsed.has(sourceKey);
+ return (
+ <section key={sourceKey} aria-label={sourceLabel}>
+ {grouped && (
+ <Button
+ variant="default"
+ size="sm"
+ aria-expanded={open}
+ title={sourceLabel}
+ data-thread-focus="group"
+ className="sticky top-0 z-10 h-8 w-full justify-start gap-1.5 rounded-none border-border/70 border-b bg-background px-3 text-muted-foreground hover:bg-background hover:text-foreground"
+ onClick={() => toggle(sourceKey)}
+ onKeyDown={moveThreadFocus}
+ >
+ <CaretDownIcon
+ className={cn(
+ "shrink-0 text-muted-foreground transition-transform",
+ !open && "-rotate-90",
+ )}
+ />
+ <SourceIcon kind={sourceKind} label={sourceLabel} />
+ <span className="min-w-0 truncate">{sourceLabel}</span>
+ <span className="ml-auto shrink-0 pl-2 font-normal text-muted-foreground tabular-nums">
+ {group.length}
+ </span>
+ </Button>
+ )}
+ {(open || !grouped) && group.map(renderThread)}
+ </section>
+ );
+ })}
+ </div>
+ );
+}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/MentionComposer.tsx b/products/desktop/packages/ui/src/features/canvas/components/MentionComposer.tsx
index 4ab9a44ec184..f51ce8e41405 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/MentionComposer.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/MentionComposer.tsx
@@ -13,7 +13,13 @@ import Mention, { type MentionNodeAttrs } from "@tiptap/extension-mention";
import Placeholder from "@tiptap/extension-placeholder";
import { EditorContent, useEditor } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
-import { type ReactNode, useEffect, useRef, useState } from "react";
+import {
+ type ReactNode,
+ useEffect,
+ useLayoutEffect,
+ useRef,
+ useState,
+} from "react";
import "./mention-chip.css";
import "./mention-composer.css";
@@ -22,6 +28,7 @@ interface MentionComposerProps {
onValueChange: (value: string) => void;
/** Fired on Enter (without Shift) while the suggestion popup is closed. */
onSubmit: () => void;
+ onEscape?: () => void;
/** The taggable pool; typically the org's members. */
members: UserBasic[];
allowAgentMention?: boolean;
@@ -58,6 +65,7 @@ export function MentionComposer({
value,
onValueChange,
onSubmit,
+ onEscape,
members,
autoFocus = false,
allowAgentMention = false,
@@ -90,6 +98,10 @@ export function MentionComposer({
onValueChangeRef.current = onValueChange;
const onSubmitRef = useRef(onSubmit);
onSubmitRef.current = onSubmit;
+ const onEscapeRef = useRef(onEscape);
+ useLayoutEffect(() => {
+ onEscapeRef.current = onEscape;
+ });
const onMentionInsertRef = useRef(onMentionInsert);
onMentionInsertRef.current = onMentionInsert;
const openRef = useRef(open);
@@ -220,6 +232,10 @@ export function MentionComposer({
onSubmitRef.current();
return true;
}
+ if (event.key === "Escape" && onEscapeRef.current) {
+ onEscapeRef.current();
+ return true;
+ }
return 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 3eb0814fa84f..4316d1dd84f9 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
@@ -28,6 +28,12 @@ const mocks = vi.hoisted(() => ({
prQueriesLoading: false,
}));
+function pickSource(label: string | RegExp): void {
+ fireEvent.click(screen.getByLabelText("Filter by source"));
+ fireEvent.click(screen.getByText("Source"));
+ fireEvent.click(screen.getAllByText(label).at(-1) as HTMLElement);
+}
+
function openThread(body: string): void {
const card = screen.getByText(body).closest("[data-comment-thread-id]");
expect(card).not.toBeNull();
@@ -137,7 +143,7 @@ vi.mock("@posthog/ui/features/sessions/components/useComments", () => ({
},
useSetCommentResolved: (target: unknown) => {
mocks.resolvedFor.push(target);
- return { mutate: mocks.setResolved, isPending: false };
+ return { mutateAsync: mocks.setResolved, isPending: false };
},
}));
@@ -313,7 +319,7 @@ describe("TaskCommentsList", () => {
{ scope: "desktop_canvas", itemId: "canvas-1" },
]);
expect(screen.getByText("Canvas feedback")).toBeInTheDocument();
- expect(screen.getByText("“important copy”")).toBeInTheDocument();
+ expect(screen.getByText("important copy")).toBeInTheDocument();
expect(screen.getByText("V2 ·")).toBeInTheDocument();
expect(screen.queryByText("Selected text")).not.toBeInTheDocument();
expect(screen.queryByText("Whole canvas")).not.toBeInTheDocument();
@@ -359,7 +365,7 @@ describe("TaskCommentsList", () => {
render(<TaskCommentsList taskId={task.id} task={task} timeline={[]} />);
expect(screen.getByText("report.md")).toBeTruthy();
- expect(screen.getByText("“Purpose”")).toBeTruthy();
+ expect(screen.getByText("Purpose")).toBeTruthy();
});
it("loads canvas comments from a local-development artifact link", () => {
@@ -408,7 +414,6 @@ describe("TaskCommentsList", () => {
).toBeTruthy();
expect(screen.getByText("summary.md")).toBeTruthy();
expect(screen.getByText("report.md")).toBeTruthy();
- expect(screen.getByText(/1 reply/)).toBeTruthy();
// The resolve/reopen reply is thread state, not a comment of its own.
expect(screen.queryByText("Agreed")).toBeTruthy();
});
@@ -463,7 +468,8 @@ describe("TaskCommentsList", () => {
const thread = screen
.getByText("Tighten this summary")
.closest("[data-comment-thread-id]") as HTMLElement;
- const pane = thread.parentElement as HTMLElement;
+ const pane = thread.closest("[data-comment-thread-list]")
+ ?.parentElement as HTMLElement;
Object.defineProperty(pane, "scrollTop", { value: 20, writable: true });
pane.getBoundingClientRect = () => ({ top: 0, bottom: 100 }) as DOMRect;
thread.getBoundingClientRect = () => ({ top: 120, bottom: 160 }) as DOMRect;
@@ -548,6 +554,26 @@ describe("TaskCommentsList", () => {
expect(second?.nonce).toBeGreaterThan(first?.nonce ?? 0);
});
+ it("expands a collapsed source when activity requests one of its threads", () => {
+ render(<TaskCommentsList taskId={task.id} task={task} timeline={[]} />);
+
+ fireEvent.click(screen.getByText("report.md"));
+ expect(screen.queryByText("Tighten this summary")).toBeNull();
+
+ act(() => {
+ useCommentNavigationStore
+ .getState()
+ .requestCommentFocus(
+ "task-1",
+ { scope: "task_artifact", itemId: "a" },
+ "comment-1",
+ { intent: "reveal-thread" },
+ );
+ });
+
+ expect(screen.getByText("Tighten this summary")).toBeTruthy();
+ });
+
it("filters between open and resolved threads", () => {
mocks.comments = [
comment({}),
@@ -574,8 +600,7 @@ describe("TaskCommentsList", () => {
expect(screen.getByText("Second thread")).toBeTruthy();
expect(screen.queryByText("Tighten this summary")).toBeNull();
- fireEvent.click(screen.getByLabelText("Filter comments"));
- fireEvent.click(screen.getByText("Resolved (1)"));
+ fireEvent.click(screen.getByRole("tab", { name: /Resolved/ }));
expect(screen.getByText("Tighten this summary")).toBeTruthy();
expect(screen.queryByText("Second thread")).toBeNull();
@@ -610,7 +635,7 @@ describe("TaskCommentsList", () => {
const thread = screen
.getByText("Tighten this summary")
.closest("[data-comment-thread-id]") as HTMLElement;
- fireEvent.click(within(thread).getByText("Resolve"));
+ fireEvent.click(within(thread).getByLabelText("Resolve"));
expect(mocks.setResolved).toHaveBeenCalledWith({
root: expect.objectContaining({ id: "comment-1" }),
@@ -645,16 +670,11 @@ describe("TaskCommentsList", () => {
render(<TaskCommentsList taskId={task.id} task={task} timeline={[]} />);
- expect(screen.getByLabelText("Filter by source")).toHaveTextContent(
- "empty.md",
- );
expect(screen.queryByText("Tighten this summary")).toBeNull();
fireEvent.click(screen.getByLabelText("Filter by source"));
- const emptySourceOption = screen
- .getAllByText("empty.md")
- .at(-1)
- ?.closest('[role="menuitemradio"]');
- expect(emptySourceOption).toHaveTextContent("0");
+ expect(screen.getByText("Source").parentElement).toHaveTextContent(
+ "empty.md",
+ );
});
it("follows an active artifact once its run data arrives", () => {
@@ -664,7 +684,8 @@ describe("TaskCommentsList", () => {
<TaskCommentsList taskId={task.id} task={task} timeline={[]} />,
);
- expect(screen.getByLabelText("Filter by source")).toHaveTextContent(
+ fireEvent.click(screen.getByLabelText("Filter by source"));
+ expect(screen.getByText("Source").parentElement).toHaveTextContent(
"All sources",
);
@@ -679,7 +700,7 @@ describe("TaskCommentsList", () => {
];
rerender(<TaskCommentsList taskId={task.id} task={task} timeline={[]} />);
- expect(screen.getByLabelText("Filter by source")).toHaveTextContent(
+ expect(screen.getByText("Source").parentElement).toHaveTextContent(
"late.md",
);
});
@@ -690,8 +711,7 @@ describe("TaskCommentsList", () => {
<TaskCommentsList taskId={task.id} task={task} timeline={[]} />,
);
- fireEvent.click(screen.getByLabelText("Filter by source"));
- fireEvent.click(screen.getByText(/^All sources/));
+ pickSource(/^All sources/);
mocks.activeArtifactId = "a";
rerender(<TaskCommentsList taskId={task.id} task={task} timeline={[]} />);
@@ -705,8 +725,7 @@ describe("TaskCommentsList", () => {
<TaskCommentsList taskId={task.id} task={task} timeline={[]} />,
);
- fireEvent.click(screen.getByLabelText("Filter by source"));
- fireEvent.click(screen.getAllByText("report.md").at(-1) as HTMLElement);
+ pickSource("report.md");
mocks.activeArtifactId = "b";
rerender(<TaskCommentsList taskId={task.id} task={task} timeline={[]} />);
@@ -733,9 +752,9 @@ describe("TaskCommentsList", () => {
expect(screen.getByText("This needs a guard")).toBeTruthy();
expect(screen.getByText("Shipping this")).toBeTruthy();
- expect(screen.getAllByText("PR #7").length).toBe(2);
+ expect(screen.getByText("PR #7")).toBeTruthy();
// Only the file-anchored thread can be resolved on GitHub.
- expect(screen.getAllByText("Resolve")).toHaveLength(1);
+ expect(screen.getAllByLabelText("Resolve")).toHaveLength(1);
// The conversation comment can't be handled here, so it links out instead.
expect(screen.getByText("View on GitHub")).toBeTruthy();
});
@@ -789,7 +808,7 @@ describe("TaskCommentsList", () => {
const thread = screen
.getByText("This needs a guard")
.closest("[data-comment-thread-id]") as HTMLElement;
- fireEvent.click(within(thread).getByText("Resolve"));
+ fireEvent.click(within(thread).getByLabelText("Resolve"));
expect(mocks.prResolve).toHaveBeenCalledWith("node-1", true);
expect(mocks.setResolved).not.toHaveBeenCalled();
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 1606ec5c5558..91111f035ff2 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/TaskCommentsList.tsx
@@ -1,19 +1,8 @@
-import {
- CaretDownIcon,
- ChatCircleIcon,
- FunnelSimpleIcon,
- GitPullRequestIcon,
-} from "@phosphor-icons/react";
+import { ChatCircleIcon } from "@phosphor-icons/react";
import type { ResourceComment } from "@posthog/api-client/posthog-client";
import type { ThreadTimelineRow } from "@posthog/core/canvas/threadTimeline";
import { commentTargetKey } from "@posthog/core/comments/anchors";
import {
- Button,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuRadioGroup,
- DropdownMenuRadioItem,
- DropdownMenuTrigger,
Empty,
EmptyDescription,
EmptyHeader,
@@ -25,7 +14,12 @@ import type {
TaskThreadMessage,
UserBasic,
} from "@posthog/shared/domain-types";
-import { iconForTemplate } from "@posthog/ui/features/canvas/components/canvasTemplateIcon";
+import {
+ ALL_SOURCES,
+ CommentListHeader,
+ type CommentStateFilter,
+} from "@posthog/ui/features/canvas/components/CommentListHeader";
+import { CommentThreadGroups } from "@posthog/ui/features/canvas/components/CommentThreadGroups";
import {
buildRows,
type CommentSource,
@@ -36,7 +30,6 @@ import {
byNewestThread,
prCommentThreads,
resourceCommentThreads,
- type SourceKind,
type TaskCommentThread,
threadSourceOptions,
} from "@posthog/ui/features/canvas/components/taskCommentThreads";
@@ -65,7 +58,6 @@ import {
useCreateComment,
useSetCommentResolved,
} from "@posthog/ui/features/sessions/components/useComments";
-import { FileIcon } from "@posthog/ui/primitives/FileIcon";
import { LoadingState } from "@posthog/ui/primitives/LoadingState";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -74,7 +66,6 @@ const EMPTY_COMMENTS: ResourceComment[] = [];
* poll because this one fans out across every resource. */
const POLL_INTERVAL_MS = 30_000;
const PULSE_MS = 1_200;
-const ALL_SOURCES = "all";
// Keep task comments live, but bound the artifact and canvas poll so generated
// output cannot turn one Comments tab into an unbounded backend request.
const MAX_RESOURCE_COMMENT_TARGETS = 20;
@@ -83,8 +74,6 @@ const MAX_RESOURCE_COMMENT_TARGETS = 20;
const MAX_PR_COMMENT_SOURCES = 20;
const MAX_CONCURRENT_PR_SOURCES = 4;
-type StateFilter = "open" | "resolved";
-
function scrollThreadInPane(pane: HTMLElement, thread: HTMLElement): void {
const paneRect = pane.getBoundingClientRect();
const threadRect = thread.getBoundingClientRect();
@@ -99,45 +88,6 @@ function scrollThreadInPane(pane: HTMLElement, thread: HTMLElement): void {
}
}
-/** The icon a source shows wherever it's named — the card label and the
- * filter menu — so the two always agree. */
-function sourceIcon(kind: SourceKind, label: string, size = 12) {
- switch (kind) {
- case "pr":
- return (
- <GitPullRequestIcon size={size} className="shrink-0 text-gray-11" />
- );
- case "canvas":
- return iconForTemplate("", { size, className: "text-violet-9" });
- case "task":
- return <ChatCircleIcon size={size} className="shrink-0 text-gray-11" />;
- default:
- return <FileIcon filename={label} size={size} />;
- }
-}
-
-function SourceLabel({ thread }: { thread: TaskCommentThread }) {
- const replies = thread.entries.length - 1;
- return (
- <span className="mb-1 flex min-w-0 items-center gap-1.5 text-muted-foreground text-xs">
- {sourceIcon(thread.sourceKind, thread.sourceLabel)}
- <span className="min-w-0 truncate" title={thread.sourceLabel}>
- {thread.sourceLabel}
- </span>
- {thread.origin.kind === "pr-review" && (
- <span className="min-w-0 truncate">
- · {thread.origin.filePath.split("/").at(-1)}
- </span>
- )}
- {replies > 0 && (
- <span className="shrink-0">
- · {replies} {replies === 1 ? "reply" : "replies"}
- </span>
- )}
- </span>
- );
-}
-
function CommentReference({
root,
versionLabel,
@@ -153,11 +103,14 @@ function CommentReference({
const quote = anchor?.kind === "text" ? anchor.quote : null;
if (!version && !quote) return null;
return (
- <span className="mb-1 flex min-w-0 items-center gap-1.5 text-muted-foreground text-xs">
+ <span className="flex min-w-0 items-center gap-1.5 text-muted-foreground text-xs">
{version && <span className="shrink-0">{version} ·</span>}
{quote && (
- <span className="min-w-0 truncate" title={quote}>
- “{quote}”
+ <span
+ className="min-w-0 truncate border-[rgb(250_204_21)] border-l-2 pl-2"
+ title={quote}
+ >
+ {quote}
</span>
)}
</span>
@@ -178,7 +131,6 @@ function ResourceThreadRow({
pulsing,
resolution,
onOpen,
- showSource = true,
commentVersionLabel,
}: {
thread: TaskCommentThread;
@@ -190,7 +142,6 @@ function ResourceThreadRow({
pulsing: boolean;
resolution?: HighlightResolution;
onOpen: () => void;
- showSource?: boolean;
commentVersionLabel?: (versionId: string) => string | null;
}) {
const createComment = useCreateComment(source.target, taskId);
@@ -208,10 +159,7 @@ function ResourceThreadRow({
resolution={resolution}
busy={createComment.isPending || setResolved.isPending}
source={
- <>
- {showSource && <SourceLabel thread={thread} />}
- <CommentReference root={root} versionLabel={commentVersionLabel} />
- </>
+ <CommentReference root={root} versionLabel={commentVersionLabel} />
}
onSelect={onOpen}
canReply={!rootPending}
@@ -224,7 +172,9 @@ function ResourceThreadRow({
mentions,
});
}}
- onResolve={(resolved) => setResolved.mutate({ root, resolved })}
+ onResolve={async (resolved) => {
+ await setResolved.mutateAsync({ root, resolved });
+ }}
/>
);
}
@@ -266,7 +216,16 @@ function PrThreadRow({
// insert markup nobody on that side understands.
members={[]}
busy={busy}
- source={<SourceLabel thread={thread} />}
+ source={
+ origin.kind === "pr-review" && (
+ <span
+ className="block truncate text-muted-foreground text-xs"
+ title={origin.filePath}
+ >
+ {origin.filePath.split("/").at(-1)}
+ </span>
+ )
+ }
// Only inline review threads accept replies and resolution; conversation
// comments are read here and linked out to GitHub to act on.
canReply={origin.kind === "pr-review"}
@@ -326,7 +285,7 @@ export function TaskCommentsList({
const resolutionsByTarget = useCommentNavigationStore(
(state) => state.resolutionsByTarget,
);
- const [stateFilter, setStateFilter] = useState<StateFilter>("open");
+ const [stateFilter, setStateFilter] = useState<CommentStateFilter>("open");
const [sourceFilter, setSourceFilter] = useState<string>(ALL_SOURCES);
const [pulseThreadId, setPulseThreadId] = useState<string | null>(null);
const [draft, setDraft] = useState("");
@@ -598,88 +557,26 @@ export function TaskCommentsList({
// The parent scrolls the middle; the filters and the composer are pinned so
// they stay reachable however long the thread list grows.
<div className="flex h-full min-h-0 flex-col">
- <header className="sticky top-0 z-10 flex shrink-0 items-center justify-end gap-1 bg-gray-1 px-2 py-2">
- {!onlySource && (
- <DropdownMenu>
- <DropdownMenuTrigger
- render={
- <Button
- size="sm"
- aria-label="Filter by source"
- title={sourceLabel}
- >
- <span className="max-w-40 truncate">{sourceLabel}</span>
- <CaretDownIcon />
- </Button>
- }
- />
- {/* Wide, single-line rows: the label truncates at the end (with the
- full name on hover) and the count is pinned right with the shared
- ml-auto idiom, so a long PR title stays legible and aligned. */}
- <DropdownMenuContent align="end" sideOffset={6} className="w-80">
- <DropdownMenuRadioGroup
- value={sourceFilter}
- onValueChange={(value) => {
+ <CommentListHeader
+ stateFilter={stateFilter}
+ openCount={openCount}
+ resolvedCount={resolvedCount}
+ onStateFilterChange={setStateFilter}
+ sourceFilter={
+ onlySource
+ ? undefined
+ : {
+ value: effectiveSourceFilter,
+ valueLabel: sourceLabel,
+ options: sourceOptions,
+ onChange: (value) => {
sourceFilterTouched.current = value !== ALL_SOURCES;
setSourceFilter(value);
- }}
- >
- <DropdownMenuRadioItem value={ALL_SOURCES} className="gap-2">
- <FunnelSimpleIcon
- size={12}
- className="shrink-0 text-gray-11"
- />
- <span className="min-w-0 truncate">All sources</span>
- <span className="ml-auto shrink-0 pl-3 text-muted-foreground tabular-nums">
- {stateFilteredThreads.length}
- </span>
- </DropdownMenuRadioItem>
- {sourceOptions.map((option) => (
- <DropdownMenuRadioItem
- key={option.key}
- value={option.key}
- title={option.label}
- className="gap-2"
- >
- {sourceIcon(option.kind, option.label)}
- <span className="min-w-0 truncate">{option.label}</span>
- <span className="ml-auto shrink-0 pl-3 text-muted-foreground tabular-nums">
- {option.count}
- </span>
- </DropdownMenuRadioItem>
- ))}
- </DropdownMenuRadioGroup>
- </DropdownMenuContent>
- </DropdownMenu>
- )}
- <DropdownMenu>
- <DropdownMenuTrigger
- render={
- <Button size="sm" aria-label="Filter comments">
- {stateFilter === "open" ? "Open" : "Resolved"}
- <CaretDownIcon />
- </Button>
- }
- />
- <DropdownMenuContent align="end" sideOffset={6}>
- <DropdownMenuRadioGroup
- value={stateFilter}
- onValueChange={(value) => setStateFilter(value as StateFilter)}
- >
- <DropdownMenuRadioItem value="open">
- Open ({openCount})
- </DropdownMenuRadioItem>
- <DropdownMenuRadioItem value="resolved">
- Resolved ({resolvedCount})
- </DropdownMenuRadioItem>
- </DropdownMenuRadioGroup>
- </DropdownMenuContent>
- </DropdownMenu>
- </header>
- <div
- ref={threadListRef}
- className="min-h-0 flex-1 space-y-2 overflow-y-auto px-2 pt-3 pb-2"
- >
+ },
+ }
+ }
+ />
+ <div ref={threadListRef} className="min-h-0 flex-1 overflow-y-auto">
{loadFailed ? (
<Empty className="py-8">
<EmptyHeader>
@@ -713,34 +610,38 @@ export function TaskCommentsList({
</EmptyHeader>
</Empty>
) : (
- visibleThreads.map((thread) =>
- thread.origin.kind === "resource" ? (
- <ResourceThreadRow
- key={thread.id}
- thread={thread}
- source={thread.origin.source}
- root={thread.origin.root}
- taskId={taskId}
- members={members}
- selected={thread.id === focusedThreadId}
- pulsing={thread.id === pulseThreadId}
- resolution={resolutionsByTarget[thread.sourceKey]?.get(
- thread.id,
- )}
- onOpen={() => openThread(thread)}
- showSource={!onlySource}
- commentVersionLabel={commentVersionLabel}
- />
- ) : (
- <PrThreadRow
- key={thread.id}
- thread={thread}
- selected={thread.id === focusedThreadId}
- pulsing={thread.id === pulseThreadId}
- onOpen={() => openThread(thread)}
- />
- ),
- )
+ <CommentThreadGroups
+ threads={visibleThreads}
+ grouped={!onlySource}
+ revealThreadId={pulseThreadId}
+ renderThread={(thread) =>
+ thread.origin.kind === "resource" ? (
+ <ResourceThreadRow
+ key={thread.id}
+ thread={thread}
+ source={thread.origin.source}
+ root={thread.origin.root}
+ taskId={taskId}
+ members={members}
+ selected={thread.id === focusedThreadId}
+ pulsing={thread.id === pulseThreadId}
+ resolution={resolutionsByTarget[thread.sourceKey]?.get(
+ thread.id,
+ )}
+ onOpen={() => openThread(thread)}
+ commentVersionLabel={commentVersionLabel}
+ />
+ ) : (
+ <PrThreadRow
+ key={thread.id}
+ thread={thread}
+ selected={thread.id === focusedThreadId}
+ pulsing={thread.id === pulseThreadId}
+ onOpen={() => openThread(thread)}
+ />
+ )
+ }
+ />
)}
</div>
<footer className="sticky bottom-0 shrink-0 border-border border-t bg-background p-2">
@@ -762,9 +663,10 @@ export function TaskCommentsList({
});
}}
members={members}
- placeholder={`Comment on this ${onlySource ? "canvas" : "task"}… Type @ to mention someone`}
- rows={2}
+ placeholder={`Comment on this ${onlySource ? "canvas" : "task"}…`}
+ rows={1}
disabled={createComment.isPending}
+ compact
/>
</footer>
</div>
diff --git a/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.tsx b/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.tsx
index fe042a23d131..494f2bbbcf6b 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.tsx
@@ -16,6 +16,7 @@ export function CommentComposer({
disabled = false,
submitLabel = "Comment",
autoFocus = false,
+ compact = false,
}: {
value: string;
onValueChange: (value: string) => void;
@@ -28,6 +29,7 @@ export function CommentComposer({
submitLabel?: string;
/** For a composer the user just opened, so they can type straight away. */
autoFocus?: boolean;
+ compact?: boolean;
}) {
const mentionsDisabledReason = useMentionsDisabledReason();
const mentionMembers = mentionsDisabledReason ? [] : members;
@@ -45,13 +47,17 @@ export function CommentComposer({
value={value}
onValueChange={onValueChange}
onSubmit={submit}
+ onEscape={onCancel}
members={mentionMembers}
autoFocus={autoFocus}
placeholder={placeholder}
rows={rows}
inputClassName="max-h-40 text-[13px]"
>
- <InputGroupAddon align="block-end" className="p-1">
+ <InputGroupAddon
+ align={compact ? "inline-end" : "block-end"}
+ className={compact ? "self-end p-1" : "p-1"}
+ >
{showMentionsDisabled && (
<output className="px-1 text-muted-foreground text-xs">
{mentionsDisabledReason}
@@ -66,7 +72,7 @@ export function CommentComposer({
<XIcon />
</InputGroupButton>
)}
- <span className="ml-auto">
+ <span className={compact ? undefined : "ml-auto"}>
<InputGroupButton
variant="primary"
size="icon-sm"
diff --git a/products/desktop/packages/ui/src/features/sessions/components/CommentThreadCard.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/CommentThreadCard.test.tsx
index e7bffeccb921..1e3a2c283ae5 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/CommentThreadCard.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/CommentThreadCard.test.tsx
@@ -69,7 +69,7 @@ describe("CommentThreadCard", () => {
/>,
);
- fireEvent.click(screen.getByText("Resolve"));
+ fireEvent.click(screen.getByLabelText("Resolve"));
await waitFor(() => expect(onResolve).toHaveBeenCalledWith(true));
});
diff --git a/products/desktop/packages/ui/src/features/sessions/components/CommentThreadCard.tsx b/products/desktop/packages/ui/src/features/sessions/components/CommentThreadCard.tsx
index 58315ade44f8..3496fcd8ae00 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/CommentThreadCard.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/CommentThreadCard.tsx
@@ -1,18 +1,22 @@
import {
- ArrowCounterClockwise,
+ ArrowBendUpLeftIcon,
+ ArrowCounterClockwiseIcon,
ArrowSquareOutIcon,
- ChatCircle,
- CheckCircle,
- WarningCircle,
+ CaretRightIcon,
+ CheckCircleIcon,
+ WarningCircleIcon,
} from "@phosphor-icons/react";
+import { avatarColor } from "@posthog/core/auth/avatarColor";
import {
Avatar,
AvatarFallback,
AvatarImage,
Button,
- Card,
- CardContent,
- Separator,
+ cn,
+ Kbd,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
} from "@posthog/quill";
import { formatRelativeTimeShort } from "@posthog/shared";
import type { UserBasic } from "@posthog/shared/domain-types";
@@ -22,53 +26,114 @@ import type { CommentEntry } from "@posthog/ui/features/canvas/components/taskCo
import { githubCommentComponents } from "@posthog/ui/features/editor/components/githubCommentImages";
import { githubRehypePlugins } from "@posthog/ui/features/editor/components/githubMarkdownPlugins";
import { MarkdownRenderer } from "@posthog/ui/features/editor/components/MarkdownRenderer";
+import { toast } from "@posthog/ui/primitives/toast";
import { cachedImageUrl } from "@posthog/ui/shell/cachedImageUrl";
import { openExternalUrl } from "@posthog/ui/shell/openExternal";
-import { type ReactNode, useState } from "react";
+import {
+ type KeyboardEvent,
+ type ReactElement,
+ type ReactNode,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
import { CommentComposer } from "./CommentComposer";
import type { HighlightResolution } from "./commentViewTypes";
+import { adjacentThread, moveThreadFocus } from "./threadListFocus";
+
+const MAX_REPLIES_SHOWN = 2;
+const TEXT_INSET = "pl-7";
-function CommentBody({ entry }: { entry: CommentEntry }) {
+function CommentBody({
+ entry,
+ actions,
+}: {
+ entry: CommentEntry;
+ actions?: ReactNode;
+}): ReactElement {
+ const color = avatarColor(entry.authorName);
return (
- <div className="flex gap-2 py-2">
- {/* A PostHog author keeps the avatar and hue they have everywhere else;
- a GitHub author only ever comes with a url. */}
- {entry.user || !entry.avatarUrl ? (
- <UserAvatar user={entry.user} size="sm" />
- ) : (
- <Avatar size="sm">
- <AvatarImage src={cachedImageUrl(entry.avatarUrl)} alt="" />
- <AvatarFallback>{entry.authorName.slice(0, 2)}</AvatarFallback>
- </Avatar>
- )}
- <div className="min-w-0 flex-1">
- <div className="flex items-baseline gap-2">
- <span className="truncate font-medium text-xs">
- {entry.authorName}
- </span>
- <span className="shrink-0 text-muted-foreground text-xs">
- {formatRelativeTimeShort(entry.createdAt)}
- </span>
- </div>
- {entry.format === "markdown" ? (
- <div className="mt-1 break-words text-[13px] leading-relaxed [&_img]:max-w-full [&_p]:m-0 [&_pre]:max-w-full [&_pre]:overflow-x-auto">
- <MarkdownRenderer
- content={entry.body}
- rehypePlugins={githubRehypePlugins}
- componentsOverride={githubCommentComponents}
- />
- </div>
+ <div>
+ <div className="flex min-h-6 items-center gap-2">
+ {/* A PostHog author keeps the avatar and hue they have everywhere else;
+ a GitHub author only ever comes with a url. */}
+ {entry.user ? (
+ <UserAvatar user={entry.user} size="xs" />
) : (
- <MentionText
- content={entry.body}
- className="mt-1 block whitespace-pre-wrap break-words text-[13px] leading-relaxed"
- />
+ <Avatar size="xs">
+ {entry.avatarUrl && (
+ <AvatarImage src={cachedImageUrl(entry.avatarUrl)} alt="" />
+ )}
+ <AvatarFallback
+ style={{ backgroundColor: color.bg, color: color.text }}
+ >
+ {entry.authorName.slice(0, 2).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
)}
+ <span className="truncate font-medium text-[13px]">
+ {entry.authorName}
+ </span>
+ <span className="shrink-0 text-muted-foreground text-xs">
+ {formatRelativeTimeShort(entry.createdAt)}
+ </span>
+ {actions}
</div>
+ {entry.format === "markdown" ? (
+ <div
+ className={`${TEXT_INSET} break-words text-[13px] leading-relaxed [&_img]:max-w-full [&_p]:m-0 [&_pre]:max-w-full [&_pre]:overflow-x-auto`}
+ >
+ <MarkdownRenderer
+ content={entry.body}
+ rehypePlugins={githubRehypePlugins}
+ componentsOverride={githubCommentComponents}
+ />
+ </div>
+ ) : (
+ <MentionText
+ content={entry.body}
+ className={`${TEXT_INSET} block whitespace-pre-wrap break-words text-[13px] leading-relaxed`}
+ />
+ )}
</div>
);
}
+function ThreadAction({
+ label,
+ shortcut,
+ disabled,
+ onClick,
+ children,
+}: {
+ label: string;
+ shortcut: string;
+ disabled?: boolean;
+ onClick: () => void;
+ children: ReactNode;
+}): ReactElement {
+ return (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ size="icon-sm"
+ aria-label={label}
+ disabled={disabled}
+ onClick={onClick}
+ >
+ {children}
+ </Button>
+ }
+ />
+ <TooltipContent side="top" className="flex items-center gap-1.5">
+ {label}
+ <Kbd>{shortcut}</Kbd>
+ </TooltipContent>
+ </Tooltip>
+ );
+}
+
/**
* One thread, with its replies and the reply/resolve controls. Selecting it is
* the caller's business: in a list spanning several resources that means
@@ -112,108 +177,191 @@ export function CommentThreadCard({
onResolve: (resolved: boolean) => void | Promise<void>;
}) {
const [replying, setReplying] = useState(false);
+ const openButtonRef = useRef<HTMLButtonElement>(null);
+ const focusAfterRemoval = useRef<HTMLElement | null>(null);
+ useEffect(
+ () => () => {
+ const next = focusAfterRemoval.current;
+ if (next?.isConnected && document.activeElement === document.body) {
+ next.focus();
+ }
+ },
+ [],
+ );
const [reply, setReply] = useState("");
+ const [showAllReplies, setShowAllReplies] = useState(false);
const [root, ...replies] = entries;
if (!root) return null;
+ const hiddenReplies =
+ showAllReplies || replies.length <= MAX_REPLIES_SHOWN
+ ? 0
+ : replies.length - 1;
+ const shownReplies = replies.slice(hiddenReplies);
+ const stopReply = () => {
+ setReplying(false);
+ setReply("");
+ };
+
+ const setThreadResolved = (next: boolean) => {
+ Promise.resolve(onResolve(next))
+ .then(() => {
+ toast.success(next ? "Thread resolved" : "Thread reopened", {
+ id: `comment-thread-state-${threadId}`,
+ action: {
+ label: "Undo",
+ onClick: () => {
+ Promise.resolve(onResolve(!next)).catch(() => undefined);
+ },
+ },
+ });
+ })
+ .catch(() => {
+ focusAfterRemoval.current = null;
+ });
+ };
+
+ const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
+ if (event.metaKey || event.ctrlKey || event.altKey) return;
+ moveThreadFocus(event);
+ if (event.key === "r" && canReply) {
+ event.preventDefault();
+ setReplying(true);
+ } else if (event.key === "e" && canResolve && !busy) {
+ event.preventDefault();
+ focusAfterRemoval.current = adjacentThread(event.currentTarget);
+ setThreadResolved(!resolved);
+ }
+ };
+
+ const actions = (canReply || canResolve) && (
+ <span
+ className={cn(
+ "pointer-events-auto ml-auto flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-focus-within/thread:opacity-100 group-hover/thread:opacity-100",
+ selected && "opacity-100",
+ )}
+ >
+ {canReply && (
+ <ThreadAction
+ label="Reply"
+ shortcut="R"
+ onClick={() => setReplying(true)}
+ >
+ <ArrowBendUpLeftIcon />
+ </ThreadAction>
+ )}
+ {canResolve && (
+ <ThreadAction
+ label={resolved ? "Reopen" : "Resolve"}
+ shortcut="E"
+ disabled={busy}
+ onClick={() => setThreadResolved(!resolved)}
+ >
+ {resolved ? <ArrowCounterClockwiseIcon /> : <CheckCircleIcon />}
+ </ThreadAction>
+ )}
+ </span>
+ );
+
return (
- <Card
- className={`gap-0 p-0 transition-all duration-300 ${
- selected ? "border-accent bg-accent/5" : ""
- } ${
+ <div
+ className={cn(
+ "group/thread relative border-border/70 border-b p-3 transition-colors duration-300 has-[>[data-thread-focus]:focus-visible]:ring-2 has-[>[data-thread-focus]:focus-visible]:ring-ring/50 has-[>[data-thread-focus]:focus-visible]:ring-inset",
+ selected ? "bg-fill-selected" : "hover:bg-fill-hover",
// Inset, so a pane that clips its overflow can't shave the highlight.
- pulsing ? "ring-2 ring-accent ring-inset" : ""
- } ${resolved ? "opacity-70" : ""}`}
+ pulsing && "ring-2 ring-primary ring-inset",
+ )}
data-comment-thread-id={threadId}
>
- <CardContent className="relative p-3">
- <Button
- type="button"
- variant="outline"
- className="absolute inset-0 h-auto w-full opacity-0"
- aria-label="Open comment thread"
- onClick={onSelect}
- />
- <div className="pointer-events-none relative [&_a]:pointer-events-auto [&_button]:pointer-events-auto">
- <div className="w-full text-left">
- {source}
- {resolution === "orphaned" && (
- <div className="mb-1.5 flex items-center gap-1 text-amber-700 text-xs dark:text-amber-300">
- <WarningCircle />
- The highlighted text changed
- </div>
- )}
- <CommentBody entry={root} />
+ <Button
+ type="button"
+ variant="outline"
+ className="absolute inset-0 h-auto w-full scroll-mt-8 rounded-none opacity-0"
+ ref={openButtonRef}
+ aria-label="Open comment thread"
+ data-thread-focus="thread"
+ onClick={onSelect}
+ onKeyDown={onKeyDown}
+ />
+ <div className="pointer-events-none relative [&_a]:pointer-events-auto [&_button]:pointer-events-auto">
+ {source && <div className="mb-2 min-w-0">{source}</div>}
+ {resolution === "orphaned" && (
+ <div className="mb-2 flex items-center gap-1 text-warning-foreground text-xs">
+ <WarningCircleIcon />
+ The highlighted text changed
</div>
- </div>
- {/* Replies sit at the root's indentation: a thread this narrow reads as
- one conversation, and nesting only stole width from the text. */}
- <div className="pointer-events-none relative">
- {replies.map((entry) => (
+ )}
+ <div className="flex flex-col gap-3">
+ <CommentBody entry={root} actions={actions} />
+ {hiddenReplies > 0 && (
+ <div className={TEXT_INSET}>
+ <Button
+ size="xs"
+ variant="link-muted"
+ className="-mt-2 -mb-1 h-5 self-start px-0"
+ onClick={() => {
+ setShowAllReplies(true);
+ openButtonRef.current?.focus();
+ }}
+ >
+ <CaretRightIcon />
+ Show {hiddenReplies} earlier{" "}
+ {hiddenReplies === 1 ? "reply" : "replies"}
+ </Button>
+ </div>
+ )}
+ {shownReplies.map((entry) => (
<CommentBody key={entry.id} entry={entry} />
))}
</div>
- {/* A conversation comment can only be read here and acted on in GitHub;
- dead Reply/Resolve buttons would just discard whatever was typed, so
- it gets a link out instead. */}
- {(canReply || canResolve || viewHref) && <Separator className="my-2" />}
- {!canReply && !canResolve && viewHref ? (
- <div className="relative">
- <Button
- size="sm"
- variant="outline"
- onClick={() => openExternalUrl(viewHref)}
- >
- <ArrowSquareOutIcon />
- View on GitHub
- </Button>
+ </div>
+ {/* A conversation comment can only be read here and acted on in GitHub;
+ dead Reply/Resolve buttons would just discard whatever was typed, so
+ it gets a link out instead. */}
+ {!canReply && !canResolve && viewHref ? (
+ <div className={`relative ${TEXT_INSET} mt-2`}>
+ <Button
+ size="xs"
+ variant="link-muted"
+ className="px-0"
+ onClick={() => openExternalUrl(viewHref)}
+ >
+ View on GitHub
+ <ArrowSquareOutIcon />
+ </Button>
+ </div>
+ ) : (
+ canReply &&
+ (replying || selected || reply) && (
+ <div className={`relative ${TEXT_INSET} mt-3`}>
+ <CommentComposer
+ key={replying ? "replying" : "idle"}
+ value={reply}
+ onValueChange={setReply}
+ onSubmit={async (content, mentions) => {
+ await onReply(content, mentions);
+ stopReply();
+ setShowAllReplies(true);
+ }}
+ onCancel={
+ replying || reply
+ ? () => {
+ stopReply();
+ openButtonRef.current?.focus();
+ }
+ : undefined
+ }
+ members={members}
+ placeholder="Reply…"
+ rows={1}
+ disabled={busy}
+ submitLabel="Reply"
+ autoFocus={replying}
+ compact
+ />
</div>
- ) : replying ? (
- <CommentComposer
- value={reply}
- onValueChange={setReply}
- onSubmit={async (content, mentions) => {
- await onReply(content, mentions);
- setReply("");
- setReplying(false);
- }}
- onCancel={() => setReplying(false)}
- members={members}
- placeholder={
- members.length > 0 ? "Reply… Type @ to mention someone" : "Reply…"
- }
- rows={2}
- disabled={busy}
- submitLabel="Reply"
- autoFocus
- />
- ) : (
- (canReply || canResolve) && (
- <div className="relative flex gap-1">
- {canReply && (
- <Button size="sm" onClick={() => setReplying(true)}>
- <ChatCircle />
- Reply
- </Button>
- )}
- {canResolve && (
- <Button
- size="sm"
- disabled={busy}
- onClick={() => {
- Promise.resolve(onResolve(!resolved)).catch(
- () => undefined,
- );
- }}
- >
- {resolved ? <ArrowCounterClockwise /> : <CheckCircle />}
- {resolved ? "Reopen" : "Resolve"}
- </Button>
- )}
- </div>
- )
- )}
- </CardContent>
- </Card>
+ )
+ )}
+ </div>
);
}
diff --git a/products/desktop/packages/ui/src/features/sessions/components/threadListFocus.ts b/products/desktop/packages/ui/src/features/sessions/components/threadListFocus.ts
new file mode 100644
index 000000000000..a2724eb03fb0
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/sessions/components/threadListFocus.ts
@@ -0,0 +1,30 @@
+import type { KeyboardEvent } from "react";
+
+const STEP_BY_KEY: Record<string, number> = {
+ ArrowDown: 1,
+ j: 1,
+ ArrowUp: -1,
+ k: -1,
+};
+
+function threadListStops(from: HTMLElement, selector: string): HTMLElement[] {
+ const list = from.closest("[data-comment-thread-list]");
+ return list ? [...list.querySelectorAll<HTMLElement>(selector)] : [];
+}
+
+export function adjacentThread(from: HTMLElement): HTMLElement | null {
+ const threads = threadListStops(from, '[data-thread-focus="thread"]');
+ const index = threads.indexOf(from);
+ return threads[index + 1] ?? threads[index - 1] ?? null;
+}
+
+export function moveThreadFocus(event: KeyboardEvent<HTMLElement>): void {
+ const step = STEP_BY_KEY[event.key];
+ if (!step || event.metaKey || event.ctrlKey || event.altKey) return;
+ const stops = threadListStops(event.currentTarget, "[data-thread-focus]");
+ const next = stops[stops.indexOf(event.currentTarget) + step];
+ if (!next) return;
+ event.preventDefault();
+ next.focus();
+ next.scrollIntoView?.({ block: "nearest" });
+}