: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, listeners, path, reducers } from 'kea'
import { actionToUrl, urlToAction } from 'kea-router'
import { addSavedInsightsModalLogic } from 'scenes/saved-insights/addSavedInsightsModalLogic'
import { urls } from 'scenes/urls'
import { InsightModel } from '~/types'
import type { Node } from '../../../frontend/src/queries/schema/schema-general'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface insightPickerEndpointModalLogicValues {
isOpen: boolean
selectedInsight: InsightModel | null
showMoreInsightTypes: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface insightPickerEndpointModalLogicActions {
clearSelectedInsight: () => {
value: true
}
closeModal: () => {
value: true
}
openModal: () => {
value: true
}
selectInsight: (insight: InsightModel) => {
insight: InsightModel<Node<Record<string, any>>>
}
toggleShowMoreInsightTypes: () => {
value: true
}
}
export type insightPickerEndpointModalLogicType = MakeLogicType<
insightPickerEndpointModalLogicValues,
insightPickerEndpointModalLogicActions
>
export const insightPickerEndpointModalLogic = kea<insightPickerEndpointModalLogicType>([
path(['products', 'endpoints', 'frontend', 'insightPickerEndpointModalLogic']),
actions({
openModal: true,
closeModal: true,
selectInsight: (insight: InsightModel) => ({ insight }),
clearSelectedInsight: true,
toggleShowMoreInsightTypes: true,
}),
reducers({
isOpen: [
false,
{
openModal: () => true,
closeModal: () => false,
},
],
selectedInsight: [
null as InsightModel | null,
{
selectInsight: (_, { insight }) => insight,
clearSelectedInsight: () => null,
closeModal: () => null,
},
],
showMoreInsightTypes: [
false,
{
toggleShowMoreInsightTypes: (state) => !state,
closeModal: () => false,
},
],
}),
listeners(() => ({
closeModal: () => {
addSavedInsightsModalLogic.findMounted()?.actions.setModalFilters({}, false)
},
})),
actionToUrl(() => ({
openModal: () => [urls.endpoints(), { new: 'insight' }],
closeModal: () => [urls.endpoints(), {}],
})),
urlToAction(({ actions, values }) => ({
[urls.endpoints()]: (_, searchParams) => {
if (searchParams.new === 'insight' && !values.isOpen) {
actions.openModal()
} else if (searchParams.new !== 'insight' && values.isOpen) {
actions.closeModal()
}
},
})),
])