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.

fix(desktop): scope the personal space loops tab to its own loops (#100279)

Harley Alexander1eb69e1814a0
diff --git a/products/desktop/packages/ui/src/features/canvas/components/WebsiteChannelLoops.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/WebsiteChannelLoops.test.tsx
index 5789a1f6f5d8..0df039ba041e 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/WebsiteChannelLoops.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/WebsiteChannelLoops.test.tsx
@@ -1,5 +1,5 @@
+import type { LoopSchemas } from "@posthog/api-client/loops";
import { render, screen } from "@testing-library/react";
-import type { ReactNode } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => {
@@ -15,7 +15,11 @@ const mocks = vi.hoisted(() => {
personalSpace,
channels: [personalSpace],
channelsLoading: false,
- useLoops: vi.fn(() => ({ data: [], isLoading: false, isError: false })),
+ useLoops: vi.fn(() => ({
+ data: [] as LoopSchemas.Loop[],
+ isLoading: false,
+ isError: false,
+ })),
};
});
@@ -57,7 +61,7 @@ vi.mock("@posthog/ui/features/loops/components/LoopFallbacks", () => ({
LoopsSkeleton: () => <div>Loading loops</div>,
}));
vi.mock("@posthog/ui/features/loops/components/LoopRow", () => ({
- LoopRow: () => null,
+ LoopRow: ({ loop }: { loop: { name: string } }) => <div>{loop.name}</div>,
}));
vi.mock("@posthog/ui/features/loops/components/LoopsEmptyState", () => ({
LoopsEmptyState: () => null,
@@ -65,29 +69,49 @@ vi.mock("@posthog/ui/features/loops/components/LoopsEmptyState", () => ({
vi.mock("@posthog/ui/features/loops/components/LoopTemplatesSection", () => ({
LoopTemplatesSection: () => null,
}));
-vi.mock("@posthog/ui/features/loops/components/LoopsListView", () => ({
- LoopsListView: ({ headerContent }: { headerContent?: ReactNode }) => (
- <div>
- {headerContent}
- Project loops registry
- </div>
- ),
-}));
import { WebsiteChannelLoops } from "./WebsiteChannelLoops";
+function loop(
+ id: string,
+ name: string,
+ folderId: string | null,
+): LoopSchemas.Loop {
+ return {
+ id,
+ name,
+ context_target: folderId ? { folder_id: folderId, name: folderId } : null,
+ } as LoopSchemas.Loop;
+}
+
describe("WebsiteChannelLoops", () => {
beforeEach(() => {
mocks.channels = [mocks.personalSpace];
mocks.channelsLoading = false;
- mocks.useLoops.mockClear();
+ mocks.useLoops.mockReset();
+ mocks.useLoops.mockReturnValue({
+ data: [],
+ isLoading: false,
+ isError: false,
+ });
});
- it("shows the project loops registry in the personal space", () => {
+ it("shows only loops attached to the personal space", () => {
+ mocks.useLoops.mockReturnValue({
+ data: [
+ loop("a", "Mine", "personal-space"),
+ loop("b", "Unattached", null),
+ loop("c", "Elsewhere", "other"),
+ ],
+ isLoading: false,
+ isError: false,
+ });
+
render(<WebsiteChannelLoops channelId="personal-space" />);
- expect(screen.getByText("Project loops registry")).toBeInTheDocument();
- expect(screen.getByText("Personal space header")).toBeInTheDocument();
+ expect(screen.getByText("Mine")).toBeInTheDocument();
+ expect(screen.queryByText("Unattached")).not.toBeInTheDocument();
+ expect(screen.queryByText("Elsewhere")).not.toBeInTheDocument();
});
it("waits for the Personal space to resolve before choosing a list", () => {
@@ -97,9 +121,6 @@ describe("WebsiteChannelLoops", () => {
render(<WebsiteChannelLoops channelId="personal-space" />);
expect(screen.getByText("Loading loops")).toBeInTheDocument();
- expect(
- screen.queryByText("Project loops registry"),
- ).not.toBeInTheDocument();
expect(mocks.useLoops).not.toHaveBeenCalled();
});
});
diff --git a/products/desktop/packages/ui/src/features/canvas/components/WebsiteChannelLoops.tsx b/products/desktop/packages/ui/src/features/canvas/components/WebsiteChannelLoops.tsx
index 0e40c5c376b3..a6351dbbf8ec 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/WebsiteChannelLoops.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/WebsiteChannelLoops.tsx
@@ -23,7 +23,6 @@ import {
} from "../../loops/components/LoopFallbacks";
import { LoopRow } from "../../loops/components/LoopRow";
import { LoopsEmptyState } from "../../loops/components/LoopsEmptyState";
-import { LoopsListView } from "../../loops/components/LoopsListView";
import { LoopTemplatesSection } from "../../loops/components/LoopTemplatesSection";
import { useLoopLimits, useLoops } from "../../loops/hooks/useLoops";
import { useLoopDraftStore } from "../../loops/loopDraftStore";
@@ -54,9 +53,7 @@ function contextQuickStarts(name: string): { label: string; prompt: string }[] {
];
}
-/** The "Loops" tab of a context: same layout as the main Loops page (list on top, agent
- * composer pinned at the bottom), but the build surface is tuned to automations that feed
- * this context. `channelId` is the desktop folder id, matching `context_target.folder_id`. */
+/** The "Loops" tab of a space, scoped to loops attached to it (Personal included; unattached loops live on the standalone Loops page). */
export function WebsiteChannelLoops({ channelId }: { channelId: string }) {
const { channels, isLoading } = useChannels();
const channel = channels.find((candidate) => candidate.id === channelId);
@@ -65,21 +62,12 @@ export function WebsiteChannelLoops({ channelId }: { channelId: string }) {
[channelId],
);
- // Don't mount the scoped scene while the route's space is unresolved. In
- // particular, that would flash a raw-id empty state for Personal before the
- // channel query identifies it as the project-level loops registry.
+ // Don't mount the scoped scene while the route's space is unresolved: it
+ // would flash a raw-id title and empty state before the name arrives.
if (isLoading && !channel) {
return <ChannelLoopsLoading headerContent={headerContent} />;
}
- // The Personal space is the project-level home for loops in the spaces
- // layout. API-created and other unattached loops have no context_target, so
- // rendering the space-scoped list here incorrectly produces the global
- // "Create your first loop" empty state while those loops already exist.
- if (channel?.channelType === "personal") {
- return <LoopsListView headerContent={headerContent} />;
- }
-
return (
<SpaceAttachedLoops
channelId={channelId}