-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
367b44a
commit 8a188cc
Showing
18 changed files
with
27,518 additions
and
17 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
frontend/src/scenes/notebooks/Nodes/NotebookNodePersonFeed/EventIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { EventType } from '~/types' | ||
|
||
import { Tooltip } from '@posthog/lemon-ui' | ||
import { IconAdsClick, IconExclamation, IconEyeHidden, IconEyeVisible, IconCode } from 'lib/lemon-ui/icons' | ||
import { KEY_MAPPING } from 'lib/taxonomy' | ||
|
||
type EventIconProps = { event: EventType } | ||
|
||
export const EventIcon = ({ event }: EventIconProps): JSX.Element => { | ||
let Component: React.ComponentType<{ className: string }> | ||
switch (event.event) { | ||
case '$pageview': | ||
Component = IconEyeVisible | ||
break | ||
case '$pageleave': | ||
Component = IconEyeHidden | ||
break | ||
case '$autocapture': | ||
Component = IconAdsClick | ||
break | ||
case '$rageclick': | ||
Component = IconExclamation | ||
break | ||
default: | ||
Component = IconCode | ||
} | ||
return ( | ||
<Tooltip title={`${KEY_MAPPING.event[event.event]?.label || 'Custom'} event`}> | ||
<Component className="text-2xl text-muted" /> | ||
</Tooltip> | ||
) | ||
} |
70 changes: 70 additions & 0 deletions
70
frontend/src/scenes/notebooks/Nodes/NotebookNodePersonFeed/NotebookNodePersonFeed.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { useValues } from 'kea' | ||
|
||
import { LemonSkeleton } from '@posthog/lemon-ui' | ||
import { NotFound } from 'lib/components/NotFound' | ||
import { NotebookNodeType, PersonType } from '~/types' | ||
// import { TimelineEntry } from '~/queries/schema' | ||
import { NotebookNodeProps } from 'scenes/notebooks/Notebook/utils' | ||
import { personLogic } from 'scenes/persons/personLogic' | ||
import { createPostHogWidgetNode } from '../NodeWrapper' | ||
import { notebookNodePersonFeedLogic } from './notebookNodePersonFeedLogic' | ||
import { Session } from './Session' | ||
|
||
const FeedSkeleton = (): JSX.Element => ( | ||
<div className="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"> | ||
{sessions.map((session: any) => ( | ||
<Session key={session.sessionId} session={session} /> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
const Component = ({ attributes }: NotebookNodeProps<NotebookNodePersonFeedAttributes>): JSX.Element => { | ||
const { id } = attributes | ||
|
||
const logic = personLogic({ id }) | ||
const { person, personLoading } = useValues(logic) | ||
|
||
if (personLoading) { | ||
return <FeedSkeleton /> | ||
} else if (!person) { | ||
return <NotFound object="person" /> | ||
} | ||
|
||
return <Feed person={person} /> | ||
} | ||
|
||
type NotebookNodePersonFeedAttributes = { | ||
id: string | ||
} | ||
|
||
export const NotebookNodePersonFeed = createPostHogWidgetNode<NotebookNodePersonFeedAttributes>({ | ||
nodeType: NotebookNodeType.PersonFeed, | ||
titlePlaceholder: 'Feed', | ||
Component, | ||
resizeable: false, | ||
expandable: false, | ||
attributes: { | ||
id: {}, | ||
}, | ||
}) |
89 changes: 89 additions & 0 deletions
89
frontend/src/scenes/notebooks/Nodes/NotebookNodePersonFeed/Session.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { useState } from 'react' | ||
import { useActions, useValues } from 'kea' | ||
|
||
import { LemonButton } from '@posthog/lemon-ui' | ||
import { IconRewindPlay } from '@posthog/icons' | ||
import { dayjs } from 'lib/dayjs' | ||
// import { TimelineEntry } from '~/queries/schema' | ||
import { NotebookNodeType } from '~/types' | ||
import { IconUnfoldLess, IconUnfoldMore } from 'lib/lemon-ui/icons' | ||
import { humanFriendlyDetailedTime, humanFriendlyDuration } from 'lib/utils' | ||
import { SessionEvent } from './SessionEvent' | ||
import { notebookNodeLogic } from '../notebookNodeLogic' | ||
|
||
type SessionProps = { | ||
session: any // TimelineEntry | ||
} | ||
|
||
export const Session = ({ session }: SessionProps): JSX.Element => { | ||
const { children, nodeId } = useValues(notebookNodeLogic) | ||
const { updateAttributes } = useActions(notebookNodeLogic) | ||
|
||
const startTime = dayjs(session.events[0].timestamp) | ||
const endTime = dayjs(session.events[session.events.length - 1].timestamp) | ||
const durationSeconds = endTime.diff(startTime, 'second') | ||
|
||
const [isFolded, setIsFolded] = useState(false) | ||
|
||
const onOpenReplay = (): void => { | ||
const newChildren = [...children] || [] | ||
|
||
const existingChild = newChildren.find((child) => child.attrs?.nodeId === `${nodeId}-active-replay`) | ||
|
||
if (existingChild) { | ||
existingChild.attrs.id = session.sessionId | ||
} else { | ||
newChildren.splice(0, 0, { | ||
type: NotebookNodeType.Recording, | ||
attrs: { | ||
id: session.sessionId, | ||
nodeId: `${nodeId}-active-replay`, | ||
height: '5rem', | ||
__init: { | ||
expanded: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
updateAttributes({ | ||
children: newChildren, | ||
}) | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col rounded bg-side border overflow-hidden mb-3" title={session.sessionId}> | ||
<div className="flex items-center justify-between bg-bg-light p-0.5 pr-2 text-xs"> | ||
<div className="flex items-center"> | ||
<LemonButton | ||
size="small" | ||
icon={isFolded ? <IconUnfoldMore /> : <IconUnfoldLess />} | ||
status="stealth" | ||
onClick={() => setIsFolded((state) => !state)} | ||
/> | ||
<span className="font-bold ml-2">{humanFriendlyDetailedTime(startTime)}</span> | ||
</div> | ||
<div className="flex items-center"> | ||
<span> | ||
<b>{session.events.length} events</b> in <b>{humanFriendlyDuration(durationSeconds)}</b> | ||
</span> | ||
{session.recording_duration_s ? ( | ||
<LemonButton | ||
className="ml-1" | ||
size="small" | ||
icon={<IconRewindPlay />} | ||
onClick={() => onOpenReplay()} | ||
/> | ||
) : null} | ||
</div> | ||
</div> | ||
{!isFolded && ( | ||
<div className="p-1 border-t space-y-1"> | ||
{session.events.map((event: any) => ( | ||
<SessionEvent key={event.id} event={event} /> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
frontend/src/scenes/notebooks/Nodes/NotebookNodePersonFeed/SessionEvent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { EventType } from '~/types' | ||
import { eventToDescription } from 'lib/utils' | ||
import { dayjs } from 'lib/dayjs' | ||
import { EventIcon } from './EventIcon' | ||
|
||
type SessionEventProps = { event: EventType } | ||
|
||
export const SessionEvent = ({ event }: SessionEventProps): JSX.Element => ( | ||
<div className="relative flex items-center justify-between border rounded pl-3 pr-4 py-1 bg-bg-light text-xs"> | ||
<div className="flex items-center"> | ||
<EventIcon event={event} /> | ||
<b className="ml-3">{eventToDescription(event)}</b> | ||
</div> | ||
<div className="flex items-center text-muted font-bold"> | ||
<span>{dayjs(event.timestamp).format('h:mm:ss A')}</span> | ||
</div> | ||
</div> | ||
) |
Oops, something went wrong.