: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { useActions, useValues } from 'kea'
import { LemonSkeleton } from '@posthog/lemon-ui'
import { NotFound } from 'lib/components/NotFound'
import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'
import { NotebookNodeProps, NotebookNodeType } from 'scenes/notebooks/types'
import { PersonType } from '~/types'
import { personLogic } from 'products/persons/frontend/logics/personLogic'
import { getCustomerProfileRemoveMenuItem } from '../customerProfileNotebookNodeMenu'
import { createPostHogWidgetNode } from '../NodeWrapper'
import { notebookNodeLogic } from '../notebookNodeLogic'
import { notebookNodePersonFeedLogic } from './notebookNodePersonFeedLogic'
import { Session } from './Session'
const FeedSkeleton = (): JSX.Element => (
<div className="deprecated-space-y-4 p-4">
<LemonSkeleton className="h-8" repeat={10} />
</div>
)
type FeedProps = {
person: PersonType
}
const Feed = ({ person }: FeedProps): JSX.Element => {
const id = person.id ?? 'missing'
const { sessions, sessionsLoading } = useValues(notebookNodePersonFeedLogic({ personId: id }))
if (!sessions && sessionsLoading) {
return <FeedSkeleton />
} else if (sessions === null) {
return <NotFound object="person" />
}
return (
<div className="p-2">
<h3 className="font-semibold mb-2">Session timeline</h3>
{sessions.map((session: any) => (
<Session key={session.sessionId} session={session} />
))}
</div>
)
}
const Component = ({ attributes }: NotebookNodeProps<NotebookNodePersonFeedAttributes>): JSX.Element | null => {
const { id, distinctId } = attributes
const { expanded, notebookLogic } = useValues(notebookNodeLogic)
const mountedPersonFeedLogic = notebookNodePersonFeedLogic({ personId: id })
useAttachedLogic(mountedPersonFeedLogic, notebookLogic)
const { setMenuItems } = useActions(notebookNodeLogic)
const logic = personLogic({ id, distinctId })
const { person, personLoading } = useValues(logic)
useOnMountEffect(() => {
const removeMenuItem = getCustomerProfileRemoveMenuItem(NotebookNodeType.PersonFeed)
if (removeMenuItem) {
setMenuItems([removeMenuItem])
}
})
if (!expanded) {
return null
}
if (personLoading) {
return <FeedSkeleton />
} else if (!person) {
return <NotFound object="person" />
}
return <Feed person={person} />
}
type NotebookNodePersonFeedAttributes = {
id: string
distinctId: string
}
export const NotebookNodePersonFeed = createPostHogWidgetNode<NotebookNodePersonFeedAttributes>({
nodeType: NotebookNodeType.PersonFeed,
titlePlaceholder: 'Feed',
Component,
resizeable: false,
expandable: true,
startExpanded: true,
attributes: {
id: {},
distinctId: {},
},
})