: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, selectors } from 'kea'
import { urlToAction } from 'kea-router'
import { GroupsAccessStatus } from 'lib/introductions/groupsAccessLogic'
import { capitalizeFirstLetter } from 'lib/utils/strings'
import { Scene } from 'scenes/sceneTypes'
import { urls } from 'scenes/urls'
import { groupsModel } from '~/models/groupsModel'
import { Breadcrumb } from '~/types'
import type { Noun } from '../../../../frontend/src/models/groupsModel'
import type { GroupType, GroupTypeIndex } from '../../../../frontend/src/types'
export type GroupsTab = {
key: string
url: string
label: string
content: any
buttons?: any
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface groupsSceneLogicValues {
aggregationLabel: (groupTypeIndex: number | null | undefined, deferToUserWording?: boolean) => Noun // groupsModel
groupTypes: Map<GroupTypeIndex, GroupType> // groupsModel
groupTypesLoading: boolean // groupsModel
groupsAccessStatus: GroupsAccessStatus // groupsModel
breadcrumbs: Breadcrumb[]
groupTypeIndex: number
groupTypeName: string
groupTypeNamePlural: string
showGroupsIntroductionPage: boolean
tabs: GroupsTab[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface groupsSceneLogicActions {
setGroupTypeIndex: (groupTypeIndex: number) => {
groupTypeIndex: number
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface groupsSceneLogicMeta {
__keaTypeGenInternalSelectorTypes: {
groupTypeName: (
aggregationLabel: (groupTypeIndex: number | null | undefined, deferToUserWording?: boolean) => Noun,
groupTypeIndex: number
) => string
groupTypeNamePlural: (
aggregationLabel: (groupTypeIndex: number | null | undefined, deferToUserWording?: boolean) => Noun,
groupTypeIndex: number
) => string
breadcrumbs: (
groupTypeIndex: number,
groupTypeNamePlural: string,
showGroupsIntroductionPage: boolean
) => Breadcrumb[]
showGroupsIntroductionPage: (groupsAccessStatus: GroupsAccessStatus) => boolean
}
}
export type groupsSceneLogicType = MakeLogicType<
groupsSceneLogicValues,
groupsSceneLogicActions,
Record<string, any>,
groupsSceneLogicMeta
>
export const groupsSceneLogic = kea<groupsSceneLogicType>([
path(['scenes', 'groups', 'groupsSceneLogic']),
connect(() => ({
values: [groupsModel, ['aggregationLabel', 'groupTypes', 'groupTypesLoading', 'groupsAccessStatus']],
})),
actions({
setGroupTypeIndex: (groupTypeIndex: number) => ({ groupTypeIndex }),
}),
reducers({
groupTypeIndex: [
0,
{
setGroupTypeIndex: (_, { groupTypeIndex }) => groupTypeIndex,
},
],
}),
selectors({
tabs: [
() => [],
(): GroupsTab[] => {
return []
},
],
groupTypeName: [
(s) => [s.aggregationLabel, s.groupTypeIndex],
(
aggregationLabel: (
groupTypeIndex: number | null | undefined,
deferToUserWording?: boolean
) => import('~/models/groupsModel').Noun,
groupTypeIndex: number
): string => {
return aggregationLabel(groupTypeIndex).singular
},
],
groupTypeNamePlural: [
(s) => [s.aggregationLabel, s.groupTypeIndex],
(
aggregationLabel: (
groupTypeIndex: number | null | undefined,
deferToUserWording?: boolean
) => import('~/models/groupsModel').Noun,
groupTypeIndex: number
): string => {
return aggregationLabel(groupTypeIndex).plural
},
],
breadcrumbs: [
(s) => [s.groupTypeIndex, s.groupTypeNamePlural, s.showGroupsIntroductionPage],
(
groupTypeIndex: number,
groupTypeNamePlural: string,
showGroupsIntroductionPage: boolean
): Breadcrumb[] => {
return [
{
key: Scene.Groups,
name: showGroupsIntroductionPage ? 'Groups' : capitalizeFirstLetter(groupTypeNamePlural),
path: urls.groups(groupTypeIndex),
iconType: 'group',
},
]
},
],
showGroupsIntroductionPage: [
(s) => [s.groupsAccessStatus],
(groupsAccessStatus: GroupsAccessStatus): boolean => {
return [
GroupsAccessStatus.HasAccess,
GroupsAccessStatus.HasGroupTypes,
GroupsAccessStatus.NoAccess,
].includes(groupsAccessStatus)
},
],
}),
urlToAction(({ actions }) => ({
[urls.groups(':key')]: ({ key }) => {
if (key) {
actions.setGroupTypeIndex(parseInt(key))
}
},
})),
])