Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand All @@ -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",
Expand All @@ -81,31 +80,30 @@ describe("LoopsListViewPresentation", () => {
loop("mine-team", "team"),
loop("teammate-team", "team", 2),
]}
currentUserId={1}
members={[currentUser]}
onStartBlank={vi.fn()}
onStartFromTemplate={vi.fn()}
/>
</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 current@example.com",
),
).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 current@example.com",
),
).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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -166,7 +150,6 @@ export function LoopsListView({

interface LoopsListViewPresentationProps {
loops: LoopSchemas.Loop[];
currentUserId?: number | null;
isLoading?: boolean;
error?: unknown;
limitReason?: string | null;
Expand All @@ -183,7 +166,6 @@ interface LoopsListViewPresentationProps {

export function LoopsListViewPresentation({
loops,
currentUserId = null,
isLoading = false,
error = null,
limitReason = null,
Expand All @@ -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
Expand Down
Loading