Skip to content

: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.

perf(replay): move the unwatched dot and property icons to their own files (#110354)

Paul D'Ambra7c26f6034f82
diff --git a/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx b/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx
index 248fc4b658d6..d39856234935 100644
--- a/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx
+++ b/frontend/src/lib/components/ViewRecordingButton/ViewRecordingButton.tsx
@@ -9,7 +9,7 @@ import { Dayjs, dayjs } from 'lib/dayjs'
import { IconPlayCircle } from 'lib/lemon-ui/icons'
import { newInternalTab } from 'lib/utils/newInternalTab'
import { sessionPlayerModalLogic } from 'scenes/session-recordings/player/modal/sessionPlayerModalLogic'
-import { UnwatchedIndicator } from 'scenes/session-recordings/playlist/SessionRecordingPreview'
+import { UnwatchedIndicator } from 'scenes/session-recordings/playlist/UnwatchedIndicator'
import { urls } from 'scenes/urls'
import { MatchedRecording } from '~/types'
diff --git a/frontend/src/scenes/session-recordings/player/player-meta/countryTitleFrom.ts b/frontend/src/scenes/session-recordings/player/player-meta/countryTitleFrom.ts
new file mode 100644
index 000000000000..d7fa2bb485b6
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/player-meta/countryTitleFrom.ts
@@ -0,0 +1,19 @@
+import { COUNTRY_CODE_TO_LONG_NAME } from 'lib/utils/country'
+
+export function countryTitleFrom(
+ recordingProperties: Record<string, any> | undefined,
+ personProperties?: Record<string, any> | undefined
+): string {
+ const props = recordingProperties || personProperties
+ if (!props) {
+ return ''
+ }
+
+ // these prop names are safe between recording and person properties
+ // the "initial" person properties share the same name as the event properties
+ const country = COUNTRY_CODE_TO_LONG_NAME[props['$geoip_country_code'] as keyof typeof COUNTRY_CODE_TO_LONG_NAME]
+ const subdivision = props['$geoip_subdivision_1_name']
+ const city = props['$geoip_city_name']
+
+ return [city, subdivision, country].filter(Boolean).join(', ')
+}
diff --git a/frontend/src/scenes/session-recordings/player/player-meta/playerMetaLogic.tsx b/frontend/src/scenes/session-recordings/player/player-meta/playerMetaLogic.tsx
index bcad81eeb545..73e5a4986e4d 100644
--- a/frontend/src/scenes/session-recordings/player/player-meta/playerMetaLogic.tsx
+++ b/frontend/src/scenes/session-recordings/player/player-meta/playerMetaLogic.tsx
@@ -32,6 +32,7 @@ import { sessionRecordingsListPropertiesLogic } from '../../playlist/sessionReco
import type { MiniFilterKey } from '../inspector/miniFiltersLogic'
import { playerInspectorLogic } from '../inspector/playerInspectorLogic'
import type { InspectorListItem } from '../inspector/playerInspectorLogic'
+import { countryTitleFrom } from './countryTitleFrom'
import { sessionRecordingPinnedPropertiesLogic } from './sessionRecordingPinnedPropertiesLogic'
import { HARDCODED_DISPLAY_LABELS } from './sessionRecordingPinnedPropertiesLogic'
@@ -45,24 +46,6 @@ function canRenderDirectly(value: any): boolean {
return typeof value === 'string' || typeof value === 'number' || React.isValidElement(value)
}
-export function countryTitleFrom(
- recordingProperties: Record<string, any> | undefined,
- personProperties?: Record<string, any> | undefined
-): string {
- const props = recordingProperties || personProperties
- if (!props) {
- return ''
- }
-
- // these prop names are safe between recording and person properties
- // the "initial" person properties share the same name as the event properties
- const country = COUNTRY_CODE_TO_LONG_NAME[props['$geoip_country_code'] as keyof typeof COUNTRY_CODE_TO_LONG_NAME]
- const subdivision = props['$geoip_subdivision_1_name']
- const city = props['$geoip_city_name']
-
- return [city, subdivision, country].filter(Boolean).join(', ')
-}
-
/**
* Get human-readable property label and type information
* @param property - The property key (e.g., '$browser', 'email')
diff --git a/frontend/src/scenes/session-recordings/playlist/PropertyIcons.scss b/frontend/src/scenes/session-recordings/playlist/PropertyIcons.scss
new file mode 100644
index 000000000000..7085dd85a415
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/playlist/PropertyIcons.scss
@@ -0,0 +1,17 @@
+.SessionRecordingPreview__property-label {
+ display: none;
+ max-width: 0;
+ overflow: hidden;
+ opacity: 0;
+ transition:
+ max-width 0.2s ease,
+ opacity 0.2s ease;
+}
+
+@container preview (min-width: 30rem) {
+ .SessionRecordingPreview__property-label {
+ display: inline;
+ max-width: 6rem;
+ opacity: 1;
+ }
+}
diff --git a/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.stories.tsx b/frontend/src/scenes/session-recordings/playlist/PropertyIcons.stories.tsx
similarity index 98%
rename from frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.stories.tsx
rename to frontend/src/scenes/session-recordings/playlist/PropertyIcons.stories.tsx
index c22b0cc33ea8..62b867ea062a 100644
--- a/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.stories.tsx
+++ b/frontend/src/scenes/session-recordings/playlist/PropertyIcons.stories.tsx
@@ -4,7 +4,7 @@ import type { Meta, StoryObj } from '@storybook/react'
import { IconCursorClick, IconKeyboard } from '@posthog/icons'
-import { PropertyIcons, PropertyIconsProps } from './SessionRecordingPreview'
+import { PropertyIcons, PropertyIconsProps } from './PropertyIcons'
const meta: Meta<PropertyIconsProps> = {
title: 'Replay/Components/PropertyIcons',
diff --git a/frontend/src/scenes/session-recordings/playlist/PropertyIcons.tsx b/frontend/src/scenes/session-recordings/playlist/PropertyIcons.tsx
new file mode 100644
index 000000000000..7f4c7ea038a1
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/playlist/PropertyIcons.tsx
@@ -0,0 +1,36 @@
+import './PropertyIcons.scss'
+
+import { PropertyIcon } from 'lib/components/PropertyIcon/PropertyIcon'
+import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
+import { Tooltip } from 'lib/lemon-ui/Tooltip'
+
+import type { GatheredProperty } from './gatherIconProperties'
+
+export interface PropertyIconsProps {
+ recordingProperties: GatheredProperty[]
+ loading?: boolean
+ iconClassNames?: string
+ showTooltip?: boolean
+ showLabel?: (key: string) => boolean
+}
+
+export function PropertyIcons({ recordingProperties, loading, iconClassNames }: PropertyIconsProps): JSX.Element {
+ return (
+ <div className="flex gap-x-1 ph-no-capture">
+ {loading ? (
+ <LemonSkeleton className="w-16 h-3" />
+ ) : (
+ recordingProperties.map(({ property, value, label }) => (
+ <Tooltip key={property} title={label}>
+ <span className="flex items-center gap-x-0.5">
+ <PropertyIcon className={iconClassNames} property={property} value={value} />
+ <span className="SessionRecordingPreview__property-label text-secondary truncate">
+ {label}
+ </span>
+ </span>
+ </Tooltip>
+ ))
+ )}
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.scss b/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.scss
index 997cbc295285..c6ab78d51927 100644
--- a/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.scss
+++ b/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.scss
@@ -3,7 +3,6 @@
container-name: preview;
}
-.SessionRecordingPreview__property-label,
.SessionRecordingPreview__activity-label {
display: none;
max-width: 0;
@@ -14,14 +13,6 @@
opacity 0.2s ease;
}
-@container preview (min-width: 30rem) {
- .SessionRecordingPreview__property-label {
- display: inline;
- max-width: 6rem;
- opacity: 1;
- }
-}
-
@container preview (min-width: 35rem) {
.SessionRecordingPreview__activity-label {
display: inline;
@@ -29,13 +20,3 @@
opacity: 1;
}
}
-
-.UnwatchedIndicator {
- &.UnwatchedIndicator--primary {
- background: var(--danger);
- }
-
- &.UnwatchedIndicator--secondary {
- background: var(--color-accent);
- }
-}
diff --git a/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.tsx b/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.tsx
index 9df0af17f7fc..c18ddbe5b4bf 100644
--- a/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.tsx
+++ b/frontend/src/scenes/session-recordings/playlist/SessionRecordingPreview.tsx
@@ -7,17 +7,14 @@ import { memo } from 'react'
import { IconBug, IconCursorClick, IconHourglass, IconKeyboard, IconLive } from '@posthog/icons'
import { LemonTag } from '@posthog/lemon-ui'
-import { PropertyIcon } from 'lib/components/PropertyIcon/PropertyIcon'
import { TZLabel } from 'lib/components/TZLabel'
-import { FEATURE_FLAGS, SESSION_RECORDINGS_TTL_WARNING_THRESHOLD_DAYS } from 'lib/constants'
+import { SESSION_RECORDINGS_TTL_WARNING_THRESHOLD_DAYS } from 'lib/constants'
import { LemonCheckbox } from 'lib/lemon-ui/LemonCheckbox'
import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { colonDelimitedDuration } from 'lib/utils/durations'
import { DraggableToNotebook } from 'scenes/notebooks/AddToNotebook/DraggableToNotebook'
import { SimpleTimeLabel } from 'scenes/session-recordings/components/SimpleTimeLabel'
-import { countryTitleFrom } from 'scenes/session-recordings/player/player-meta/playerMetaLogic'
import { TimestampFormat, playerSettingsLogic } from 'scenes/session-recordings/player/playerSettingsLogic'
import { urls } from 'scenes/urls'
@@ -26,12 +23,15 @@ import { SessionRecordingType } from '~/types'
import { asDisplay } from 'products/persons/frontend/person-utils'
+import { gatherIconProperties } from './gatherIconProperties'
+import { PropertyIcons } from './PropertyIcons'
import { sessionRecordingsListPropertiesLogic } from './sessionRecordingsListPropertiesLogic'
import {
DEFAULT_RECORDING_FILTERS_ORDER_BY,
MAX_SELECTED_RECORDINGS,
sessionRecordingsPlaylistLogic,
} from './sessionRecordingsPlaylistLogic'
+import { UnwatchedIndicator } from './UnwatchedIndicator'
export interface SessionRecordingPreviewProps {
recording: SessionRecordingType
@@ -106,66 +106,6 @@ function RecordingExpiry({
)
}
-interface GatheredProperty {
- property: string
- value: string | undefined
- label: string | undefined
-}
-
-const browserIconPropertyKeys = ['$geoip_country_code', '$browser', '$device_type', '$os']
-const mobileIconPropertyKeys = ['$geoip_country_code', '$device_type', '$os_name']
-
-export function gatherIconProperties(
- recordingProperties: Record<string, any> | undefined,
- recording?: SessionRecordingType
-): GatheredProperty[] {
- const iconProperties =
- recordingProperties && Object.keys(recordingProperties).length > 0
- ? recordingProperties
- : recording?.person?.properties || {}
-
- const deviceType = iconProperties['$device_type'] || iconProperties['$initial_device_type']
- const iconPropertyKeys = deviceType === 'Mobile' ? mobileIconPropertyKeys : browserIconPropertyKeys
-
- return iconPropertyKeys
- .flatMap((property) => {
- const value = property === '$device_type' ? deviceType : iconProperties[property]
- const label = property === '$geoip_country_code' ? countryTitleFrom(iconProperties) : value
-
- return { property, value, label }
- })
- .filter((property) => !!property.value)
-}
-
-export interface PropertyIconsProps {
- recordingProperties: GatheredProperty[]
- loading?: boolean
- iconClassNames?: string
- showTooltip?: boolean
- showLabel?: (key: string) => boolean
-}
-
-export function PropertyIcons({ recordingProperties, loading, iconClassNames }: PropertyIconsProps): JSX.Element {
- return (
- <div className="flex gap-x-1 ph-no-capture">
- {loading ? (
- <LemonSkeleton className="w-16 h-3" />
- ) : (
- recordingProperties.map(({ property, value, label }) => (
- <Tooltip key={property} title={label}>
- <span className="flex items-center gap-x-0.5">
- <PropertyIcon className={iconClassNames} property={property} value={value} />
- <span className="SessionRecordingPreview__property-label text-secondary truncate">
- {label}
- </span>
- </span>
- </Tooltip>
- ))
- )}
- </div>
- )
-}
-
function FirstURL(props: { startUrl: string | undefined }): JSX.Element {
const firstPath = props.startUrl?.replace(/https?:\/\//g, '').split(/[?|#]/)[0]
return (
@@ -185,46 +125,6 @@ function RecordingOngoingIndicator(): JSX.Element {
)
}
-export function UnwatchedIndicator({ otherViewersCount }: { otherViewersCount: number }): JSX.Element {
- const { featureFlags } = useValues(featureFlagLogic)
-
- const isExcludedFromHideRecordingsMenu = featureFlags[FEATURE_FLAGS.REPLAY_EXCLUDE_FROM_HIDE_RECORDINGS_MENU]
-
- // If person wished to be excluded from the hide recordings menu, we don't show the tooltip
- const tooltip = isExcludedFromHideRecordingsMenu ? (
- <span>You have not watched this recording yet.</span>
- ) : otherViewersCount ? (
- <span>
- You have not watched this recording yet. {otherViewersCount} other{' '}
- {otherViewersCount === 1 ? 'person has' : 'people have'}.
- </span>
- ) : (
- <span>Nobody has watched this recording yet.</span>
- )
-
- return (
- <Tooltip title={tooltip}>
- <div
- className={clsx(
- 'UnwatchedIndicator w-2 h-2 rounded-full',
- isExcludedFromHideRecordingsMenu
- ? 'UnwatchedIndicator--primary'
- : otherViewersCount
- ? 'UnwatchedIndicator--secondary'
- : 'UnwatchedIndicator--primary'
- )}
- aria-label={
- isExcludedFromHideRecordingsMenu
- ? 'unwatched-recording-by-you-label'
- : otherViewersCount
- ? 'unwatched-recording-by-you-label'
- : 'unwatched-recording-by-everyone-label'
- }
- />
- </Tooltip>
- )
-}
-
function durationToShow(recording: SessionRecordingType, order: RecordingsQuery['order']): number | undefined {
return order === 'active_seconds'
? recording.active_seconds
diff --git a/frontend/src/scenes/session-recordings/playlist/UnwatchedIndicator.scss b/frontend/src/scenes/session-recordings/playlist/UnwatchedIndicator.scss
new file mode 100644
index 000000000000..f6fe6b11b818
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/playlist/UnwatchedIndicator.scss
@@ -0,0 +1,9 @@
+.UnwatchedIndicator {
+ &.UnwatchedIndicator--primary {
+ background: var(--danger);
+ }
+
+ &.UnwatchedIndicator--secondary {
+ background: var(--color-accent);
+ }
+}
diff --git a/frontend/src/scenes/session-recordings/playlist/UnwatchedIndicator.tsx b/frontend/src/scenes/session-recordings/playlist/UnwatchedIndicator.tsx
new file mode 100644
index 000000000000..4c0cc801e5b5
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/playlist/UnwatchedIndicator.tsx
@@ -0,0 +1,48 @@
+import './UnwatchedIndicator.scss'
+
+import clsx from 'clsx'
+import { useValues } from 'kea'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+export function UnwatchedIndicator({ otherViewersCount }: { otherViewersCount: number }): JSX.Element {
+ const { featureFlags } = useValues(featureFlagLogic)
+
+ const isExcludedFromHideRecordingsMenu = featureFlags[FEATURE_FLAGS.REPLAY_EXCLUDE_FROM_HIDE_RECORDINGS_MENU]
+
+ // If person wished to be excluded from the hide recordings menu, we don't show the tooltip
+ const tooltip = isExcludedFromHideRecordingsMenu ? (
+ <span>You have not watched this recording yet.</span>
+ ) : otherViewersCount ? (
+ <span>
+ You have not watched this recording yet. {otherViewersCount} other{' '}
+ {otherViewersCount === 1 ? 'person has' : 'people have'}.
+ </span>
+ ) : (
+ <span>Nobody has watched this recording yet.</span>
+ )
+
+ return (
+ <Tooltip title={tooltip}>
+ <div
+ className={clsx(
+ 'UnwatchedIndicator w-2 h-2 rounded-full',
+ isExcludedFromHideRecordingsMenu
+ ? 'UnwatchedIndicator--primary'
+ : otherViewersCount
+ ? 'UnwatchedIndicator--secondary'
+ : 'UnwatchedIndicator--primary'
+ )}
+ aria-label={
+ isExcludedFromHideRecordingsMenu
+ ? 'unwatched-recording-by-you-label'
+ : otherViewersCount
+ ? 'unwatched-recording-by-you-label'
+ : 'unwatched-recording-by-everyone-label'
+ }
+ />
+ </Tooltip>
+ )
+}
diff --git a/frontend/src/scenes/session-recordings/playlist/gatherIconProperties.ts b/frontend/src/scenes/session-recordings/playlist/gatherIconProperties.ts
new file mode 100644
index 000000000000..67ccb077dbff
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/playlist/gatherIconProperties.ts
@@ -0,0 +1,34 @@
+import { countryTitleFrom } from 'scenes/session-recordings/player/player-meta/countryTitleFrom'
+
+import { SessionRecordingType } from '~/types'
+
+export interface GatheredProperty {
+ property: string
+ value: string | undefined
+ label: string | undefined
+}
+
+const browserIconPropertyKeys = ['$geoip_country_code', '$browser', '$device_type', '$os']
+const mobileIconPropertyKeys = ['$geoip_country_code', '$device_type', '$os_name']
+
+export function gatherIconProperties(
+ recordingProperties: Record<string, any> | undefined,
+ recording?: SessionRecordingType
+): GatheredProperty[] {
+ const iconProperties =
+ recordingProperties && Object.keys(recordingProperties).length > 0
+ ? recordingProperties
+ : recording?.person?.properties || {}
+
+ const deviceType = iconProperties['$device_type'] || iconProperties['$initial_device_type']
+ const iconPropertyKeys = deviceType === 'Mobile' ? mobileIconPropertyKeys : browserIconPropertyKeys
+
+ return iconPropertyKeys
+ .flatMap((property) => {
+ const value = property === '$device_type' ? deviceType : iconProperties[property]
+ const label = property === '$geoip_country_code' ? countryTitleFrom(iconProperties) : value
+
+ return { property, value, label }
+ })
+ .filter((property) => !!property.value)
+}
diff --git a/frontend/src/scenes/trends/persons-modal/SessionActorDisplay.tsx b/frontend/src/scenes/trends/persons-modal/SessionActorDisplay.tsx
index 371f12902f68..4c15048871ed 100644
--- a/frontend/src/scenes/trends/persons-modal/SessionActorDisplay.tsx
+++ b/frontend/src/scenes/trends/persons-modal/SessionActorDisplay.tsx
@@ -1,6 +1,7 @@
import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'
import { humanFriendlyDuration } from 'lib/utils/durations'
-import { gatherIconProperties, PropertyIcons } from 'scenes/session-recordings/playlist/SessionRecordingPreview'
+import { gatherIconProperties } from 'scenes/session-recordings/playlist/gatherIconProperties'
+import { PropertyIcons } from 'scenes/session-recordings/playlist/PropertyIcons'
import { SessionActorType } from '~/types'