: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 { LogicWrapper, MakeLogicType, actions, kea, key, listeners, path, props, propsChanged, reducers } from 'kea'
export interface InlineListVariableSelectLogicProps {
variableId: string
selectedValues: string[]
onChange: (selectedValues: string[]) => void
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface inlineListVariableSelectLogicValues {
hasChanges: boolean
selectedValues: string[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface inlineListVariableSelectLogicActions {
commitSelectedValues: () => {
hasChanges: boolean
selectedValues: string[]
}
resetSelectedValues: (selectedValues: string[]) => {
selectedValues: string[]
}
setSelectedValues: (selectedValues: string[]) => {
selectedValues: string[]
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface inlineListVariableSelectLogicMeta {
key: string
}
export type inlineListVariableSelectLogicType = MakeLogicType<
inlineListVariableSelectLogicValues,
inlineListVariableSelectLogicActions,
InlineListVariableSelectLogicProps,
inlineListVariableSelectLogicMeta
>
const equalSelectedValues = (left: string[], right: string[]): boolean =>
left.length === right.length && left.every((value, index) => value === right[index])
export const inlineListVariableSelectLogic: LogicWrapper<inlineListVariableSelectLogicType> =
kea<inlineListVariableSelectLogicType>([
props({} as InlineListVariableSelectLogicProps),
key((props) => props.variableId),
path((key) => ['queries', 'nodes', 'DataVisualization', 'Variables', 'inlineListVariableSelectLogic', key]),
actions(({ values }) => ({
setSelectedValues: (selectedValues: string[]) => ({ selectedValues }),
resetSelectedValues: (selectedValues: string[]) => ({ selectedValues }),
commitSelectedValues: () => ({ selectedValues: values.selectedValues, hasChanges: values.hasChanges }),
})),
reducers(({ props }) => ({
selectedValues: [
props.selectedValues,
{
setSelectedValues: (_, { selectedValues }) => selectedValues,
resetSelectedValues: (_, { selectedValues }) => selectedValues,
},
],
hasChanges: [
false,
{
setSelectedValues: () => true,
resetSelectedValues: () => false,
commitSelectedValues: () => false,
},
],
})),
listeners(({ props }) => ({
commitSelectedValues: ({ selectedValues, hasChanges }) => {
if (hasChanges) {
props.onChange(selectedValues)
}
},
})),
propsChanged(({ actions, props }, oldProps) => {
if (!equalSelectedValues(props.selectedValues, oldProps.selectedValues)) {
actions.resetSelectedValues(props.selectedValues)
}
}),
])