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.

feat(customer-analytics): add custom property definitions UI (#65518)

Arthur Moreira de Deus55aa357a1c9d
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertiesConfig.tsx b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertiesConfig.tsx
new file mode 100644
index 000000000000..fdc6ae72d3e3
--- /dev/null
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertiesConfig.tsx
@@ -0,0 +1,109 @@
+import { useActions, useValues } from 'kea'
+
+import { IconPencil, IconTrash } from '@posthog/icons'
+import { LemonButton, LemonTable, LemonTableColumns } from '@posthog/lemon-ui'
+
+import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'
+import { TZLabel } from 'lib/components/TZLabel'
+import { TeamMembershipLevel } from 'lib/constants'
+import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
+
+import type { CustomPropertyDefinitionApi } from 'products/customer_analytics/frontend/generated/api.schemas'
+
+import { customPropertyDefinitionsLogic } from './customPropertyDefinitionsLogic'
+import { CustomPropertyModal } from './CustomPropertyModal'
+import { labelForDisplayType } from './customPropertyTypes'
+
+export function CustomPropertiesConfig(): JSX.Element {
+ const { definitions, definitionsLoading } = useValues(customPropertyDefinitionsLogic)
+ const { openCreateModal, openEditModal, deleteDefinition } = useActions(customPropertyDefinitionsLogic)
+ const restrictionReason = useRestrictedArea({
+ scope: RestrictionScope.Project,
+ minimumAccessLevel: TeamMembershipLevel.Admin,
+ })
+
+ const confirmDelete = (definition: CustomPropertyDefinitionApi): void => {
+ LemonDialog.open({
+ title: `Delete ${definition.name}?`,
+ description: `Deleting ${definition.name} removes this custom property. This can't be undone.`,
+ primaryButton: {
+ children: 'Delete',
+ status: 'danger',
+ onClick: () => deleteDefinition({ id: definition.id }),
+ },
+ secondaryButton: { children: 'Cancel' },
+ })
+ }
+
+ const columns: LemonTableColumns<CustomPropertyDefinitionApi> = [
+ {
+ title: 'Name',
+ dataIndex: 'name',
+ render: (_, definition) => <span className="font-semibold">{definition.name}</span>,
+ },
+ {
+ title: 'Type',
+ render: (_, definition) => labelForDisplayType(definition.display_type),
+ },
+ {
+ title: 'Description',
+ dataIndex: 'description',
+ render: (_, definition) =>
+ definition.description ? definition.description : <span className="text-secondary">—</span>,
+ },
+ {
+ title: 'Last updated',
+ render: (_, definition) =>
+ definition.updated_at ? (
+ <TZLabel time={definition.updated_at} />
+ ) : (
+ <span className="text-secondary">—</span>
+ ),
+ },
+ {
+ title: '',
+ width: 0,
+ render: (_, definition) => (
+ <div className="flex gap-1 justify-end">
+ <LemonButton
+ size="small"
+ icon={<IconPencil />}
+ tooltip="Edit"
+ onClick={() => openEditModal(definition)}
+ disabledReason={restrictionReason}
+ />
+ <LemonButton
+ size="small"
+ status="danger"
+ icon={<IconTrash />}
+ tooltip="Delete"
+ onClick={() => confirmDelete(definition)}
+ disabledReason={restrictionReason}
+ />
+ </div>
+ ),
+ },
+ ]
+
+ return (
+ <div className="flex flex-col gap-2">
+ <div className="flex items-center justify-between gap-2">
+ <div>
+ <h3 className="mb-0">Custom properties</h3>
+ <p className="text-secondary mb-0">Define typed properties to store on your accounts.</p>
+ </div>
+ <LemonButton type="primary" onClick={openCreateModal} disabledReason={restrictionReason}>
+ New custom property
+ </LemonButton>
+ </div>
+ <LemonTable
+ columns={columns}
+ dataSource={definitions}
+ loading={definitionsLoading}
+ rowKey="id"
+ emptyState="No custom properties yet. Create one to get started."
+ />
+ <CustomPropertyModal />
+ </div>
+ )
+}
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx
new file mode 100644
index 000000000000..35c73a1735ea
--- /dev/null
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx
@@ -0,0 +1,68 @@
+import { useActions, useValues } from 'kea'
+import { Form } from 'kea-forms'
+
+import { LemonButton, LemonInput, LemonModal, LemonSelect, LemonSwitch, LemonTextArea } from '@posthog/lemon-ui'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import { customPropertyDefinitionsLogic } from './customPropertyDefinitionsLogic'
+import { DISPLAY_TYPE_OPTIONS, isNumericDisplayType } from './customPropertyTypes'
+
+export function CustomPropertyModal(): JSX.Element {
+ const { modalVisible, editingDefinition, customPropertyForm, isCustomPropertyFormSubmitting } =
+ useValues(customPropertyDefinitionsLogic)
+ const { closeModal, submitCustomPropertyForm } = useActions(customPropertyDefinitionsLogic)
+
+ const showBigNumberSwitch = isNumericDisplayType(customPropertyForm.displayType)
+
+ return (
+ <LemonModal
+ isOpen={modalVisible}
+ onClose={closeModal}
+ title={editingDefinition ? 'Edit custom property' : 'New custom property'}
+ footer={
+ <>
+ <LemonButton type="secondary" onClick={closeModal}>
+ Cancel
+ </LemonButton>
+ <LemonButton
+ type="primary"
+ onClick={submitCustomPropertyForm}
+ loading={isCustomPropertyFormSubmitting}
+ >
+ {editingDefinition ? 'Save' : 'Create'}
+ </LemonButton>
+ </>
+ }
+ >
+ <Form
+ logic={customPropertyDefinitionsLogic}
+ formKey="customPropertyForm"
+ enableFormOnSubmit
+ className="flex flex-col gap-4"
+ >
+ <LemonField name="name" label="Name">
+ <LemonInput placeholder="e.g. ARR" autoFocus />
+ </LemonField>
+ <LemonField name="description" label="Description">
+ <LemonTextArea placeholder="Optional description" minRows={2} />
+ </LemonField>
+ <LemonField name="displayType" label="Type">
+ <LemonSelect options={DISPLAY_TYPE_OPTIONS} fullWidth />
+ </LemonField>
+ {showBigNumberSwitch && (
+ <LemonField name="isBigNumber">
+ {({ value, onChange }) => (
+ <LemonSwitch
+ checked={value}
+ onChange={onChange}
+ label="Abbreviate large numbers (e.g. 10,000 → 10K)"
+ bordered
+ />
+ )}
+ </LemonField>
+ )}
+ </Form>
+ </LemonModal>
+ )
+}
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomerAnalyticsAccountConfig.tsx b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomerAnalyticsAccountConfig.tsx
index 5c9f52da92f3..d025a1646001 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomerAnalyticsAccountConfig.tsx
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomerAnalyticsAccountConfig.tsx
@@ -1,6 +1,6 @@
import { useActions, useValues } from 'kea'
-import { LemonSelect } from '@posthog/lemon-ui'
+import { LemonDivider, LemonSelect } from '@posthog/lemon-ui'
import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'
import { TeamMembershipLevel } from 'lib/constants'
@@ -12,6 +12,8 @@ import { teamLogic } from 'scenes/teamLogic'
import { groupsModel } from '~/models/groupsModel'
import { CustomerAnalyticsConfig } from '~/queries/schema/schema-general'
+import { CustomPropertiesConfig } from './CustomPropertiesConfig'
+
const NO_ACCOUNT_GROUP = -1
export function CustomerAnalyticsAccountConfig(): JSX.Element {
@@ -39,20 +41,24 @@ export function CustomerAnalyticsAccountConfig(): JSX.Element {
const value = customerAnalyticsConfig.account_group_type_index ?? NO_ACCOUNT_GROUP
return (
- <LemonSelect
- data-attr="customer-analytics-account-group-type"
- value={value}
- onChange={(newValue) =>
- updateCurrentTeam({
- customer_analytics_config: {
- account_group_type_index: newValue === NO_ACCOUNT_GROUP ? null : newValue,
- } as CustomerAnalyticsConfig,
- })
- }
- disabledReason={currentTeamLoading ? 'Loading...' : restrictedReason}
- fullWidth
- className="max-w-160"
- options={options}
- />
+ <div className="flex flex-col gap-4">
+ <LemonSelect
+ data-attr="customer-analytics-account-group-type"
+ value={value}
+ onChange={(newValue) =>
+ updateCurrentTeam({
+ customer_analytics_config: {
+ account_group_type_index: newValue === NO_ACCOUNT_GROUP ? null : newValue,
+ } as CustomerAnalyticsConfig,
+ })
+ }
+ disabledReason={currentTeamLoading ? 'Loading...' : restrictedReason}
+ fullWidth
+ className="max-w-160"
+ options={options}
+ />
+ <LemonDivider />
+ <CustomPropertiesConfig />
+ </div>
)
}
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts
new file mode 100644
index 000000000000..63359ff894d4
--- /dev/null
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts
@@ -0,0 +1,147 @@
+import { MOCK_DEFAULT_TEAM, MOCK_DEFAULT_USER } from '~/lib/api.mock'
+
+import { expectLogic } from 'kea-test-utils'
+
+import { userLogic } from 'scenes/userLogic'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import type { CustomPropertyDefinitionApi } from 'products/customer_analytics/frontend/generated/api.schemas'
+
+import { customPropertyDefinitionsLogic } from './customPropertyDefinitionsLogic'
+
+const DEFINITIONS_URL = '/api/projects/:team_id/custom_property_definitions/'
+const DEFINITION_URL = '/api/projects/:team_id/custom_property_definitions/:id/'
+
+const buildDefinition = (overrides: Partial<CustomPropertyDefinitionApi> = {}): CustomPropertyDefinitionApi =>
+ ({
+ id: 'def-1',
+ name: 'ARR',
+ description: null,
+ display_type: 'currency',
+ is_big_number: true,
+ created_at: '2026-01-01T00:00:00Z',
+ created_by: 1,
+ updated_at: '2026-01-01T00:00:00Z',
+ ...overrides,
+ }) as CustomPropertyDefinitionApi
+
+const defaultMocks = (): Parameters<typeof useMocks>[0] => ({
+ get: { [DEFINITIONS_URL]: { count: 1, results: [buildDefinition()] } },
+ post: { [DEFINITIONS_URL]: buildDefinition({ id: 'def-2' }) },
+ patch: { [DEFINITION_URL]: buildDefinition() },
+ delete: { [DEFINITION_URL]: {} },
+})
+
+describe('customPropertyDefinitionsLogic', () => {
+ let logic: ReturnType<typeof customPropertyDefinitionsLogic.build>
+
+ const mountLogic = (): void => {
+ logic = customPropertyDefinitionsLogic()
+ logic.mount()
+ }
+
+ beforeEach(() => {
+ window.POSTHOG_APP_CONTEXT = {
+ ...window.POSTHOG_APP_CONTEXT,
+ current_team: MOCK_DEFAULT_TEAM,
+ current_user: MOCK_DEFAULT_USER,
+ } as any
+ initKeaTests()
+ userLogic.mount()
+ })
+
+ it('loads definitions on mount', async () => {
+ useMocks(defaultMocks())
+ mountLogic()
+ await expectLogic(logic)
+ .toDispatchActions(['loadDefinitions', 'loadDefinitionsSuccess'])
+ .toMatchValues({ definitions: [expect.objectContaining({ id: 'def-1', name: 'ARR' })] })
+ })
+
+ it('hydrates the form when editing a definition', async () => {
+ useMocks(defaultMocks())
+ mountLogic()
+ const definition = buildDefinition()
+ await expectLogic(logic, () => logic.actions.openEditModal(definition)).toFinishAllListeners()
+
+ expect(logic.values.modalVisible).toBe(true)
+ expect(logic.values.editingDefinition).toEqual(definition)
+ expect(logic.values.customPropertyForm).toEqual({
+ name: 'ARR',
+ description: '',
+ displayType: 'currency',
+ isBigNumber: true,
+ })
+ })
+
+ it('creates a definition, reloads, and closes the modal', async () => {
+ useMocks(defaultMocks())
+ mountLogic()
+ logic.actions.openCreateModal()
+ logic.actions.setCustomPropertyFormValues({
+ name: 'Plan',
+ description: '',
+ displayType: 'text',
+ isBigNumber: false,
+ })
+
+ await expectLogic(logic, () => logic.actions.submitCustomPropertyForm()).toDispatchActions([
+ 'submitCustomPropertyFormSuccess',
+ 'loadDefinitions',
+ 'closeModal',
+ ])
+ expect(logic.values.modalVisible).toBe(false)
+ })
+
+ it('drops the big-number flag when switching to a non-numeric type', async () => {
+ let patchedBody: Record<string, any> | null = null
+ useMocks({
+ ...defaultMocks(),
+ patch: {
+ [DEFINITION_URL]: async ({ request }) => {
+ patchedBody = (await request.json()) as Record<string, any>
+ return buildDefinition()
+ },
+ },
+ })
+ mountLogic()
+ // Edit a numeric definition that has the big-number flag on, then switch it to a
+ // non-numeric type without touching the (now hidden) switch.
+ logic.actions.openEditModal(buildDefinition({ display_type: 'currency', is_big_number: true }))
+ logic.actions.setCustomPropertyFormValue('displayType', 'text')
+
+ await expectLogic(logic, () => logic.actions.submitCustomPropertyForm()).toDispatchActions([
+ 'submitCustomPropertyFormSuccess',
+ ])
+ expect(patchedBody).toMatchObject({ display_type: 'text', is_big_number: false })
+ })
+
+ it('surfaces a name conflict on the name field', async () => {
+ useMocks({ ...defaultMocks(), post: { [DEFINITIONS_URL]: () => [409, { detail: 'conflict' }] } })
+ mountLogic()
+ logic.actions.openCreateModal()
+ logic.actions.setCustomPropertyFormValues({
+ name: 'ARR',
+ description: '',
+ displayType: 'text',
+ isBigNumber: false,
+ })
+
+ await expectLogic(logic, () => logic.actions.submitCustomPropertyForm()).toDispatchActions([
+ 'submitCustomPropertyFormFailure',
+ 'setCustomPropertyFormManualErrors',
+ ])
+ expect(logic.values.modalVisible).toBe(true)
+ })
+
+ it('deletes a definition', async () => {
+ useMocks(defaultMocks())
+ mountLogic()
+ await expectLogic(logic).toDispatchActions(['loadDefinitionsSuccess'])
+ await expectLogic(logic, () => logic.actions.deleteDefinition({ id: 'def-1' }))
+ .toDispatchActions(['deleteDefinitionSuccess'])
+ .toMatchValues({ definitions: [] })
+ })
+})
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts
new file mode 100644
index 000000000000..38f8e07fa8f3
--- /dev/null
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts
@@ -0,0 +1,153 @@
+import { actions, afterMount, connect, kea, listeners, path, reducers } from 'kea'
+import { forms } from 'kea-forms'
+import { loaders } from 'kea-loaders'
+import posthog from 'posthog-js'
+
+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { projectLogic } from 'scenes/projectLogic'
+
+import {
+ customPropertyDefinitionsCreate,
+ customPropertyDefinitionsDestroy,
+ customPropertyDefinitionsList,
+ customPropertyDefinitionsPartialUpdate,
+} from 'products/customer_analytics/frontend/generated/api'
+import type {
+ CustomPropertyDefinitionApi,
+ CustomPropertyDisplayTypeEnumApi,
+} from 'products/customer_analytics/frontend/generated/api.schemas'
+
+import type { customPropertyDefinitionsLogicType } from './customPropertyDefinitionsLogicType'
+import { isNumericDisplayType } from './customPropertyTypes'
+
+export interface CustomPropertyFormValues {
+ name: string
+ description: string
+ displayType: CustomPropertyDisplayTypeEnumApi
+ isBigNumber: boolean
+}
+
+const DEFAULT_FORM_VALUES: CustomPropertyFormValues = {
+ name: '',
+ description: '',
+ displayType: 'text',
+ isBigNumber: false,
+}
+
+export const customPropertyDefinitionsLogic = kea<customPropertyDefinitionsLogicType>([
+ path([
+ 'products',
+ 'customer_analytics',
+ 'frontend',
+ 'scenes',
+ 'CustomerAnalyticsConfigurationScene',
+ 'account',
+ 'customPropertyDefinitionsLogic',
+ ]),
+ connect(() => ({
+ values: [projectLogic, ['currentProjectId']],
+ })),
+ actions({
+ openCreateModal: true,
+ openEditModal: (definition: CustomPropertyDefinitionApi) => ({ definition }),
+ closeModal: true,
+ }),
+ reducers({
+ modalVisible: [
+ false,
+ {
+ openCreateModal: () => true,
+ openEditModal: () => true,
+ closeModal: () => false,
+ },
+ ],
+ editingDefinition: [
+ null as CustomPropertyDefinitionApi | null,
+ {
+ openCreateModal: () => null,
+ openEditModal: (_, { definition }) => definition,
+ closeModal: () => null,
+ },
+ ],
+ }),
+ loaders(({ values }) => ({
+ definitions: [
+ [] as CustomPropertyDefinitionApi[],
+ {
+ loadDefinitions: async (): Promise<CustomPropertyDefinitionApi[]> => {
+ const response = await customPropertyDefinitionsList(String(values.currentProjectId))
+ return response.results
+ },
+ deleteDefinition: async ({ id }: { id: string }): Promise<CustomPropertyDefinitionApi[]> => {
+ await customPropertyDefinitionsDestroy(String(values.currentProjectId), id)
+ return values.definitions.filter((definition) => definition.id !== id)
+ },
+ },
+ ],
+ })),
+ forms(({ values }) => ({
+ customPropertyForm: {
+ defaults: DEFAULT_FORM_VALUES,
+ errors: ({ name }: CustomPropertyFormValues) => ({
+ name: !name?.trim() ? 'Name is required' : undefined,
+ }),
+ submit: async ({ name, description, displayType, isBigNumber }: CustomPropertyFormValues) => {
+ const body = {
+ name: name.trim(),
+ description: description?.trim() || null,
+ display_type: displayType,
+ // The switch is hidden for non-numeric types, so never send a stale flag for them.
+ is_big_number: isNumericDisplayType(displayType) ? isBigNumber : false,
+ }
+ const editing = values.editingDefinition
+ if (editing) {
+ await customPropertyDefinitionsPartialUpdate(String(values.currentProjectId), editing.id, body)
+ } else {
+ await customPropertyDefinitionsCreate(String(values.currentProjectId), body)
+ }
+ },
+ },
+ })),
+ listeners(({ actions, values }) => ({
+ openCreateModal: () => {
+ actions.resetCustomPropertyForm()
+ },
+ openEditModal: ({ definition }) => {
+ actions.setCustomPropertyFormValues({
+ name: definition.name,
+ description: definition.description ?? '',
+ displayType: definition.display_type,
+ isBigNumber: definition.is_big_number ?? false,
+ })
+ },
+ submitCustomPropertyFormSuccess: () => {
+ lemonToast.success(values.editingDefinition ? 'Custom property updated' : 'Custom property created')
+ actions.loadDefinitions()
+ actions.closeModal()
+ },
+ submitCustomPropertyFormFailure: ({ error }) => {
+ posthog.captureException(error, { scope: 'customPropertyDefinitionsLogic.submit' })
+ if ((error as { status?: number })?.status === 409) {
+ actions.setCustomPropertyFormManualErrors({
+ name: 'A custom property with this name already exists.',
+ })
+ return
+ }
+ lemonToast.error('Failed to save custom property')
+ },
+ deleteDefinitionSuccess: () => {
+ lemonToast.success('Custom property deleted')
+ },
+ deleteDefinitionFailure: ({ error }) => {
+ posthog.captureException(error, { scope: 'customPropertyDefinitionsLogic.delete' })
+ lemonToast.error('Failed to delete custom property')
+ },
+ loadDefinitionsFailure: ({ error }) => {
+ posthog.captureException(error, { scope: 'customPropertyDefinitionsLogic.load' })
+ lemonToast.error('Failed to load custom properties')
+ },
+ })),
+ afterMount(({ actions }) => {
+ actions.loadDefinitions()
+ }),
+])
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts
new file mode 100644
index 000000000000..5bb8a4555ff5
--- /dev/null
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts
@@ -0,0 +1,22 @@
+import { DISPLAY_TYPE_OPTIONS, isNumericDisplayType, labelForDisplayType } from './customPropertyTypes'
+
+describe('customPropertyTypes', () => {
+ it('labels each display type with its option label', () => {
+ expect(labelForDisplayType('currency')).toBe('Currency')
+ expect(labelForDisplayType('datetime')).toBe('Date & time')
+ expect(labelForDisplayType('text')).toBe('Text')
+ expect(labelForDisplayType('boolean')).toBe('True / false')
+ })
+
+ it('marks only numeric display types as numeric (drives the big-number switch)', () => {
+ const numeric = DISPLAY_TYPE_OPTIONS.filter((option) => option.isNumeric).map((option) => option.value)
+ expect(numeric).toEqual(['number', 'currency', 'percent'])
+ })
+
+ it('isNumericDisplayType matches the option metadata', () => {
+ expect(isNumericDisplayType('currency')).toBe(true)
+ expect(isNumericDisplayType('number')).toBe(true)
+ expect(isNumericDisplayType('text')).toBe(false)
+ expect(isNumericDisplayType('boolean')).toBe(false)
+ })
+})
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts
new file mode 100644
index 000000000000..00ea8c993a2e
--- /dev/null
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts
@@ -0,0 +1,28 @@
+import type { CustomPropertyDisplayTypeEnumApi } from 'products/customer_analytics/frontend/generated/api.schemas'
+
+// The backend stores the granular display type directly, so the form value maps 1:1 to the API.
+// This file holds only the UI metadata (label + whether the big-number switch applies).
+export interface DisplayTypeOption {
+ value: CustomPropertyDisplayTypeEnumApi
+ label: string
+ isNumeric: boolean
+}
+
+export const DISPLAY_TYPE_OPTIONS: DisplayTypeOption[] = [
+ { value: 'text', label: 'Text', isNumeric: false },
+ { value: 'number', label: 'Number', isNumeric: true },
+ { value: 'currency', label: 'Currency', isNumeric: true },
+ { value: 'percent', label: 'Percent', isNumeric: true },
+ { value: 'date', label: 'Date', isNumeric: false },
+ { value: 'datetime', label: 'Date & time', isNumeric: false },
+ { value: 'boolean', label: 'True / false', isNumeric: false },
+]
+
+export function labelForDisplayType(displayType: CustomPropertyDisplayTypeEnumApi): string {
+ return DISPLAY_TYPE_OPTIONS.find((option) => option.value === displayType)?.label ?? displayType
+}
+
+// Drives the big-number switch: it's only shown — and only meaningful in the payload — for numeric types.
+export function isNumericDisplayType(displayType: CustomPropertyDisplayTypeEnumApi): boolean {
+ return DISPLAY_TYPE_OPTIONS.find((option) => option.value === displayType)?.isNumeric ?? false
+}