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(loops): group loops by visibility (#81654)

Benjamin Knofe-Vider00f50ad72d64
diff --git a/products/desktop/packages/ui/src/features/loops/components/LoopsListView.test.tsx b/products/desktop/packages/ui/src/features/loops/components/LoopsListView.test.tsx
index 52308d1e835a..a68ef64b5715 100644
--- a/products/desktop/packages/ui/src/features/loops/components/LoopsListView.test.tsx
+++ b/products/desktop/packages/ui/src/features/loops/components/LoopsListView.test.tsx
@@ -48,12 +48,11 @@ function controlledPanel(tab: HTMLElement): HTMLElement {
}
describe("LoopsListViewPresentation", () => {
- it("does not render ownership groups while identity is loading", () => {
+ it("does not render visibility groups while loops are loading", () => {
render(
<Theme>
<LoopsListViewPresentation
loops={[loop("mine-team", "team")]}
- currentUserId={null}
isLoading
onStartBlank={vi.fn()}
onStartFromTemplate={vi.fn()}
@@ -67,7 +66,7 @@ describe("LoopsListViewPresentation", () => {
// The triggers sit in the page header and the panels stay in the scrolling
// body — one Tabs root spanning both, so switching has to keep working
// across that split.
- it("groups loops by ownership rather than visibility", async () => {
+ it("groups loops by visibility regardless of their creator", async () => {
const currentUser: UserBasic = {
id: 1,
uuid: "current-user",
@@ -81,7 +80,6 @@ describe("LoopsListViewPresentation", () => {
loop("mine-team", "team"),
loop("teammate-team", "team", 2),
]}
- currentUserId={1}
members={[currentUser]}
onStartBlank={vi.fn()}
onStartFromTemplate={vi.fn()}
@@ -89,23 +87,23 @@ describe("LoopsListViewPresentation", () => {
</Theme>,
);
- const personalTab = screen.getByRole("tab", { name: "My loops (2)" });
+ const personalTab = screen.getByRole("tab", { name: "My loops (1)" });
expect(
within(controlledPanel(personalTab)).getByText("personal loop"),
).toBeVisible();
- expect(
- within(controlledPanel(personalTab)).getByText(
- "team loop by [email protected]",
- ),
- ).toBeVisible();
- const teamTab = screen.getByRole("tab", { name: "Team loops (1)" });
+ const teamTab = screen.getByRole("tab", { name: "Team loops (2)" });
await userEvent.click(teamTab);
expect(teamTab).toHaveAttribute("aria-selected", "true");
expect(
- within(controlledPanel(teamTab)).getByText("team loop"),
+ within(controlledPanel(teamTab)).getByText(
+ "team loop by [email protected]",
+ ),
).toBeVisible();
+ expect(
+ within(controlledPanel(teamTab)).getAllByText(/team loop/),
+ ).toHaveLength(2);
// The deselected panel is inert, then unmounts when its transition ends.
await waitFor(() =>
expect(screen.queryByText("personal loop")).not.toBeInTheDocument(),
diff --git a/products/desktop/packages/ui/src/features/loops/components/LoopsListView.tsx b/products/desktop/packages/ui/src/features/loops/components/LoopsListView.tsx
index e9f4be9a66e8..4aa69ef48830 100644
--- a/products/desktop/packages/ui/src/features/loops/components/LoopsListView.tsx
+++ b/products/desktop/packages/ui/src/features/loops/components/LoopsListView.tsx
@@ -3,8 +3,6 @@ import type { LoopSchemas } from "@posthog/api-client/loops";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@posthog/quill";
import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";
import type { UserBasic } from "@posthog/shared/domain-types";
-import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
-import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser";
import { useOrgMembers } from "@posthog/ui/features/canvas/hooks/useOrgMembers";
import { StopCloudRunDialog } from "@posthog/ui/features/sessions/components/StopCloudRunDialog";
import { useSetHeaderContent } from "@posthog/ui/hooks/useSetHeaderContent";
@@ -78,22 +76,9 @@ export function LoopsListView({
headerContent?: ReactNode;
}) {
const { data: loops, isLoading, isError, error } = useLoops();
- const authenticatedClient = useOptionalAuthenticatedClient();
- const {
- data: currentUser,
- isLoading: currentUserLoading,
- isError: currentUserError,
- error: currentUserQueryError,
- } = useCurrentUser({ client: authenticatedClient });
const limits = useLoopLimits();
const limitReason =
limits?.atLimit === true ? loopLimitReason(limits.max) : null;
- let listError: unknown = null;
- if (isError) {
- listError = error;
- } else if (currentUserError) {
- listError = currentUserQueryError;
- }
// The standalone page names itself in-page and has no breadcrumb. When the
// registry is hosted inside a space, its caller supplies that navigation
@@ -147,9 +132,8 @@ export function LoopsListView({
return (
<LoopsListViewPresentation
loops={allLoops}
- currentUserId={currentUser?.id ?? null}
- isLoading={isLoading || currentUserLoading}
- error={listError}
+ isLoading={isLoading}
+ error={isError ? error : null}
limitReason={limitReason}
members={members}
membersLoading={membersLoading}
@@ -166,7 +150,6 @@ export function LoopsListView({
interface LoopsListViewPresentationProps {
loops: LoopSchemas.Loop[];
- currentUserId?: number | null;
isLoading?: boolean;
error?: unknown;
limitReason?: string | null;
@@ -183,7 +166,6 @@ interface LoopsListViewPresentationProps {
export function LoopsListViewPresentation({
loops,
- currentUserId = null,
isLoading = false,
error = null,
limitReason = null,
@@ -197,16 +179,8 @@ export function LoopsListViewPresentation({
onResumeBuilderSession,
onBuilderSessionStopped,
}: LoopsListViewPresentationProps) {
- const personalLoops = loops.filter(
- (loop) =>
- loop.visibility === "personal" ||
- (currentUserId !== null && loop.created_by_id === currentUserId),
- );
- const teamLoops = loops.filter(
- (loop) =>
- loop.visibility === "team" &&
- (currentUserId === null || loop.created_by_id !== currentUserId),
- );
+ const personalLoops = loops.filter((loop) => loop.visibility === "personal");
+ const teamLoops = loops.filter((loop) => loop.visibility === "team");
const createButton = (
<Button