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): Expose select property options on the API (#68300)

Arthur Moreira de Deus957dbb58bc43
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index df42915c0d9b..488f352829bf 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -514,7 +514,19 @@ SPECTACULAR_SETTINGS = {
"HeatmapType": "products.web_analytics.backend.models.heatmap_saved.SavedHeatmap.Type",
# --- Inline value lists (type-hint enums, no x-spec-enum-id) ---
"PropertyGroupOperator": ["AND", "OR"],
- "CustomPropertyDisplayTypeEnum": ["text", "number", "currency", "percent", "date", "datetime", "boolean"],
+ "CustomPropertyDisplayTypeEnum": [
+ "text",
+ "number",
+ "currency",
+ "percent",
+ "date",
+ "datetime",
+ "boolean",
+ "select",
+ ],
+ # Pinned pre-emptively: the auto-name would be the collision-prone "ColorEnum", and adding a
+ # palette color later would change the hash and silently rename the generated type.
+ "CustomPropertyOptionColorEnum": [f"preset-{i}" for i in range(1, 11)],
# Experiment now has two serializers (full ExperimentSerializer + ExperimentBasicSerializer
# for the list endpoint) that both expose `type`/`status`. Pin both to their pre-existing
# generated names so the shared enums don't get component-prefixed auto-names on collision.
diff --git a/products/customer_analytics/backend/COMPROMISES.md b/products/customer_analytics/backend/COMPROMISES.md
index afd28ae0ec5d..0cbd0db2efa2 100644
--- a/products/customer_analytics/backend/COMPROMISES.md
+++ b/products/customer_analytics/backend/COMPROMISES.md
@@ -2,6 +2,14 @@
Shortcuts taken to ship the first version. Revisit when they bite.
+## Select custom property option side effects
+
+- **Rename backfill / removal clearing runs inline.** `update_custom_property_definition` rewrites the definition's `CustomPropertyValue` rows synchronously, inside the definition-save transaction (`apply_option_side_effects` in `logic/custom_property_definitions.py`).
+ For a definition with many account values this makes the PATCH slow and holds the transaction open.
+ Brittle at scale — move to an async backfill job when large value sets bite.
+- **Conversion safety lives in a caller-side guard.** Side effects run only while the definition is still `select`: on a select→other conversion the id diff would read every option as removed and wrongly clear all values, which must instead survive as plain strings.
+ The guard sits in the facade update path, locked by `test_converting_select_to_text_keeps_values_and_clears_options`; a new write path that skips it would clear values on conversion.
+
## Custom property view sync
- **Celery, not Temporal.** The sync runs in a Celery task, not a dedicated Temporal workflow. No
diff --git a/products/customer_analytics/backend/constants.py b/products/customer_analytics/backend/constants.py
index 58f29d52f946..bf95beb5b649 100644
--- a/products/customer_analytics/backend/constants.py
+++ b/products/customer_analytics/backend/constants.py
@@ -14,7 +14,16 @@ ACCOUNT_ASSIGNMENT_ROLE_FIELDS = ("csm", "account_executive", "account_owner")
BILLING_USAGE_INSIGHT_SHORT_IDS = ["fiJDsKLp"]
BILLING_SPEND_INSIGHT_SHORT_IDS = ["o4I9sdFE", "Tjo4bsux"]
-CUSTOM_PROPERTY_DISPLAY_TYPE_CHOICES = ["text", "number", "currency", "percent", "date", "datetime", "boolean"]
+CUSTOM_PROPERTY_DISPLAY_TYPE_CHOICES = [
+ "text",
+ "number",
+ "currency",
+ "percent",
+ "date",
+ "datetime",
+ "boolean",
+ "select",
+]
# Mirrors OPTION_COLOR_TOKENS in the frontend's customPropertyTypes.ts (DataColorToken presets).
CUSTOM_PROPERTY_OPTION_COLORS = [f"preset-{i}" for i in range(1, 11)]
diff --git a/products/customer_analytics/backend/facade/constants.py b/products/customer_analytics/backend/facade/constants.py
index cb4efa592080..91233596f361 100644
--- a/products/customer_analytics/backend/facade/constants.py
+++ b/products/customer_analytics/backend/facade/constants.py
@@ -10,6 +10,7 @@ from products.customer_analytics.backend.constants import (
BILLING_SPEND_INSIGHT_SHORT_IDS,
BILLING_USAGE_INSIGHT_SHORT_IDS,
CUSTOM_PROPERTY_DISPLAY_TYPE_CHOICES,
+ CUSTOM_PROPERTY_OPTION_COLORS,
CUSTOMER_ANALYTICS_CSP_FLAG,
DEFAULT_ACTIVITY_EVENT,
)
@@ -19,6 +20,7 @@ __all__ = [
"BILLING_SPEND_INSIGHT_SHORT_IDS",
"BILLING_USAGE_INSIGHT_SHORT_IDS",
"CUSTOM_PROPERTY_DISPLAY_TYPE_CHOICES",
+ "CUSTOM_PROPERTY_OPTION_COLORS",
"CUSTOMER_ANALYTICS_CSP_FLAG",
"DEFAULT_ACTIVITY_EVENT",
]
diff --git a/products/customer_analytics/backend/presentation/views/serializers.py b/products/customer_analytics/backend/presentation/views/serializers.py
index ba00edb65668..554f2f25238b 100644
--- a/products/customer_analytics/backend/presentation/views/serializers.py
+++ b/products/customer_analytics/backend/presentation/views/serializers.py
@@ -27,7 +27,10 @@ from rest_framework_dataclasses.serializers import DataclassSerializer
from posthog.api.shared import UserBasicSerializer
from posthog.models import OrganizationMembership
-from products.customer_analytics.backend.facade.constants import CUSTOM_PROPERTY_DISPLAY_TYPE_CHOICES
+from products.customer_analytics.backend.facade.constants import (
+ CUSTOM_PROPERTY_DISPLAY_TYPE_CHOICES,
+ CUSTOM_PROPERTY_OPTION_COLORS,
+)
from products.customer_analytics.backend.facade.contracts import (
AccountNotebookView,
AccountNoteView,
@@ -35,6 +38,7 @@ from products.customer_analytics.backend.facade.contracts import (
CustomerJourneyView,
CustomerProfileConfigView,
CustomPropertyDefinitionView,
+ CustomPropertyOption,
CustomPropertyReference,
CustomPropertySourceView,
)
@@ -356,6 +360,32 @@ class CustomPropertySourceSerializer(DataclassSerializer):
]
+class CustomPropertyOptionSerializer(DataclassSerializer):
+ """An allowed value of a select custom property."""
+
+ id = serializers.CharField(
+ required=False,
+ allow_null=True,
+ help_text=(
+ "Server-assigned stable id of the option. Omit for new options; send it back unchanged "
+ "when editing so renames and removals can be told apart."
+ ),
+ )
+ label = serializers.CharField( # type: ignore[assignment]
+ max_length=400,
+ help_text="Display label of the option. Stored as the account's value when picked.",
+ )
+ color = serializers.ChoiceField(
+ choices=CUSTOM_PROPERTY_OPTION_COLORS,
+ help_text="Preset color token used to render the option ('preset-1' through 'preset-10').",
+ )
+
+ class Meta:
+ dataclass = CustomPropertyOption
+ ref_name = "CustomPropertyOption"
+ fields = ["id", "label", "color"]
+
+
class CustomPropertyDefinitionSerializer(DataclassSerializer):
"""A team-scoped definition of a custom account property — the attribute side of the model.
@@ -378,7 +408,7 @@ class CustomPropertyDefinitionSerializer(DataclassSerializer):
choices=CUSTOM_PROPERTY_DISPLAY_TYPE_CHOICES,
help_text=(
"How the property is interpreted and rendered: 'text', 'number', 'currency', "
- "'percent', 'date', 'datetime', or 'boolean'."
+ "'percent', 'date', 'datetime', 'boolean', or 'select'."
),
)
is_big_number = serializers.BooleanField(
@@ -386,6 +416,15 @@ class CustomPropertyDefinitionSerializer(DataclassSerializer):
default=False,
help_text="Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties.",
)
+ options = CustomPropertyOptionSerializer(
+ many=True,
+ required=False,
+ allow_null=True,
+ help_text=(
+ "For select properties: the allowed options. Required (non-empty) when display_type is "
+ "'select'; cleared server-side for other types."
+ ),
+ )
source = CustomPropertySourceSerializer( # type: ignore[assignment]
read_only=True,
allow_null=True,
@@ -409,6 +448,7 @@ class CustomPropertyDefinitionSerializer(DataclassSerializer):
"description",
"display_type",
"is_big_number",
+ "options",
"source",
"created_at",
"created_by",
diff --git a/products/customer_analytics/backend/presentation/views/views.py b/products/customer_analytics/backend/presentation/views/views.py
index 7a9d61b67318..344236d9982f 100644
--- a/products/customer_analytics/backend/presentation/views/views.py
+++ b/products/customer_analytics/backend/presentation/views/views.py
@@ -13,6 +13,7 @@ pydantic-error formatting, and activity logging live behind the facade.
from __future__ import annotations
import json
+from dataclasses import asdict
from typing import cast
from uuid import UUID
@@ -228,12 +229,15 @@ class CustomPropertyDefinitionViewSet(
description=data.description,
display_type=data.display_type,
is_big_number=data.is_big_number,
+ options=_custom_property_option_dicts(data.options),
organization_id=self.organization.id,
user=cast(User, request.user),
was_impersonated=is_impersonated(request),
)
except api.CustomPropertyDefinitionConflictError as e:
raise Conflict(str(e))
+ except api.InvalidCustomPropertyOptions as e:
+ raise ValidationError({"options": str(e)})
return Response(CustomPropertyDefinitionSerializer(instance=definition).data, status=status.HTTP_201_CREATED)
def update(self, request: Request, *args, **kwargs) -> Response:
@@ -251,6 +255,8 @@ class CustomPropertyDefinitionViewSet(
)
except api.CustomPropertyDefinitionConflictError as e:
raise Conflict(str(e))
+ except api.InvalidCustomPropertyOptions as e:
+ raise ValidationError({"options": str(e)})
if definition is None:
return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND)
return Response(CustomPropertyDefinitionSerializer(instance=definition).data)
@@ -284,9 +290,19 @@ def _custom_property_definition_write_fields(validated, raw_data: dict) -> dict:
fields["display_type"] = validated.display_type
if "is_big_number" in raw_data:
fields["is_big_number"] = validated.is_big_number
+ if "options" in raw_data:
+ fields["options"] = _custom_property_option_dicts(validated.options)
return fields
+def _custom_property_option_dicts(options) -> list[dict] | None:
+ """Nested DataclassSerializer fields validate into dataclass instances; the facade and the
+ JSONField speak plain dicts."""
+ if options is None:
+ return None
+ return [asdict(option) for option in options]
+
+
class CustomPropertySourceViewSet(
TeamAndOrgViewSetMixin,
AccessControlViewSetMixin,
diff --git a/products/customer_analytics/backend/test/test_views.py b/products/customer_analytics/backend/test/test_views.py
index 826e470c1362..8f1c37c34b03 100644
--- a/products/customer_analytics/backend/test/test_views.py
+++ b/products/customer_analytics/backend/test/test_views.py
@@ -1579,6 +1579,41 @@ class TestCustomPropertyDefinitionViewSet(APIBaseTest):
response = self.client.post(self.endpoint_base, {"name": "P", "display_type": display_type}, format="json")
self.assertEqual(expected_status, response.status_code, response.json())
+ def test_create_select_assigns_option_ids_and_patch_round_trips(self):
+ response = self._create(
+ name="Stage",
+ display_type="select",
+ is_big_number=False,
+ options=[{"label": "Open", "color": "preset-1"}, {"label": "Closed", "color": "preset-2"}],
+ )
+
+ self.assertEqual(status.HTTP_201_CREATED, response.status_code, response.json())
+ options = response.json()["options"]
+ self.assertEqual([option["label"] for option in options], ["Open", "Closed"])
+ self.assertTrue(all(option["id"] for option in options))
+
+ patched = self.client.patch(
+ f"{self.endpoint_base}{response.json()['id']}/",
+ {"options": [{**options[0], "label": "Won"}, options[1]]},
+ format="json",
+ )
+
+ self.assertEqual(status.HTTP_200_OK, patched.status_code, patched.json())
+ self.assertEqual([option["label"] for option in patched.json()["options"]], ["Won", "Closed"])
+ self.assertEqual(patched.json()["options"][0]["id"], options[0]["id"])
+
+ @parameterized.expand(
+ [
+ ("select_without_options", {"name": "S1", "display_type": "select"}),
+ ("select_empty_options", {"name": "S2", "display_type": "select", "options": []}),
+ ("bad_color", {"name": "S3", "display_type": "select", "options": [{"label": "A", "color": "red"}]}),
+ ]
+ )
+ def test_create_select_rejects_invalid_payloads(self, _name, payload):
+ response = self.client.post(self.endpoint_base, payload, format="json")
+
+ self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code, response.json())
+
def test_is_big_number_forced_false_for_non_numeric(self):
response = self._create(name="Tier", display_type="text", is_big_number=True)
diff --git a/products/customer_analytics/frontend/components/AccountPropertiesInput/CyclotronJobInputAccountProperties.tsx b/products/customer_analytics/frontend/components/AccountPropertiesInput/CyclotronJobInputAccountProperties.tsx
index 7b766e4ebdb9..4758ae291250 100644
--- a/products/customer_analytics/frontend/components/AccountPropertiesInput/CyclotronJobInputAccountProperties.tsx
+++ b/products/customer_analytics/frontend/components/AccountPropertiesInput/CyclotronJobInputAccountProperties.tsx
@@ -2,8 +2,9 @@ import { useValues } from 'kea'
import { useRef, useState } from 'react'
import { IconPlus, IconX } from '@posthog/icons'
-import { LemonButton } from '@posthog/lemon-ui'
+import { LemonButton, LemonColorGlyph, LemonSelect } from '@posthog/lemon-ui'
+import type { DataColorToken } from 'lib/colors'
import type { CustomInputRendererProps } from 'lib/components/CyclotronJob/customInputRenderers'
import { CodeEditorInline } from 'lib/monaco/CodeEditorInline'
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from 'lib/ui/quill'
@@ -17,9 +18,10 @@ export default function CyclotronJobInputAccountProperties({
onChange,
sampleGlobalsWithInputs,
}: CustomInputRendererProps): JSX.Element {
- const { definitions, nameById, definitionsLoading } = useValues(accountPropertiesInputLogic)
+ const { definitions, definitionsLoading } = useValues(accountPropertiesInputLogic)
- // Keys are custom property definition ids (stable across renames); values are Hog expressions.
+ // Keys are custom property definition ids (stable across renames); values are Hog expressions
+ // (select properties store the chosen option label as a literal).
const properties: Record<string, string> = value ?? {}
const entries = Object.entries(properties)
const selectedIds = new Set(entries.map(([id]) => id))
@@ -36,20 +38,38 @@ export default function CyclotronJobInputAccountProperties({
return (
<div className="flex flex-col gap-2">
{entries.map(([id, hogValue]) => {
- const label = nameById[id]
+ const definition = definitions.find((d) => d.id === id)
return (
<div className="flex gap-2 items-center" key={id}>
- <div className="flex-1 min-w-50 font-medium truncate" title={label ?? id}>
- {label ?? <span className="text-secondary italic">Unknown property</span>}
+ <div className="flex-1 min-w-50 font-medium truncate" title={definition?.name ?? id}>
+ {definition?.name ?? <span className="text-secondary italic">Unknown property</span>}
</div>
- <CodeEditorInline
- className="overflow-hidden flex-2"
- minHeight="37"
- value={hogValue}
- onChange={(val) => setProperty(id, val ?? '')}
- language="hogTemplate"
- globals={sampleGlobalsWithInputs ?? undefined}
- />
+ {definition?.display_type === 'select' ? (
+ <LemonSelect
+ className="flex-2"
+ value={hogValue || null}
+ onChange={(option) => setProperty(id, option ?? '')}
+ options={(definition.options ?? []).map((option) => ({
+ value: option.label,
+ label: (
+ <span className="inline-flex items-center gap-1.5">
+ <LemonColorGlyph colorToken={option.color as DataColorToken} size="small" />
+ {option.label}
+ </span>
+ ),
+ }))}
+ placeholder="Select an option"
+ />
+ ) : (
+ <CodeEditorInline
+ className="overflow-hidden flex-2"
+ minHeight="37"
+ value={hogValue}
+ onChange={(val) => setProperty(id, val ?? '')}
+ language="hogTemplate"
+ globals={sampleGlobalsWithInputs ?? undefined}
+ />
+ )}
<LemonButton icon={<IconX />} size="small" onClick={() => removeProperty(id)} />
</div>
)
diff --git a/products/customer_analytics/frontend/components/AccountPropertiesInput/accountPropertiesInputLogic.ts b/products/customer_analytics/frontend/components/AccountPropertiesInput/accountPropertiesInputLogic.ts
index e01fcaebcc93..a56560c9fbb9 100644
--- a/products/customer_analytics/frontend/components/AccountPropertiesInput/accountPropertiesInputLogic.ts
+++ b/products/customer_analytics/frontend/components/AccountPropertiesInput/accountPropertiesInputLogic.ts
@@ -1,4 +1,4 @@
-import { afterMount, connect, kea, listeners, path, selectors } from 'kea'
+import { afterMount, connect, kea, listeners, path } from 'kea'
import { loaders } from 'kea-loaders'
import posthog from 'posthog-js'
@@ -32,12 +32,6 @@ export const accountPropertiesInputLogic = kea<accountPropertiesInputLogicType>(
},
],
})),
- selectors({
- nameById: [
- (s) => [s.definitions],
- (definitions): Record<string, string> => Object.fromEntries(definitions.map((d) => [d.id, d.name])),
- ],
- }),
listeners({
loadDefinitionsFailure: ({ error }) => {
posthog.captureException(error, { scope: 'accountPropertiesInputLogic.load' })
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
index ba421f27732c..0f5df72127dd 100644
--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md
+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
@@ -56,7 +56,7 @@ AccountsTabContent ── binds dataNodeLogic(ACCOUNTS_HOGQL_DATA_NODE_KEY, acc
Default columns (`ACCOUNTS_HOGQL_DEFAULT_SELECT`): `name`, `tag_names`, `notebook_count`, `csm`, `account_executive`, `account_owner`. The name column is force-kept (`ensureNameColumn`) — removing it breaks identity, scroll, and role edits. Extra columns come from account properties, lazy/virtual-table joins under `system.accounts`, data-warehouse joins, freeform SQL, or **custom properties** — all assembled by `buildAccountColumnGroups`.
-**Custom property columns** surface the team's `CustomPropertyDefinition`s (loaded in `accountsColumnConfigLogic` via the generated `customPropertyDefinitionsList`) as a "Custom properties" picker group. Each is selected as `accounts.custom_properties.values.\`<definition-id>\` AS cp*<id>`— a JSON dot-access through the`custom_properties`lazy join on`system.accounts`(backed by the`customer_analytics_custompropertyvalue`EAV table; one JOIN regardless of column count). Because the alias is an opaque`cp*<id>`, every label-bearing surface must resolve it back via the`aliasToDefinition`selector: the table header (`useContextColumns`in`AccountsHogQLTable`) and the configurator's "Visible columns" list (`SelectedAccountColumn`). Cells render by display type (`CustomPropertyCell`: date→`TZLabel`, boolean→icon, numeric→`formatCustomPropertyValue`). v1 is display-only with lexical sort (the JSON value is a string). Numeric custom properties (display type`number`/`currency`/`percent`) are also selectable in the **overview tiles** sum/avg/threshold pickers —`numericColumnOptions`recognizes the display type and wraps the (string) value in`toFloatOrNull(...)` so aggregation is numeric.
+**Custom property columns** surface the team's `CustomPropertyDefinition`s (loaded in `accountsColumnConfigLogic` via the generated `customPropertyDefinitionsList`) as a "Custom properties" picker group. Each is selected as `accounts.custom_properties.values.\`<definition-id>\` AS cp*<id>`— a JSON dot-access through the`custom_properties`lazy join on`system.accounts`(backed by the`customer_analytics_custompropertyvalue`EAV table; one JOIN regardless of column count). Because the alias is an opaque`cp*<id>`, every label-bearing surface must resolve it back via the`aliasToDefinition`selector: the table header (`useContextColumns`in`AccountsHogQLTable`) and the configurator's "Visible columns" list (`SelectedAccountColumn`). Cells render by display type (`CustomPropertyCell`: date→`TZLabel`, boolean→icon, select→`LemonColorGlyph`+ label, numeric→`formatCustomPropertyValue`). v1 is display-only with lexical sort (the JSON value is a string). Numeric custom properties (display type`number`/`currency`/`percent`) are also selectable in the **overview tiles** sum/avg/threshold pickers —`numericColumnOptions`recognizes the display type and wraps the (string) value in`toFloatOrNull(...)` so aggregation is numeric.
Sort safety: removing the sorted column drops the sort (`clearSortIfColumnRemoved`), else the backend gets an `orderBy` referencing a missing alias.
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx
index e261bfd4d475..1505604a19db 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx
@@ -2,8 +2,9 @@ import { useActions, useValues } from 'kea'
import { useMemo } from 'react'
import { IconCheck, IconX } from '@posthog/icons'
-import { LemonButton, LemonSkeleton, LemonTable, ProfilePicture } from '@posthog/lemon-ui'
+import { LemonButton, LemonColorGlyph, LemonSkeleton, LemonTable, ProfilePicture } from '@posthog/lemon-ui'
+import type { DataColorToken } from 'lib/colors'
import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'
import { MemberSelect } from 'lib/components/MemberSelect'
import { ObjectTags } from 'lib/components/ObjectTags/ObjectTags'
@@ -183,6 +184,15 @@ function CustomPropertyCell({
if (definition.display_type === 'boolean') {
return value === 'true' || value === '1' ? <IconCheck /> : <IconX className="text-muted" />
}
+ if (definition.display_type === 'select') {
+ const option = definition.options?.find((candidate) => candidate.label === value)
+ return (
+ <span className="inline-flex items-center gap-1.5">
+ {option && <LemonColorGlyph colorToken={option.color as DataColorToken} size="small" />}
+ <span>{value}</span>
+ </span>
+ )
+ }
return <span>{formatCustomPropertyValue(value, definition)}</span>
}
diff --git a/products/customer_analytics/frontend/generated/api.schemas.ts b/products/customer_analytics/frontend/generated/api.schemas.ts
index eaf99d7a4bc8..8e90149e1c97 100644
--- a/products/customer_analytics/frontend/generated/api.schemas.ts
+++ b/products/customer_analytics/frontend/generated/api.schemas.ts
@@ -306,6 +306,7 @@ export interface PatchedAccountApi {
* * `date` - date
* * `datetime` - datetime
* * `boolean` - boolean
+ * * `select` - select
*/
export type CustomPropertyDisplayTypeEnumApi =
(typeof CustomPropertyDisplayTypeEnumApi)[keyof typeof CustomPropertyDisplayTypeEnumApi]
@@ -318,8 +319,66 @@ export const CustomPropertyDisplayTypeEnumApi = {
Date: 'date',
Datetime: 'datetime',
Boolean: 'boolean',
+ Select: 'select',
} as const
+/**
+ * * `preset-1` - preset-1
+ * * `preset-2` - preset-2
+ * * `preset-3` - preset-3
+ * * `preset-4` - preset-4
+ * * `preset-5` - preset-5
+ * * `preset-6` - preset-6
+ * * `preset-7` - preset-7
+ * * `preset-8` - preset-8
+ * * `preset-9` - preset-9
+ * * `preset-10` - preset-10
+ */
+export type CustomPropertyOptionColorEnumApi =
+ (typeof CustomPropertyOptionColorEnumApi)[keyof typeof CustomPropertyOptionColorEnumApi]
+
+export const CustomPropertyOptionColorEnumApi = {
+ Preset1: 'preset-1',
+ Preset2: 'preset-2',
+ Preset3: 'preset-3',
+ Preset4: 'preset-4',
+ Preset5: 'preset-5',
+ Preset6: 'preset-6',
+ Preset7: 'preset-7',
+ Preset8: 'preset-8',
+ Preset9: 'preset-9',
+ Preset10: 'preset-10',
+} as const
+
+/**
+ * An allowed value of a select custom property.
+ */
+export interface CustomPropertyOptionApi {
+ /**
+ * Server-assigned stable id of the option. Omit for new options; send it back unchanged when editing so renames and removals can be told apart.
+ * @nullable
+ */
+ id?: string | null
+ /**
+ * Display label of the option. Stored as the account's value when picked.
+ * @maxLength 400
+ */
+ label: string
+ /** Preset color token used to render the option ('preset-1' through 'preset-10').
+ *
+ * * `preset-1` - preset-1
+ * * `preset-2` - preset-2
+ * * `preset-3` - preset-3
+ * * `preset-4` - preset-4
+ * * `preset-5` - preset-5
+ * * `preset-6` - preset-6
+ * * `preset-7` - preset-7
+ * * `preset-8` - preset-8
+ * * `preset-9` - preset-9
+ * * `preset-10` - preset-10 */
+ color: CustomPropertyOptionColorEnumApi
+}
+
/**
* Binds a materialized data-warehouse view column to a custom property definition; the view's
* values are synced onto matching accounts on each materialization.
@@ -393,7 +452,7 @@ export interface CustomPropertyDefinitionApi {
* @nullable
*/
description?: string | null
- /** How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', or 'boolean'.
+ /** How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', or 'select'.
*
* * `text` - text
* * `number` - number
@@ -401,10 +460,16 @@ export interface CustomPropertyDefinitionApi {
* * `percent` - percent
* * `date` - date
* * `datetime` - datetime
- * * `boolean` - boolean */
+ * * `boolean` - boolean
+ * * `select` - select */
display_type: CustomPropertyDisplayTypeEnumApi
/** Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties. */
is_big_number?: boolean
+ /**
+ * For select properties: the allowed options. Required (non-empty) when display_type is 'select'; cleared server-side for other types.
+ * @nullable
+ */
+ options?: CustomPropertyOptionApi[] | null
/** The data-warehouse view-sync binding feeding this property, or null when values are set manually. */
readonly source: CustomPropertySourceApi | null
readonly created_at: string
@@ -443,7 +508,7 @@ export interface PatchedCustomPropertyDefinitionApi {
* @nullable
*/
description?: string | null
- /** How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', or 'boolean'.
+ /** How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', or 'select'.
*
* * `text` - text
* * `number` - number
@@ -451,10 +516,16 @@ export interface PatchedCustomPropertyDefinitionApi {
* * `percent` - percent
* * `date` - date
* * `datetime` - datetime
- * * `boolean` - boolean */
+ * * `boolean` - boolean
+ * * `select` - select */
display_type?: CustomPropertyDisplayTypeEnumApi
/** Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties. */
is_big_number?: boolean
+ /**
+ * For select properties: the allowed options. Required (non-empty) when display_type is 'select'; cleared server-side for other types.
+ * @nullable
+ */
+ options?: CustomPropertyOptionApi[] | null
/** The data-warehouse view-sync binding feeding this property, or null when values are set manually. */
readonly source?: CustomPropertySourceApi | null
readonly created_at?: string
diff --git a/products/customer_analytics/frontend/generated/api.zod.ts b/products/customer_analytics/frontend/generated/api.zod.ts
index 7c5160791796..62fd50a436a2 100644
--- a/products/customer_analytics/frontend/generated/api.zod.ts
+++ b/products/customer_analytics/frontend/generated/api.zod.ts
@@ -196,6 +196,7 @@ export const AccountsPartialUpdateBody = /* @__PURE__ */ zod
export const customPropertyDefinitionsCreateBodyNameMax = 400
export const customPropertyDefinitionsCreateBodyIsBigNumberDefault = false
+export const customPropertyDefinitionsCreateBodyOptionsItemLabelMax = 400
export const CustomPropertyDefinitionsCreateBody = /* @__PURE__ */ zod
.object({
@@ -205,17 +206,57 @@ export const CustomPropertyDefinitionsCreateBody = /* @__PURE__ */ zod
.describe('Human-readable name of the custom property. Unique within the team.'),
description: zod.string().nullish().describe('Optional description of what the property represents.'),
display_type: zod
- .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean'])
+ .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', 'select'])
.describe(
- '\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean'
+ '\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean\n\* `select` - select'
)
.describe(
- "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', or 'boolean'.\n\n\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean"
+ "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', or 'select'.\n\n\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean\n\* `select` - select"
),
is_big_number: zod
.boolean()
.default(customPropertyDefinitionsCreateBodyIsBigNumberDefault)
.describe('Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties.'),
+ options: zod
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Server-assigned stable id of the option. Omit for new options; send it back unchanged when editing so renames and removals can be told apart.'
+ ),
+ label: zod
+ .string()
+ .max(customPropertyDefinitionsCreateBodyOptionsItemLabelMax)
+ .describe("Display label of the option. Stored as the account's value when picked."),
+ color: zod
+ .enum([
+ 'preset-1',
+ 'preset-2',
+ 'preset-3',
+ 'preset-4',
+ 'preset-5',
+ 'preset-6',
+ 'preset-7',
+ 'preset-8',
+ 'preset-9',
+ 'preset-10',
+ ])
+ .describe(
+ '\* `preset-1` - preset-1\n\* `preset-2` - preset-2\n\* `preset-3` - preset-3\n\* `preset-4` - preset-4\n\* `preset-5` - preset-5\n\* `preset-6` - preset-6\n\* `preset-7` - preset-7\n\* `preset-8` - preset-8\n\* `preset-9` - preset-9\n\* `preset-10` - preset-10'
+ )
+ .describe(
+ "Preset color token used to render the option ('preset-1' through 'preset-10').\n\n\* `preset-1` - preset-1\n\* `preset-2` - preset-2\n\* `preset-3` - preset-3\n\* `preset-4` - preset-4\n\* `preset-5` - preset-5\n\* `preset-6` - preset-6\n\* `preset-7` - preset-7\n\* `preset-8` - preset-8\n\* `preset-9` - preset-9\n\* `preset-10` - preset-10"
+ ),
+ })
+ .describe('An allowed value of a select custom property.')
+ )
+ .nullish()
+ .describe(
+ "For select properties: the allowed options. Required (non-empty) when display_type is 'select'; cleared server-side for other types."
+ ),
})
.describe(
"A team-scoped definition of a custom account property — the attribute side of the model.\n\nHolds only the property's shape (name, display type, big-number flag). Per-account values are\nstored separately, so this serializer never reads or writes account values."
@@ -224,6 +265,7 @@ export const CustomPropertyDefinitionsCreateBody = /* @__PURE__ */ zod
export const customPropertyDefinitionsUpdateBodyNameMax = 400
export const customPropertyDefinitionsUpdateBodyIsBigNumberDefault = false
+export const customPropertyDefinitionsUpdateBodyOptionsItemLabelMax = 400
export const CustomPropertyDefinitionsUpdateBody = /* @__PURE__ */ zod
.object({
@@ -233,17 +275,57 @@ export const CustomPropertyDefinitionsUpdateBody = /* @__PURE__ */ zod
.describe('Human-readable name of the custom property. Unique within the team.'),
description: zod.string().nullish().describe('Optional description of what the property represents.'),
display_type: zod
- .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean'])
+ .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', 'select'])
.describe(
- '\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean'
+ '\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean\n\* `select` - select'
)
.describe(
- "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', or 'boolean'.\n\n\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean"
+ "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', or 'select'.\n\n\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean\n\* `select` - select"
),
is_big_number: zod
.boolean()
.default(customPropertyDefinitionsUpdateBodyIsBigNumberDefault)
.describe('Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties.'),
+ options: zod
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Server-assigned stable id of the option. Omit for new options; send it back unchanged when editing so renames and removals can be told apart.'
+ ),
+ label: zod
+ .string()
+ .max(customPropertyDefinitionsUpdateBodyOptionsItemLabelMax)
+ .describe("Display label of the option. Stored as the account's value when picked."),
+ color: zod
+ .enum([
+ 'preset-1',
+ 'preset-2',
+ 'preset-3',
+ 'preset-4',
+ 'preset-5',
+ 'preset-6',
+ 'preset-7',
+ 'preset-8',
+ 'preset-9',
+ 'preset-10',
+ ])
+ .describe(
+ '\* `preset-1` - preset-1\n\* `preset-2` - preset-2\n\* `preset-3` - preset-3\n\* `preset-4` - preset-4\n\* `preset-5` - preset-5\n\* `preset-6` - preset-6\n\* `preset-7` - preset-7\n\* `preset-8` - preset-8\n\* `preset-9` - preset-9\n\* `preset-10` - preset-10'
+ )
+ .describe(
+ "Preset color token used to render the option ('preset-1' through 'preset-10').\n\n\* `preset-1` - preset-1\n\* `preset-2` - preset-2\n\* `preset-3` - preset-3\n\* `preset-4` - preset-4\n\* `preset-5` - preset-5\n\* `preset-6` - preset-6\n\* `preset-7` - preset-7\n\* `preset-8` - preset-8\n\* `preset-9` - preset-9\n\* `preset-10` - preset-10"
+ ),
+ })
+ .describe('An allowed value of a select custom property.')
+ )
+ .nullish()
+ .describe(
+ "For select properties: the allowed options. Required (non-empty) when display_type is 'select'; cleared server-side for other types."
+ ),
})
.describe(
"A team-scoped definition of a custom account property — the attribute side of the model.\n\nHolds only the property's shape (name, display type, big-number flag). Per-account values are\nstored separately, so this serializer never reads or writes account values."
@@ -252,6 +334,7 @@ export const CustomPropertyDefinitionsUpdateBody = /* @__PURE__ */ zod
export const customPropertyDefinitionsPartialUpdateBodyNameMax = 400
export const customPropertyDefinitionsPartialUpdateBodyIsBigNumberDefault = false
+export const customPropertyDefinitionsPartialUpdateBodyOptionsItemLabelMax = 400
export const CustomPropertyDefinitionsPartialUpdateBody = /* @__PURE__ */ zod
.object({
@@ -262,18 +345,58 @@ export const CustomPropertyDefinitionsPartialUpdateBody = /* @__PURE__ */ zod
.describe('Human-readable name of the custom property. Unique within the team.'),
description: zod.string().nullish().describe('Optional description of what the property represents.'),
display_type: zod
- .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean'])
+ .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', 'select'])
.describe(
- '\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean'
+ '\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean\n\* `select` - select'
)
.optional()
.describe(
- "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', or 'boolean'.\n\n\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean"
+ "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', or 'select'.\n\n\* `text` - text\n\* `number` - number\n\* `currency` - currency\n\* `percent` - percent\n\* `date` - date\n\* `datetime` - datetime\n\* `boolean` - boolean\n\* `select` - select"
),
is_big_number: zod
.boolean()
.default(customPropertyDefinitionsPartialUpdateBodyIsBigNumberDefault)
.describe('Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties.'),
+ options: zod
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Server-assigned stable id of the option. Omit for new options; send it back unchanged when editing so renames and removals can be told apart.'
+ ),
+ label: zod
+ .string()
+ .max(customPropertyDefinitionsPartialUpdateBodyOptionsItemLabelMax)
+ .describe("Display label of the option. Stored as the account's value when picked."),
+ color: zod
+ .enum([
+ 'preset-1',
+ 'preset-2',
+ 'preset-3',
+ 'preset-4',
+ 'preset-5',
+ 'preset-6',
+ 'preset-7',
+ 'preset-8',
+ 'preset-9',
+ 'preset-10',
+ ])
+ .describe(
+ '\* `preset-1` - preset-1\n\* `preset-2` - preset-2\n\* `preset-3` - preset-3\n\* `preset-4` - preset-4\n\* `preset-5` - preset-5\n\* `preset-6` - preset-6\n\* `preset-7` - preset-7\n\* `preset-8` - preset-8\n\* `preset-9` - preset-9\n\* `preset-10` - preset-10'
+ )
+ .describe(
+ "Preset color token used to render the option ('preset-1' through 'preset-10').\n\n\* `preset-1` - preset-1\n\* `preset-2` - preset-2\n\* `preset-3` - preset-3\n\* `preset-4` - preset-4\n\* `preset-5` - preset-5\n\* `preset-6` - preset-6\n\* `preset-7` - preset-7\n\* `preset-8` - preset-8\n\* `preset-9` - preset-9\n\* `preset-10` - preset-10"
+ ),
+ })
+ .describe('An allowed value of a select custom property.')
+ )
+ .nullish()
+ .describe(
+ "For select properties: the allowed options. Required (non-empty) when display_type is 'select'; cleared server-side for other types."
+ ),
})
.describe(
"A team-scoped definition of a custom account property — the attribute side of the model.\n\nHolds only the property's shape (name, display type, big-number flag). Per-account values are\nstored separately, so this serializer never reads or writes account values."
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx
index 4e7421a6aadb..549e99341b52 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertyModal.tsx
@@ -1,11 +1,13 @@
import { useActions, useValues } from 'kea'
import { Form } from 'kea-forms'
-import { IconRefresh } from '@posthog/icons'
+import { IconPlus, IconRefresh, IconTrash } from '@posthog/icons'
import {
LemonBanner,
LemonButton,
+ LemonColorPicker,
LemonInput,
+ LemonLabel,
LemonModal,
LemonSearchableSelect,
LemonSelect,
@@ -15,12 +17,20 @@ import {
Link,
} from '@posthog/lemon-ui'
+import type { DataColorToken } from 'lib/colors'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { LemonSegmentedButton } from 'lib/lemon-ui/LemonSegmentedButton'
import { urls } from 'scenes/urls'
+import type { CustomPropertyOptionApi } from 'products/customer_analytics/frontend/generated/api.schemas'
+
import { CustomPropertySourceMode, customPropertyDefinitionsLogic } from './customPropertyDefinitionsLogic'
-import { DISPLAY_TYPE_OPTIONS, isNumericDisplayType } from './customPropertyTypes'
+import {
+ DISPLAY_TYPE_OPTIONS,
+ NEW_OPTION_ID_PREFIX,
+ OPTION_COLOR_TOKENS,
+ isNumericDisplayType,
+} from './customPropertyTypes'
const SOURCE_MODE_OPTIONS: { value: CustomPropertySourceMode; label: string }[] = [
{ value: 'manual', label: 'Manual' },
@@ -28,6 +38,67 @@ const SOURCE_MODE_OPTIONS: { value: CustomPropertySourceMode; label: string }[]
{ value: 'workflow', label: 'Workflow' },
]
+function CustomPropertyOptionsEditor(): JSX.Element {
+ const { customPropertyForm } = useValues(customPropertyDefinitionsLogic)
+ const { setCustomPropertyFormValue } = useActions(customPropertyDefinitionsLogic)
+
+ const options = customPropertyForm.options
+ const setOptions = (next: CustomPropertyOptionApi[]): void => setCustomPropertyFormValue('options', next)
+
+ return (
+ <div className="flex flex-col gap-2">
+ <LemonLabel>Options</LemonLabel>
+ {options.map((option, index) => (
+ <div key={option.id ?? index} className="flex items-start gap-2">
+ <LemonColorPicker
+ colorTokens={OPTION_COLOR_TOKENS}
+ selectedColorToken={option.color as DataColorToken}
+ onSelectColorToken={(colorToken) =>
+ setOptions(
+ options.map((candidate, candidateIndex) =>
+ candidateIndex === index
+ ? { ...candidate, color: colorToken as CustomPropertyOptionApi['color'] }
+ : candidate
+ )
+ )
+ }
+ hideDropdown
+ />
+ <div className="flex-1">
+ <LemonField name={['options', index, 'label']}>
+ <LemonInput placeholder="Option label" fullWidth />
+ </LemonField>
+ </div>
+ <LemonButton
+ icon={<IconTrash />}
+ size="small"
+ tooltip="Remove option"
+ onClick={() => setOptions(options.filter((_, candidateIndex) => candidateIndex !== index))}
+ />
+ </div>
+ ))}
+ <LemonButton
+ type="secondary"
+ icon={<IconPlus />}
+ onClick={() =>
+ setOptions([
+ ...options,
+ {
+ id: `${NEW_OPTION_ID_PREFIX}${crypto.randomUUID()}`,
+ label: '',
+ color: OPTION_COLOR_TOKENS[
+ options.length % OPTION_COLOR_TOKENS.length
+ ] as CustomPropertyOptionApi['color'],
+ },
+ ])
+ }
+ >
+ Add option
+ </LemonButton>
+ </div>
+ )
+}
+
export function CustomPropertyModal(): JSX.Element {
const {
modalVisible,
@@ -68,11 +139,13 @@ export function CustomPropertyModal(): JSX.Element {
)
const submitDisabledReason =
- sourceMode === 'data_warehouse' && noViews
- ? 'No materialized views are available'
- : sourceMode === 'workflow' && editingReferences.length === 0
- ? 'Create a workflow that updates this property first'
- : undefined
+ customPropertyForm.displayType === 'select' && customPropertyForm.options.length === 0
+ ? 'Add at least one option'
+ : sourceMode === 'data_warehouse' && noViews
+ ? 'No materialized views are available'
+ : sourceMode === 'workflow' && editingReferences.length === 0
+ ? 'Create a workflow that updates this property first'
+ : undefined
return (
<LemonModal
@@ -122,6 +195,7 @@ export function CustomPropertyModal(): JSX.Element {
)}
</LemonField>
)}
+ {customPropertyForm.displayType === 'select' && <CustomPropertyOptionsEditor />}
<LemonField name="sourceMode" label="Source">
{({ value, onChange }) => (
<LemonSegmentedButton value={value} onChange={onChange} options={sourceModeOptions} fullWidth />
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts
index 3f520aa9d35c..b1d4446bfb3b 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts
@@ -116,6 +116,7 @@ describe('customPropertyDefinitionsLogic', () => {
description: '',
displayType: 'currency',
isBigNumber: true,
+ options: [],
sourceMode: 'data_warehouse',
savedQuery: 'view-1',
sourceColumn: 'mrr',
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts
index 7425eabff6cf..8b6b9d4f624a 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts
@@ -22,11 +22,12 @@ import {
import type {
CustomPropertyDefinitionApi,
CustomPropertyDisplayTypeEnumApi,
+ CustomPropertyOptionApi,
CustomPropertyReferenceApi,
} from 'products/customer_analytics/frontend/generated/api.schemas'
import type { customPropertyDefinitionsLogicType } from './customPropertyDefinitionsLogicType'
-import { isNumericDisplayType } from './customPropertyTypes'
+import { NEW_OPTION_ID_PREFIX, isNumericDisplayType, optionLabelError } from './customPropertyTypes'
export type CustomPropertySourceMode = 'manual' | 'data_warehouse' | 'workflow'
@@ -35,6 +36,7 @@ export interface CustomPropertyFormValues {
description: string
displayType: CustomPropertyDisplayTypeEnumApi
isBigNumber: boolean
+ options: CustomPropertyOptionApi[]
sourceMode: CustomPropertySourceMode
savedQuery: string | null
sourceColumn: string | null
@@ -47,6 +49,7 @@ const DEFAULT_FORM_VALUES: CustomPropertyFormValues = {
description: '',
displayType: 'text',
isBigNumber: false,
+ options: [],
sourceMode: 'manual',
savedQuery: null,
sourceColumn: null,
@@ -59,17 +62,29 @@ const serializeDefinition = ({
description,
displayType,
isBigNumber,
+ options,
}: CustomPropertyFormValues): {
name: string
description: string | null
display_type: CustomPropertyDisplayTypeEnumApi
is_big_number: boolean
+ options?: CustomPropertyOptionApi[]
} => ({
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,
+ // Options only apply to select; the backend clears them for other types.
+ ...(displayType === 'select'
+ ? {
+ options: options.map(({ id, label, color }) => ({
+ ...(id && !id.startsWith(NEW_OPTION_ID_PREFIX) ? { id } : {}),
+ label: label.trim(),
+ color,
+ })),
+ }
+ : {}),
})
const handleNameConflict = (error: unknown, setManualErrors: (errors: { name: string }) => void): boolean => {
@@ -170,8 +185,20 @@ export const customPropertyDefinitionsLogic = kea<customPropertyDefinitionsLogic
forms(({ actions, values }) => ({
customPropertyForm: {
defaults: DEFAULT_FORM_VALUES,
- errors: ({ name, sourceMode, savedQuery, sourceColumn, keyColumn }: CustomPropertyFormValues) => ({
+ errors: ({
+ name,
+ displayType,
+ options,
+ sourceMode,
+ savedQuery,
+ sourceColumn,
+ keyColumn,
+ }: CustomPropertyFormValues) => ({
name: !name?.trim() ? 'Name is required' : undefined,
+ options:
+ displayType === 'select'
+ ? options.map((_, index) => ({ label: optionLabelError(options, index) }))
+ : undefined,
savedQuery: sourceMode === 'data_warehouse' && !savedQuery ? 'Select a view' : undefined,
sourceColumn: sourceMode === 'data_warehouse' && !sourceColumn ? 'Select the value column' : undefined,
keyColumn: sourceMode === 'data_warehouse' && !keyColumn ? 'Select the key column' : undefined,
@@ -257,6 +284,7 @@ export const customPropertyDefinitionsLogic = kea<customPropertyDefinitionsLogic
description: definition.description ?? '',
displayType: definition.display_type,
isBigNumber: definition.is_big_number ?? false,
+ options: definition.options ?? [],
sourceMode: definition.source
? 'data_warehouse'
: definition.references?.length
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts
index b509029c3be0..f162cd4c41ce 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts
@@ -1,5 +1,6 @@
import type {
CustomPropertyDisplayTypeEnumApi,
+ CustomPropertyOptionApi,
CustomPropertySourceApi,
} from 'products/customer_analytics/frontend/generated/api.schemas'
@@ -8,6 +9,7 @@ import {
formatCustomPropertyValue,
isNumericDisplayType,
labelForDisplayType,
+ optionLabelError,
sourceSyncStatus,
} from './customPropertyTypes'
@@ -70,6 +72,24 @@ describe('customPropertyTypes', () => {
})
})
+ describe('optionLabelError', () => {
+ const options = [
+ { label: 'Open', color: 'preset-1' },
+ { label: ' Open ', color: 'preset-2' },
+ { label: ' ', color: 'preset-3' },
+ { label: 'Closed', color: 'preset-4' },
+ ] as CustomPropertyOptionApi[]
+
+ it.each([
+ ['first occurrence is valid', 0, undefined],
+ ['later duplicate after trim is flagged', 1, 'Duplicate option label.'],
+ ['blank label is flagged', 2, 'Please enter a label.'],
+ ['unique label is valid', 3, undefined],
+ ])('%s', (_name, index, expected) => {
+ expect(optionLabelError(options, index)).toBe(expected)
+ })
+ })
+
it('derives sync status from the source state', () => {
expect(sourceSyncStatus(buildSource({})).level).toBe('synced')
expect(sourceSyncStatus(buildSource({ last_synced_at: null })).level).toBe('pending')
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts
index 37f04263ed43..68af4db466d2 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts
@@ -1,8 +1,10 @@
+import { DataColorToken } from 'lib/colors'
import { humanFriendlyCurrency, humanFriendlyLargeNumber, humanFriendlyNumber, percentage } from 'lib/utils/numbers'
import type {
CustomPropertyDefinitionApi,
CustomPropertyDisplayTypeEnumApi,
+ CustomPropertyOptionApi,
CustomPropertySourceApi,
} from 'products/customer_analytics/frontend/generated/api.schemas'
@@ -22,8 +24,30 @@ export const DISPLAY_TYPE_OPTIONS: DisplayTypeOption[] = [
{ value: 'date', label: 'Date', isNumeric: false },
{ value: 'datetime', label: 'Date & time', isNumeric: false },
{ value: 'boolean', label: 'True / false', isNumeric: false },
+ { value: 'select', label: 'Select', isNumeric: false },
]
+// Keep in sync with CUSTOM_PROPERTY_OPTION_COLORS in the backend's constants.py.
+export const OPTION_COLOR_TOKENS: DataColorToken[] = Array.from(
+ { length: 10 },
+ (_, index) => `preset-${index + 1}` as DataColorToken
+)
+
+// New options get a client-side id for a stable React key; the server mints the real id, so
+// these are stripped from the payload on save.
+export const NEW_OPTION_ID_PREFIX = 'new-'
+
+export function optionLabelError(options: CustomPropertyOptionApi[], index: number): string | undefined {
+ const label = options[index].label.trim()
+ if (!label) {
+ return 'Please enter a label.'
+ }
+ if (options.slice(0, index).some((option) => option.label.trim() === label)) {
+ return 'Duplicate option label.'
+ }
+ return undefined
+}
+
export function labelForDisplayType(displayType: CustomPropertyDisplayTypeEnumApi): string {
return DISPLAY_TYPE_OPTIONS.find((option) => option.value === displayType)?.label ?? displayType
}
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 813fde05f555..6ced5d4a07b2 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -14205,6 +14205,7 @@ export namespace Schemas {
* * `date` - date
* * `datetime` - datetime
* * `boolean` - boolean
+ * * `select` - select
*/
export type CustomPropertyDisplayTypeEnum = typeof CustomPropertyDisplayTypeEnum[keyof typeof CustomPropertyDisplayTypeEnum];
@@ -14217,8 +14218,66 @@ export namespace Schemas {
Date: 'date',
Datetime: 'datetime',
Boolean: 'boolean',
+ Select: 'select',
} as const;
+ /**
+ * * `preset-1` - preset-1
+ * * `preset-2` - preset-2
+ * * `preset-3` - preset-3
+ * * `preset-4` - preset-4
+ * * `preset-5` - preset-5
+ * * `preset-6` - preset-6
+ * * `preset-7` - preset-7
+ * * `preset-8` - preset-8
+ * * `preset-9` - preset-9
+ * * `preset-10` - preset-10
+ */
+ export type CustomPropertyOptionColorEnum = typeof CustomPropertyOptionColorEnum[keyof typeof CustomPropertyOptionColorEnum];
+
+
+ export const CustomPropertyOptionColorEnum = {
+ Preset1: 'preset-1',
+ Preset2: 'preset-2',
+ Preset3: 'preset-3',
+ Preset4: 'preset-4',
+ Preset5: 'preset-5',
+ Preset6: 'preset-6',
+ Preset7: 'preset-7',
+ Preset8: 'preset-8',
+ Preset9: 'preset-9',
+ Preset10: 'preset-10',
+ } as const;
+
+ /**
+ * An allowed value of a select custom property.
+ */
+ export interface CustomPropertyOption {
+ /**
+ * Server-assigned stable id of the option. Omit for new options; send it back unchanged when editing so renames and removals can be told apart.
+ * @nullable
+ */
+ id?: string | null;
+ /**
+ * Display label of the option. Stored as the account's value when picked.
+ * @maxLength 400
+ */
+ label: string;
+ /** Preset color token used to render the option ('preset-1' through 'preset-10').
+ *
+ * * `preset-1` - preset-1
+ * * `preset-2` - preset-2
+ * * `preset-3` - preset-3
+ * * `preset-4` - preset-4
+ * * `preset-5` - preset-5
+ * * `preset-6` - preset-6
+ * * `preset-7` - preset-7
+ * * `preset-8` - preset-8
+ * * `preset-9` - preset-9
+ * * `preset-10` - preset-10 */
+ color: CustomPropertyOptionColorEnum;
+ }
+
/**
* Binds a materialized data-warehouse view column to a custom property definition; the view's
* values are synced onto matching accounts on each materialization.
@@ -14292,7 +14351,7 @@ export namespace Schemas {
* @nullable
*/
description?: string | null;
- /** How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', or 'boolean'.
+ /** How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', or 'select'.
*
* * `text` - text
* * `number` - number
@@ -14300,10 +14359,16 @@ export namespace Schemas {
* * `percent` - percent
* * `date` - date
* * `datetime` - datetime
- * * `boolean` - boolean */
+ * * `boolean` - boolean
+ * * `select` - select */
display_type: CustomPropertyDisplayTypeEnum;
/** Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties. */
is_big_number?: boolean;
+ /**
+ * For select properties: the allowed options. Required (non-empty) when display_type is 'select'; cleared server-side for other types.
+ * @nullable
+ */
+ options?: CustomPropertyOption[] | null;
/** The data-warehouse view-sync binding feeding this property, or null when values are set manually. */
readonly source: CustomPropertySource | null;
readonly created_at: string;
@@ -36706,7 +36771,7 @@ export namespace Schemas {
* @nullable
*/
description?: string | null;
- /** How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', or 'boolean'.
+ /** How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', or 'select'.
*
* * `text` - text
* * `number` - number
@@ -36714,10 +36779,16 @@ export namespace Schemas {
* * `percent` - percent
* * `date` - date
* * `datetime` - datetime
- * * `boolean` - boolean */
+ * * `boolean` - boolean
+ * * `select` - select */
display_type?: CustomPropertyDisplayTypeEnum;
/** Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties. */
is_big_number?: boolean;
+ /**
+ * For select properties: the allowed options. Required (non-empty) when display_type is 'select'; cleared server-side for other types.
+ * @nullable
+ */
+ options?: CustomPropertyOption[] | null;
/** The data-warehouse view-sync binding feeding this property, or null when values are set manually. */
readonly source?: CustomPropertySource | null;
readonly created_at?: string;
diff --git a/services/mcp/src/generated/customer_analytics/api.ts b/services/mcp/src/generated/customer_analytics/api.ts
index 67439c1978cc..c203b9a38a55 100644
--- a/services/mcp/src/generated/customer_analytics/api.ts
+++ b/services/mcp/src/generated/customer_analytics/api.ts
@@ -295,6 +295,7 @@ export const CustomPropertyDefinitionsCreateParams = /* @__PURE__ */ zod.object(
export const customPropertyDefinitionsCreateBodyNameMax = 400
export const customPropertyDefinitionsCreateBodyIsBigNumberDefault = false
+export const customPropertyDefinitionsCreateBodyOptionsItemLabelMax = 400
export const CustomPropertyDefinitionsCreateBody = /* @__PURE__ */ zod
.object({
@@ -304,17 +305,57 @@ export const CustomPropertyDefinitionsCreateBody = /* @__PURE__ */ zod
.describe('Human-readable name of the custom property. Unique within the team.'),
description: zod.string().nullish().describe('Optional description of what the property represents.'),
display_type: zod
- .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean'])
+ .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', 'select'])
.describe(
- '* `text` - text\n* `number` - number\n* `currency` - currency\n* `percent` - percent\n* `date` - date\n* `datetime` - datetime\n* `boolean` - boolean'
+ '* `text` - text\n* `number` - number\n* `currency` - currency\n* `percent` - percent\n* `date` - date\n* `datetime` - datetime\n* `boolean` - boolean\n* `select` - select'
)
.describe(
- "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', or 'boolean'.\n\n* `text` - text\n* `number` - number\n* `currency` - currency\n* `percent` - percent\n* `date` - date\n* `datetime` - datetime\n* `boolean` - boolean"
+ "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', or 'select'.\n\n* `text` - text\n* `number` - number\n* `currency` - currency\n* `percent` - percent\n* `date` - date\n* `datetime` - datetime\n* `boolean` - boolean\n* `select` - select"
),
is_big_number: zod
.boolean()
.default(customPropertyDefinitionsCreateBodyIsBigNumberDefault)
.describe('Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties.'),
+ options: zod
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Server-assigned stable id of the option. Omit for new options; send it back unchanged when editing so renames and removals can be told apart.'
+ ),
+ label: zod
+ .string()
+ .max(customPropertyDefinitionsCreateBodyOptionsItemLabelMax)
+ .describe("Display label of the option. Stored as the account's value when picked."),
+ color: zod
+ .enum([
+ 'preset-1',
+ 'preset-2',
+ 'preset-3',
+ 'preset-4',
+ 'preset-5',
+ 'preset-6',
+ 'preset-7',
+ 'preset-8',
+ 'preset-9',
+ 'preset-10',
+ ])
+ .describe(
+ '* `preset-1` - preset-1\n* `preset-2` - preset-2\n* `preset-3` - preset-3\n* `preset-4` - preset-4\n* `preset-5` - preset-5\n* `preset-6` - preset-6\n* `preset-7` - preset-7\n* `preset-8` - preset-8\n* `preset-9` - preset-9\n* `preset-10` - preset-10'
+ )
+ .describe(
+ "Preset color token used to render the option ('preset-1' through 'preset-10').\n\n* `preset-1` - preset-1\n* `preset-2` - preset-2\n* `preset-3` - preset-3\n* `preset-4` - preset-4\n* `preset-5` - preset-5\n* `preset-6` - preset-6\n* `preset-7` - preset-7\n* `preset-8` - preset-8\n* `preset-9` - preset-9\n* `preset-10` - preset-10"
+ ),
+ })
+ .describe('An allowed value of a select custom property.')
+ )
+ .nullish()
+ .describe(
+ "For select properties: the allowed options. Required (non-empty) when display_type is 'select'; cleared server-side for other types."
+ ),
})
.describe(
"A team-scoped definition of a custom account property — the attribute side of the model.\n\nHolds only the property's shape (name, display type, big-number flag). Per-account values are\nstored separately, so this serializer never reads or writes account values."
@@ -340,6 +381,8 @@ export const CustomPropertyDefinitionsPartialUpdateParams = /* @__PURE__ */ zod.
export const customPropertyDefinitionsPartialUpdateBodyNameMax = 400
+export const customPropertyDefinitionsPartialUpdateBodyOptionsItemLabelMax = 400
+
export const CustomPropertyDefinitionsPartialUpdateBody = /* @__PURE__ */ zod
.object({
name: zod
@@ -349,18 +392,58 @@ export const CustomPropertyDefinitionsPartialUpdateBody = /* @__PURE__ */ zod
.describe('Human-readable name of the custom property. Unique within the team.'),
description: zod.string().nullish().describe('Optional description of what the property represents.'),
display_type: zod
- .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean'])
+ .enum(['text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', 'select'])
.describe(
- '* `text` - text\n* `number` - number\n* `currency` - currency\n* `percent` - percent\n* `date` - date\n* `datetime` - datetime\n* `boolean` - boolean'
+ '* `text` - text\n* `number` - number\n* `currency` - currency\n* `percent` - percent\n* `date` - date\n* `datetime` - datetime\n* `boolean` - boolean\n* `select` - select'
)
.optional()
.describe(
- "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', or 'boolean'.\n\n* `text` - text\n* `number` - number\n* `currency` - currency\n* `percent` - percent\n* `date` - date\n* `datetime` - datetime\n* `boolean` - boolean"
+ "How the property is interpreted and rendered: 'text', 'number', 'currency', 'percent', 'date', 'datetime', 'boolean', or 'select'.\n\n* `text` - text\n* `number` - number\n* `currency` - currency\n* `percent` - percent\n* `date` - date\n* `datetime` - datetime\n* `boolean` - boolean\n* `select` - select"
),
is_big_number: zod
.boolean()
.optional()
.describe('Abbreviate large numbers (e.g. 10,000 → 10K). Only applies to numeric properties.'),
+ options: zod
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Server-assigned stable id of the option. Omit for new options; send it back unchanged when editing so renames and removals can be told apart.'
+ ),
+ label: zod
+ .string()
+ .max(customPropertyDefinitionsPartialUpdateBodyOptionsItemLabelMax)
+ .describe("Display label of the option. Stored as the account's value when picked."),
+ color: zod
+ .enum([
+ 'preset-1',
+ 'preset-2',
+ 'preset-3',
+ 'preset-4',
+ 'preset-5',
+ 'preset-6',
+ 'preset-7',
+ 'preset-8',
+ 'preset-9',
+ 'preset-10',
+ ])
+ .describe(
+ '* `preset-1` - preset-1\n* `preset-2` - preset-2\n* `preset-3` - preset-3\n* `preset-4` - preset-4\n* `preset-5` - preset-5\n* `preset-6` - preset-6\n* `preset-7` - preset-7\n* `preset-8` - preset-8\n* `preset-9` - preset-9\n* `preset-10` - preset-10'
+ )
+ .describe(
+ "Preset color token used to render the option ('preset-1' through 'preset-10').\n\n* `preset-1` - preset-1\n* `preset-2` - preset-2\n* `preset-3` - preset-3\n* `preset-4` - preset-4\n* `preset-5` - preset-5\n* `preset-6` - preset-6\n* `preset-7` - preset-7\n* `preset-8` - preset-8\n* `preset-9` - preset-9\n* `preset-10` - preset-10"
+ ),
+ })
+ .describe('An allowed value of a select custom property.')
+ )
+ .nullish()
+ .describe(
+ "For select properties: the allowed options. Required (non-empty) when display_type is 'select'; cleared server-side for other types."
+ ),
})
.describe(
"A team-scoped definition of a custom account property — the attribute side of the model.\n\nHolds only the property's shape (name, display type, big-number flag). Per-account values are\nstored separately, so this serializer never reads or writes account values."
diff --git a/services/mcp/src/tools/generated/customer_analytics.ts b/services/mcp/src/tools/generated/customer_analytics.ts
index a5beb1a2ccc8..57d1b17dbb17 100644
--- a/services/mcp/src/tools/generated/customer_analytics.ts
+++ b/services/mcp/src/tools/generated/customer_analytics.ts
@@ -324,6 +324,9 @@ const customPropertyDefinitionsCreate = (): ToolBase<
if (params.is_big_number !== undefined) {
body['is_big_number'] = params.is_big_number
}
+ if (params.options !== undefined) {
+ body['options'] = params.options
+ }
const result = await context.api.request<Schemas.CustomPropertyDefinition>({
method: 'POST',
path: `/api/projects/${encodeURIComponent(String(projectId))}/custom_property_definitions/`,
@@ -395,6 +398,9 @@ const customPropertyDefinitionsPartialUpdate = (): ToolBase<
if (params.is_big_number !== undefined) {
body['is_big_number'] = params.is_big_number
}
+ if (params.options !== undefined) {
+ body['options'] = params.options
+ }
const result = await context.api.request<Schemas.CustomPropertyDefinition>({
method: 'PATCH',
path: `/api/projects/${encodeURIComponent(String(projectId))}/custom_property_definitions/${encodeURIComponent(String(params.id))}/`,