Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit 36353aa

Browse files
authored
fix(loops): Improve loop detail back navigation (#3876)
1 parent d94111c commit 36353aa

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

packages/ui/src/features/loops/components/LoopDetailView.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ import { TimezoneTimestamp } from "@posthog/ui/primitives/TimezoneTimestamp";
2727
import { systemTimezone } from "@posthog/ui/primitives/timezone";
2828
import { toast } from "@posthog/ui/primitives/toast";
2929
import {
30+
canGoBackInHistory,
31+
goBackInHistory,
3032
navigateToEditLoop,
3133
navigateToLoops,
3234
} from "@posthog/ui/router/navigationBridge";
3335
import { track } from "@posthog/ui/shell/analytics";
3436
import { useHostCapabilities } from "@posthog/ui/shell/useHostCapabilities";
3537
import { Flex, Text } from "@radix-ui/themes";
3638
import { useQuery } from "@tanstack/react-query";
39+
import { useLocation } from "@tanstack/react-router";
3740
import { useEffect, useRef, useState } from "react";
3841
import { useLoop } from "../hooks/useLoop";
3942
import {
@@ -62,6 +65,9 @@ import { LoopLoadError } from "./LoopFallbacks";
6265
import { LoopRunRow } from "./LoopRunRow";
6366

6467
export function LoopDetailView({ loopId }: { loopId: string }) {
68+
const hasLoopListOrigin = useLocation({
69+
select: (location) => location.state.loopListOrigin === true,
70+
});
6571
const { data: loop, isLoading, isError } = useLoop(loopId);
6672
const updateLoop = useUpdateLoop(loopId);
6773
const deleteLoop = useDeleteLoop();
@@ -207,11 +213,17 @@ export function LoopDetailView({ loopId }: { loopId: string }) {
207213
<Button
208214
variant="link-muted"
209215
size="sm"
210-
onClick={navigateToLoops}
216+
onClick={() => {
217+
if (hasLoopListOrigin && canGoBackInHistory()) {
218+
goBackInHistory();
219+
return;
220+
}
221+
navigateToLoops();
222+
}}
211223
className="w-fit px-0"
212224
>
213225
<ArrowLeftIcon size={15} />
214-
Loops
226+
Back
215227
</Button>
216228

217229
<Flex align="center" justify="between" gap="3" wrap="wrap">

packages/ui/src/features/loops/components/LoopRow.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import {
1212
summarizeNotificationDestinations,
1313
} from "../loopDisplay";
1414

15+
declare module "@tanstack/react-router" {
16+
interface HistoryState {
17+
loopListOrigin?: boolean;
18+
}
19+
}
20+
1521
export function LoopRow({
1622
loop,
1723
creator,
@@ -55,6 +61,7 @@ export function LoopRow({
5561
<Link
5662
to="/code/loops/$loopId"
5763
params={{ loopId: loop.id }}
64+
state={{ loopListOrigin: true }}
5865
className="flex items-center justify-between gap-3 rounded-(--radius-2) border border-border bg-(--color-panel-solid) px-4 py-3.5 no-underline transition-colors duration-150 hover:border-(--gray-6) hover:bg-(--gray-2)"
5966
>
6067
<Flex align="center" gap="3" className="min-w-0">

0 commit comments

Comments
 (0)