Skip to content

: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.

2.3 KB
Raw Blame
import { MakeLogicType, actions, kea, listeners, path, reducers } from 'kea'

export interface CustomUnitModalData {
    type: 'prefix' | 'postfix'
    currentValue: string
    callback: (value: string) => void
}

export interface UnitPickerModalLogicType {
    actions: {
        showCustomUnitModal: (data: CustomUnitModalData) => { data: CustomUnitModalData }
        hideCustomUnitModal: () => void
        applyCustomUnit: (value: string) => { value: string }
    }
    values: {
        customUnitModalData: CustomUnitModalData | null
        isCustomUnitModalOpen: boolean
    }
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface unitPickerModalLogicValues {
    customUnitModalData: CustomUnitModalData | null
    isCustomUnitModalOpen: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface unitPickerModalLogicActions {
    applyCustomUnit: (value: string) => {
        value: string
    }
    hideCustomUnitModal: () => {
        value: true
    }
    showCustomUnitModal: (data: CustomUnitModalData) => {
        data: CustomUnitModalData
    }
}

export type unitPickerModalLogicType = MakeLogicType<unitPickerModalLogicValues, unitPickerModalLogicActions>

export const unitPickerModalLogic = kea<unitPickerModalLogicType>([
    path(['lib', 'components', 'UnitPicker', 'unitPickerModalLogic']),
    actions({
        showCustomUnitModal: (data: CustomUnitModalData) => ({ data }),
        hideCustomUnitModal: true,
        applyCustomUnit: (value: string) => ({ value }),
    }),
    reducers({
        customUnitModalData: [
            null as CustomUnitModalData | null,
            {
                showCustomUnitModal: (_, { data }) => data,
                hideCustomUnitModal: () => null,
            },
        ],
        isCustomUnitModalOpen: [
            false,
            {
                showCustomUnitModal: () => true,
                hideCustomUnitModal: () => false,
                applyCustomUnit: () => false,
            },
        ],
    }),
    listeners(({ values }) => ({
        applyCustomUnit: ({ value }: { value: string }) => {
            if (values.customUnitModalData?.callback) {
                values.customUnitModalData.callback(value)
            }
        },
    })),
])