: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, kea, key, path, props } from 'kea'
import { forms } from 'kea-forms'
import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from 'kea-forms'
import { isNumber } from 'lib/utils/guards'
import { AsyncMigrationModalProps, asyncMigrationsLogic } from 'scenes/instance/AsyncMigrations/asyncMigrationsLogic'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface asyncMigrationParameterFormLogicValues {
isParametersSubmitting: boolean
isParametersValid: boolean
parameters: Record<string, number>
parametersAllErrors: Record<string, any>
parametersChanged: boolean
parametersErrors: DeepPartialMap<Record<string, number>, ValidationErrorType>
parametersHasErrors: boolean
parametersManualErrors: Record<string, any>
parametersTouched: boolean
parametersTouches: Record<string, boolean>
parametersValidationErrors: DeepPartialMap<Record<string, number>, ValidationErrorType>
showParametersErrors: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface asyncMigrationParameterFormLogicActions {
resetParameters: (values?: Record<string, number>) => {
values?: Record<string, number>
}
setParametersManualErrors: (errors: Record<string, any>) => {
errors: Record<string, any>
}
setParametersValue: (
key: FieldName,
value: any
) => {
name: FieldName
value: any
}
setParametersValues: (values: DeepPartial<Record<string, number>>) => {
values: DeepPartial<Record<string, number>>
}
submitParameters: () => {
value: boolean
}
submitParametersFailure: (
error: Error,
errors: Record<string, any>
) => {
error: Error
errors: Record<string, any>
}
submitParametersRequest: (parameters: Record<string, number>) => {
parameters: Record<string, number>
}
submitParametersSuccess: (parameters: Record<string, number>) => {
parameters: Record<string, number>
}
touchParametersField: (key: string) => {
key: string
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface asyncMigrationParameterFormLogicMeta {
key: number
}
export type asyncMigrationParameterFormLogicType = MakeLogicType<
asyncMigrationParameterFormLogicValues,
asyncMigrationParameterFormLogicActions,
AsyncMigrationModalProps,
asyncMigrationParameterFormLogicMeta
>
export const asyncMigrationParameterFormLogic = kea<asyncMigrationParameterFormLogicType>([
path(['scenes', 'instance', 'AsyncMigrations', 'asyncMigrationParameterFormLogic']),
props({} as AsyncMigrationModalProps),
key((props) => props.migration.id),
forms(({ props }) => ({
parameters: {
defaults: defaultParameters(props),
submit: async (parameters: Record<string, number>) => {
asyncMigrationsLogic.actions.updateMigrationStatus(
{
...props.migration,
parameters,
},
props.endpoint,
props.message
)
},
},
})),
])
function defaultParameters(props: AsyncMigrationModalProps): Record<string, number> {
return Object.keys(props.migration.parameter_definitions).reduce<Record<string, number>>((acc, key) => {
const parameter = props.migration.parameters[key]
const parameterDefinition = props.migration.parameter_definitions[key][0]
if (parameter) {
acc[key] = parameter
} else if (isNumber(parameterDefinition)) {
acc[key] = parameterDefinition
}
return acc
}, {})
}