: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, connect, kea, path, reducers } from 'kea'
import { PERSON_DEFAULT_DISPLAY_NAME_PROPERTIES } from 'lib/constants'
import { teamLogic } from 'scenes/teamLogic'
import type { TeamPublicType, TeamType } from '../../types'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface userPreferencesLogicValues {
currentTeam: TeamPublicType | TeamType | null // teamLogic
editorVimModeEnabled: boolean
hideNullValues: boolean
hidePostHogPropertiesInTable: boolean
pinnedGroupProperties: string[]
pinnedPersonProperties: string[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface userPreferencesLogicActions {
pinGroupProperty: (prop: string) => {
prop: string
}
pinPersonProperty: (prop: string) => {
prop: string
}
setHideNullValues: (enabled: boolean) => {
enabled: boolean
}
setHidePostHogPropertiesInTable: (enabled: boolean) => {
enabled: boolean
}
unpinGroupProperty: (prop: string) => {
prop: string
}
unpinPersonProperty: (prop: string) => {
prop: string
}
}
export type userPreferencesLogicType = MakeLogicType<userPreferencesLogicValues, userPreferencesLogicActions>
// This logic is for browser stored user preferences where it's not super important that it is persisted to the server
export const userPreferencesLogic = kea<userPreferencesLogicType>([
path(['lib', 'logic', 'userPreferencesLogic']),
actions({
setHidePostHogPropertiesInTable: (enabled: boolean) => ({ enabled }),
setHideNullValues: (enabled: boolean) => ({ enabled }),
pinPersonProperty: (prop: string) => ({ prop }),
unpinPersonProperty: (prop: string) => ({ prop }),
pinGroupProperty: (prop: string) => ({ prop }),
unpinGroupProperty: (prop: string) => ({ prop }),
}),
connect(() => ({
values: [teamLogic, ['currentTeam']],
})),
reducers(({ values }) => ({
hidePostHogPropertiesInTable: [
false,
{ persist: true },
{
setHidePostHogPropertiesInTable: (_, { enabled }) => enabled,
},
],
hideNullValues: [true, { persist: true }, { setHideNullValues: (_, { enabled }) => enabled }],
pinnedPersonProperties: [
[
...(values.currentTeam?.person_display_name_properties || PERSON_DEFAULT_DISPLAY_NAME_PROPERTIES),
'$browser',
'$browser_version',
],
{ persist: true },
{
pinPersonProperty: (state, { prop }) => (state.includes(prop) ? state : [...state, prop]),
unpinPersonProperty: (state, { prop }) => state.filter((p) => p !== prop),
},
],
pinnedGroupProperties: [
['name'] as string[],
{ persist: true },
{
pinGroupProperty: (state, { prop }) => (state.includes(prop) ? state : [...state, prop]),
unpinGroupProperty: (state, { prop }) => state.filter((p) => p !== prop),
},
],
// Read-only fallback for users who turned Vim mode on before sqlEditorVimLogic saved it to their account.
// pinned: the persisted localStorage key comes from this reducer name, so renaming it drops their setting.
editorVimModeEnabled: [false, { persist: true }, {}],
})),
])