: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 { MakeLogicType, actions, kea, key, path, props, reducers, selectors } from 'kea'
import { SessionRecordingId } from '~/types'
export interface WindowIdRegistryLogicProps {
sessionRecordingId: SessionRecordingId
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface windowIdRegistryLogicValues {
getWindowId: (uuid: string | undefined) => number | undefined
uuidToIndex: Record<string, number>
windowIds: number[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface windowIdRegistryLogicActions {
registerWindowId: (uuid: string) => {
uuid: string
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface windowIdRegistryLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
getWindowId: (uuidToIndex: Record<string, number>) => (uuid: string | undefined) => number | undefined
windowIds: (uuidToIndex: Record<string, number>) => number[]
}
}
export type windowIdRegistryLogicType = MakeLogicType<
windowIdRegistryLogicValues,
windowIdRegistryLogicActions,
WindowIdRegistryLogicProps,
windowIdRegistryLogicMeta
>
export const windowIdRegistryLogic = kea<windowIdRegistryLogicType>([
path((key) => ['scenes', 'session-recordings', 'windowIdRegistryLogic', key]),
props({} as WindowIdRegistryLogicProps),
key(({ sessionRecordingId }) => sessionRecordingId || 'no-session-recording-id'),
actions({
registerWindowId: (uuid: string) => ({ uuid }),
}),
reducers({
uuidToIndex: [
{} as Record<string, number>,
{
registerWindowId: (state, { uuid }) => {
if (uuid in state) {
return state
}
return { ...state, [uuid]: Object.keys(state).length + 1 }
},
},
],
}),
selectors({
getWindowId: [
(s) => [s.uuidToIndex],
(uuidToIndex: Record<string, number>) =>
(uuid: string | undefined): number | undefined => {
if (!uuid) {
return undefined
}
return uuidToIndex[uuid]
},
],
windowIds: [
(s) => [s.uuidToIndex],
(uuidToIndex: Record<string, number>): number[] => Object.values(uuidToIndex).sort((a, b) => a - b),
],
}),
])