11import { CaretRightIcon , RepeatIcon } from "@phosphor-icons/react" ;
22import type { LoopSchemas } from "@posthog/api-client/loops" ;
3+ import type { UserBasic } from "@posthog/shared/domain-types" ;
4+ import { userDisplayName } from "@posthog/ui/features/canvas/utils/userDisplay" ;
35import { Badge } from "@posthog/ui/primitives/Badge" ;
46import { Flex , Text } from "@radix-ui/themes" ;
57import { Link } from "@tanstack/react-router" ;
6- import { loopStatusColor , loopStatusLabel } from "../loopDisplay" ;
8+ import {
9+ loopStatusColor ,
10+ loopStatusLabel ,
11+ summarizeNotificationDestinations ,
12+ } from "../loopDisplay" ;
13+
14+ export function LoopRow ( {
15+ loop,
16+ creator,
17+ creatorLoading = false ,
18+ creatorError = false ,
19+ creatorLookupComplete = true ,
20+ } : {
21+ loop : LoopSchemas . Loop ;
22+ creator ?: UserBasic ;
23+ creatorLoading ?: boolean ;
24+ creatorError ?: boolean ;
25+ creatorLookupComplete ?: boolean ;
26+ } ) {
27+ const description = loop . description . trim ( ) ;
28+ const triggerLabel = loop . triggers . length === 1 ? "trigger" : "triggers" ;
29+ const triggerSummary =
30+ loop . triggers . length === 0
31+ ? "No triggers configured"
32+ : `${ loop . triggers . length } ${ triggerLabel } ` ;
33+
34+ let creatorLabel : string | null = null ;
35+ if ( loop . visibility === "team" && creatorError ) {
36+ creatorLabel = "Creator unavailable" ;
37+ } else if (
38+ loop . visibility === "team" &&
39+ ! creatorLoading &&
40+ ! creatorLookupComplete
41+ ) {
42+ creatorLabel = "Creator unavailable" ;
43+ } else if ( loop . visibility === "team" && ! creatorLoading ) {
44+ creatorLabel = creator
45+ ? `Created by ${ userDisplayName ( creator ) } `
46+ : "Created by a former organization member" ;
47+ }
48+
49+ const metadata = [ triggerSummary ] ;
50+ const notificationDestinations = summarizeNotificationDestinations (
51+ loop . notifications ,
52+ ) ;
53+ if ( notificationDestinations . length > 0 ) {
54+ metadata . push ( `Notifications: ${ notificationDestinations . join ( ", " ) } ` ) ;
55+ }
56+ if ( creatorLabel ) metadata . push ( creatorLabel ) ;
757
8- export function LoopRow ( { loop } : { loop : LoopSchemas . Loop } ) {
958 return (
1059 < Link
1160 to = "/code/loops/$loopId"
@@ -22,13 +71,14 @@ export function LoopRow({ loop }: { loop: LoopSchemas.Loop }) {
2271 < Badge color = { loopStatusColor ( loop ) } > { loopStatusLabel ( loop ) } </ Badge >
2372 < Badge color = "gray" > { loop . visibility } </ Badge >
2473 </ Flex >
25- < Text className = "truncate text-[12px] text-gray-11 leading-snug" >
26- { loop . description . trim ( )
27- ? loop . description
28- : loop . triggers . length === 0
29- ? "No triggers configured"
30- : `${ loop . triggers . length } trigger${ loop . triggers . length === 1 ? "" : "s" } ` }
74+ < Text className = "text-[12px] text-gray-11 leading-snug" >
75+ { metadata . join ( " · " ) }
3176 </ Text >
77+ { description ? (
78+ < Text className = "truncate text-[12px] text-gray-10 leading-snug" >
79+ { description }
80+ </ Text >
81+ ) : null }
3282 </ Flex >
3383 </ Flex >
3484 < Flex align = "center" gap = "3" className = "shrink-0" >
0 commit comments