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(canvas): add unreads-only filter to activity surfaces (#80307)

Adam Leitheb798536f54d
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityHoverCard.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityHoverCard.test.tsx
index b5cf8abe1f28..312f51407d6b 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityHoverCard.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityHoverCard.test.tsx
@@ -23,10 +23,29 @@ vi.mock("@posthog/quill", () => ({
EmptyHeader: ({ children }: { children: ReactNode }) => <div>{children}</div>,
EmptyMedia: ({ children }: { children: ReactNode }) => <div>{children}</div>,
EmptyTitle: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+ Label: ({ children, htmlFor }: { children: ReactNode; htmlFor?: string }) => (
+ <label htmlFor={htmlFor}>{children}</label>
+ ),
PopoverContent: ({ children }: { children: ReactNode }) => (
<div>{children}</div>
),
Spinner: () => <div>Loading</div>,
+ Switch: ({
+ checked,
+ onCheckedChange,
+ }: {
+ checked: boolean;
+ onCheckedChange: (checked: boolean) => void;
+ }) => (
+ <button
+ type="button"
+ role="switch"
+ aria-checked={checked}
+ onClick={() => onCheckedChange(!checked)}
+ >
+ Unreads
+ </button>
+ ),
}));
vi.mock("@posthog/ui/features/auth/authClient", () => ({
useOptionalAuthenticatedClient: () => ({}),
@@ -74,6 +93,7 @@ vi.mock("@posthog/ui/primitives/hooks/useInView", () => ({
}));
vi.mock("@posthog/ui/shell/analytics", () => ({ track: vi.fn() }));
+import { useActivityFilterStore } from "@posthog/ui/features/canvas/stores/activityFilterStore";
import { ActivityHoverCard } from "./ActivityHoverCard";
describe("ActivityHoverCard", () => {
@@ -83,6 +103,7 @@ describe("ActivityHoverCard", () => {
mocks.isFetchingNextPage = false;
mocks.items = [];
mocks.commentsEnabled = true;
+ useActivityFilterStore.setState({ unreadsOnly: false });
});
it("loads the next page when the bottom sentinel is visible", async () => {
@@ -146,4 +167,30 @@ describe("ActivityHoverCard", () => {
expect(screen.getAllByText("Activity row")).toHaveLength(1);
});
+
+ it("drops read activity while the unreads filter is on", () => {
+ mocks.items = [
+ {
+ id: "read-activity",
+ taskId: "task-1",
+ activityAt: "2026-08-07T00:00:00Z",
+ activityKind: "mention",
+ isUnread: false,
+ } as TaskActivityItem,
+ {
+ id: "unread-activity",
+ taskId: "task-2",
+ activityAt: "2026-08-07T00:01:00Z",
+ activityKind: "mention",
+ isUnread: true,
+ } as TaskActivityItem,
+ ];
+
+ render(<ActivityHoverCard onClose={vi.fn()} />);
+ expect(screen.getAllByText("Activity row")).toHaveLength(2);
+
+ fireEvent.click(screen.getByRole("switch"));
+
+ expect(screen.getAllByText("Activity row")).toHaveLength(1);
+ });
});
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityHoverCard.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityHoverCard.tsx
index 771347a777a1..9b45aa85e09d 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityHoverCard.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityHoverCard.tsx
@@ -12,10 +12,12 @@ import {
import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";
import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser";
+import { ActivityUnreadsToggle } from "@posthog/ui/features/canvas/components/ActivityUnreadsToggle";
import { ActivityRow } from "@posthog/ui/features/canvas/components/ActivityView";
import { useBlockedTaskIds } from "@posthog/ui/features/canvas/hooks/useBlockedSessionCount";
import { useMarkTaskActivityRead } from "@posthog/ui/features/canvas/hooks/useMarkTaskActivityRead";
import { useTaskActivity } from "@posthog/ui/features/canvas/hooks/useTaskActivity";
+import { useActivityFilterStore } from "@posthog/ui/features/canvas/stores/activityFilterStore";
import { useCommentsEnabled } from "@posthog/ui/features/sessions/useCommentsEnabled";
import { useInView } from "@posthog/ui/primitives/hooks/useInView";
import { track } from "@posthog/ui/shell/analytics";
@@ -54,8 +56,10 @@ export function ActivityHoverCard({
root: scrollRoot,
rootMargin: "100px 0px",
});
+ const unreadsOnly = useActivityFilterStore((state) => state.unreadsOnly);
const visibleItems = getVisibleActivityItems(items, commentsEnabled);
const unreadItems = getUnreadActivityItems(visibleItems);
+ const shownItems = unreadsOnly ? unreadItems : visibleItems;
const { mutate: markTasksRead, isPending: isMarkingRead } =
useMarkTaskActivityRead();
useEffect(() => {
@@ -85,41 +89,48 @@ export function ActivityHoverCard({
sideOffset={8}
className="w-[380px] gap-0 overflow-hidden p-0"
>
- <div className="flex min-h-12 items-center justify-between border-border border-b px-3">
+ <div className="flex min-h-12 items-center gap-2 border-border border-b px-3">
<span className="font-semibold text-sm">Activity</span>
- {unreadItems.length > 0 && (
- <Button
- variant="default"
- size="sm"
- loading={isMarkingRead}
- disabled={isMarkingRead}
- onClick={markAllRead}
- >
- <ChecksIcon size={14} />
- {markLoadedReadLabel(unreadItems.length, unreadCount)}
- </Button>
- )}
+ <div className="ml-auto flex shrink-0 items-center gap-2">
+ {unreadItems.length > 0 && (
+ <Button
+ variant="default"
+ size="sm"
+ loading={isMarkingRead}
+ disabled={isMarkingRead}
+ onClick={markAllRead}
+ >
+ <ChecksIcon size={14} />
+ {markLoadedReadLabel(unreadItems.length, unreadCount)}
+ </Button>
+ )}
+ <ActivityUnreadsToggle />
+ </div>
</div>
<div ref={setScrollRoot} className="max-h-[480px] overflow-y-auto p-1.5">
- {isLoading && visibleItems.length === 0 ? (
+ {isLoading && shownItems.length === 0 ? (
<div className="flex justify-center py-10">
<Spinner />
</div>
- ) : visibleItems.length === 0 ? (
+ ) : shownItems.length === 0 ? (
<Empty className="border-0 py-8">
<EmptyHeader>
<EmptyMedia variant="icon">
<BellIcon />
</EmptyMedia>
- <EmptyTitle>No recent activity</EmptyTitle>
+ <EmptyTitle>
+ {unreadsOnly ? "No unread activity" : "No recent activity"}
+ </EmptyTitle>
<EmptyDescription>
- New task updates will appear here.
+ {unreadsOnly
+ ? "You're all caught up."
+ : "New task updates will appear here."}
</EmptyDescription>
</EmptyHeader>
</Empty>
) : (
<div className="flex flex-col gap-0.5">
- {visibleItems.map((item) => (
+ {shownItems.map((item) => (
<ActivityRow
key={item.id}
item={item}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityUnreadsToggle.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityUnreadsToggle.tsx
new file mode 100644
index 000000000000..6c970d539f75
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityUnreadsToggle.tsx
@@ -0,0 +1,24 @@
+import { Label, Switch } from "@posthog/quill";
+import { useActivityFilterStore } from "@posthog/ui/features/canvas/stores/activityFilterStore";
+import { useId } from "react";
+
+/** Narrows both Activity surfaces down to what hasn't been read yet. */
+export function ActivityUnreadsToggle() {
+ const switchId = useId();
+ const unreadsOnly = useActivityFilterStore((state) => state.unreadsOnly);
+ const setUnreadsOnly = useActivityFilterStore(
+ (state) => state.setUnreadsOnly,
+ );
+
+ return (
+ <div className="flex shrink-0 items-center gap-2">
+ <Label htmlFor={switchId}>Unreads</Label>
+ <Switch
+ id={switchId}
+ size="sm"
+ checked={unreadsOnly}
+ onCheckedChange={setUnreadsOnly}
+ />
+ </div>
+ );
+}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx
index a22ce08ea3cd..9c9ae506d40f 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx
@@ -24,11 +24,13 @@ import type { UserBasic } from "@posthog/shared/domain-types";
import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
import { UserAvatar } from "@posthog/ui/features/auth/UserAvatar";
import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser";
+import { ActivityUnreadsToggle } from "@posthog/ui/features/canvas/components/ActivityUnreadsToggle";
import { MentionText } from "@posthog/ui/features/canvas/components/MentionText";
import { useBlockedTaskIds } from "@posthog/ui/features/canvas/hooks/useBlockedSessionCount";
import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";
import { useMarkTaskActivityRead } from "@posthog/ui/features/canvas/hooks/useMarkTaskActivityRead";
import { useTaskActivity } from "@posthog/ui/features/canvas/hooks/useTaskActivity";
+import { useActivityFilterStore } from "@posthog/ui/features/canvas/stores/activityFilterStore";
import { useCanvasChatPanelStore } from "@posthog/ui/features/canvas/stores/canvasChatPanelStore";
import { useThreadPanelStore } from "@posthog/ui/features/canvas/stores/threadPanelStore";
import { copyChannelLink } from "@posthog/ui/features/canvas/utils/copyChannelLink";
@@ -361,6 +363,8 @@ export function ActivityView() {
() => getUnreadActivityItems(visibleItems),
[visibleItems],
);
+ const unreadsOnly = useActivityFilterStore((state) => state.unreadsOnly);
+ const shownItems = unreadsOnly ? unreadItems : visibleItems;
const visibleUnreadCount = activityUnreadTotalForLabel({
commentsEnabled,
unreadCount,
@@ -403,51 +407,64 @@ export function ActivityView() {
</Button>
);
+ // Sits below the rows and below the empty state alike: filtering to unreads can
+ // empty a page that still has unread activity waiting on the next one.
+ const loadMoreButton = hasNextPage && (
+ <div className="mt-3 flex justify-center">
+ <Button
+ variant="outline"
+ loading={isFetchingNextPage}
+ disabled={isFetchingNextPage}
+ onClick={() => void fetchNextPage()}
+ >
+ Load more
+ </Button>
+ </div>
+ );
+
// The feed body is identical in both shells; only the empty-state copy tracks
// the layout's naming ("spaces" vs "channels").
const feed =
- isLoading && visibleItems.length === 0 ? (
+ isLoading && shownItems.length === 0 ? (
<div className="flex justify-center py-16">
<Spinner />
</div>
- ) : visibleItems.length === 0 ? (
- <Empty>
- <EmptyHeader>
- <EmptyMedia variant="icon">
- <BellIcon size={20} />
- </EmptyMedia>
- <EmptyTitle>No activity yet</EmptyTitle>
- <EmptyDescription>
- Task updates and comment notifications across{" "}
- {spacesLayout ? "spaces" : "channels"} appear here.
- </EmptyDescription>
- </EmptyHeader>
- </Empty>
+ ) : shownItems.length === 0 ? (
+ <>
+ <Empty>
+ <EmptyHeader>
+ <EmptyMedia variant="icon">
+ <BellIcon size={20} />
+ </EmptyMedia>
+ <EmptyTitle>
+ {unreadsOnly ? "No unread activity" : "No activity yet"}
+ </EmptyTitle>
+ <EmptyDescription>
+ {unreadsOnly
+ ? "You're all caught up."
+ : `Task updates and comment notifications across ${spacesLayout ? "spaces" : "channels"} appear here.`}
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ {loadMoreButton}
+ </>
) : (
- <div className="flex flex-col gap-0.5">
- {visibleItems.map((item) => (
- <ActivityRow
- key={item.id}
- item={item}
- channelId={item.channelId}
- onOpen={markRead}
- onMarkRead={markRead}
- currentUser={currentUser}
- blockedTaskIds={blockedTaskIds}
- />
- ))}
- {hasNextPage && (
- <Button
- variant="outline"
- className="mt-3 self-center"
- loading={isFetchingNextPage}
- disabled={isFetchingNextPage}
- onClick={() => void fetchNextPage()}
- >
- Load more
- </Button>
- )}
- </div>
+ <>
+ <div className="flex flex-col gap-0.5">
+ {shownItems.map((item) => (
+ <ActivityRow
+ key={item.id}
+ item={item}
+ channelId={item.channelId}
+ onOpen={markRead}
+ onMarkRead={markRead}
+ currentUser={currentUser}
+ blockedTaskIds={blockedTaskIds}
+ />
+ ))}
+ </div>
+ {loadMoreButton}
+ </>
);
if (spacesLayout) {
@@ -462,9 +479,10 @@ export function ActivityView() {
{unreadCount} unread
</PageHeaderChip>
)}
- {unreadCount > 0 && (
- <PageHeaderActions>{markAllReadButton}</PageHeaderActions>
- )}
+ <PageHeaderActions>
+ {unreadCount > 0 && markAllReadButton}
+ <ActivityUnreadsToggle />
+ </PageHeaderActions>
</PageHeaderTitleRow>
<PageHeaderDescription>
Task updates and comment notifications across spaces.
@@ -491,7 +509,10 @@ export function ActivityView() {
{spacesLayout ? "spaces" : "channels"}.
</Text>
</div>
- {unreadCount > 0 && markAllReadButton}
+ <div className="flex shrink-0 items-center gap-2">
+ {unreadCount > 0 && markAllReadButton}
+ <ActivityUnreadsToggle />
+ </div>
</div>
<div className="mt-4">{feed}</div>
</div>
diff --git a/products/desktop/packages/ui/src/features/canvas/stores/activityFilterStore.ts b/products/desktop/packages/ui/src/features/canvas/stores/activityFilterStore.ts
new file mode 100644
index 000000000000..002d6d71957e
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/canvas/stores/activityFilterStore.ts
@@ -0,0 +1,20 @@
+import { create } from "zustand";
+import { persist } from "zustand/middleware";
+
+interface ActivityFilterStore {
+ /** Show only activity that hasn't been read yet. */
+ unreadsOnly: boolean;
+ setUnreadsOnly: (unreadsOnly: boolean) => void;
+}
+
+// Per-device preference shared by the Activity popover and the Activity page, so
+// the filter you set on one is the filter you find on the other.
+export const useActivityFilterStore = create<ActivityFilterStore>()(
+ persist(
+ (set) => ({
+ unreadsOnly: false,
+ setUnreadsOnly: (unreadsOnly) => set({ unreadsOnly }),
+ }),
+ { name: "activity-filter-storage" },
+ ),
+);