: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
feat(flags): restore v2 match-by UI (#58945)
Dylan Martinb1ec9f9b0cbf
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsxindex 81d5575a0ce0..dc5f4f04e606 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx@@ -16,7 +16,7 @@ import React, { useRef, useState } from 'react'import { v4 as uuidv4 } from 'uuid'import {- IconBalance,+ IconBrackets,IconCollapse,IconCopy,IconEllipsis,@@ -93,6 +93,18 @@ interface FeatureFlagReleaseConditionsCollapsibleProps extends FeatureFlagReleashideMatchOptions?: boolean}+const PERSON = 'person' as const+type AggregationValue = number | typeof PERSON++type MatchByOption = {+ value: string+ icon: JSX.Element+ label: string+ description: string+ badge?: { type: 'warning' | 'highlight'; text: string }+ learnMoreUrl?: string+}+function summarizeProperties(properties: AnyPropertyFilter[], aggregationTargetName: string): string {if (!properties || properties.length === 0) {// Capitalize first letter of aggregation target name@@ -302,8 +314,8 @@ interface ConditionProps {taxonomicGroupTypesForCondition: (conditionGroupTypeIndex: number | null | undefined) => TaxonomicFilterGroupType[]groupTypes: Map<GroupTypeIndex, GroupType>setConditionAggregation: (index: number, groupTypeIndex: number | null) => void- isMixedTargetingEnabled: boolean- mixedGroupTypeIndex: number+ isTargetingV2Enabled: boolean+ isDeviceTargeting: booleanonMoveUp: () => voidonMoveDown: () => voidonDuplicate: () => void@@ -371,8 +383,8 @@ const ConditionContent = ({taxonomicGroupTypesForCondition,groupTypes,setConditionAggregation,- isMixedTargetingEnabled,- mixedGroupTypeIndex,+ isTargetingV2Enabled,+ isDeviceTargeting,onMoveUp,onMoveDown,onDuplicate,@@ -519,39 +531,46 @@ const ConditionContent = ({/></div>- {isMixedTargetingEnabled && groupTypes.size > 0 && (+ {isTargetingV2Enabled && groupTypes.size > 0 && !isDeviceTargeting && (<div>- <LemonLabel className="mb-1">Targeting criteria</LemonLabel>- <LemonSelect+ <LemonLabel className="mb-1">Target by</LemonLabel>+ <LemonSelect<AggregationValue>size="small"data-attr={`condition-set-${index}-aggregation`}- value={group.aggregation_group_type_index != null ? 'group' : 'person'}+ value={+ group.aggregation_group_type_index !== undefined+ ? (group.aggregation_group_type_index ?? PERSON)+ : (releaseFilters.aggregation_group_type_index ?? PERSON)+ }onChange={(value) => {- setConditionAggregation(- index,- value === 'person' ? null : mixedGroupTypeIndex- )+ setConditionAggregation(index, value === PERSON ? null : value)}}- options={(() => {- const gt = groupTypes.get(mixedGroupTypeIndex as GroupTypeIndex)- const groupLabel = gt- ? gt.name_plural ||- gt.group_type.charAt(0).toUpperCase() +- gt.group_type.slice(1) +- 's'- : 'Groups'- return [- { value: 'person' as const, label: 'Users' },- {- value: 'group' as const,- label: groupLabel,- },- ]- })()}+ options={[+ {+ options: [+ {+ value: PERSON,+ label: 'Users',+ icon: <IconPerson />,+ },+ ],+ },+ {+ title: 'Group types',+ options: Array.from(groupTypes.values()).map((gt) => ({+ value: gt.group_type_index as number,+ label:+ gt.name_plural ||+ gt.group_type.charAt(0).toUpperCase() ++ gt.group_type.slice(1) ++ 's',+ icon: <IconPeople />,+ })),+ },+ ]}/></div>)}-<div><LemonLabel className="mb-1">Match filters</LemonLabel><PropertyFilters@@ -802,14 +821,15 @@ export function FeatureFlagReleaseConditionsCollapsible({openConditions,properties,isMixedTargeting,- mixedGroupTypeIndex,isAnyItemDragging,draggedGroup,} = useValues(releaseConditionsLogic)const { featureFlags } = useValues(featureFlagLogic)const isDragDropEnabled = !!featureFlags[FEATURE_FLAGS.FEATURE_FLAG_DRAG_DROP_CONDITIONS]- const isMixedTargetingEnabled = !!featureFlags[FEATURE_FLAGS.FEATURE_FLAG_MIXED_TARGETING]+ // The mixed-targeting flag now gates the unified v2 UI (Properties / Device with full per-condition group-type selector).+ // The legacy 4-card path is reached only when the flag is off.+ const isTargetingV2Enabled = !!featureFlags[FEATURE_FLAGS.FEATURE_FLAG_MIXED_TARGETING]// Ref map for focus managementconst optionRefs = useRef<Record<string, HTMLDivElement | null>>({})@@ -829,7 +849,6 @@ export function FeatureFlagReleaseConditionsCollapsible({setOpenConditions,setIsMixedTargeting,switchToMixedTargeting,- setMixedGroupTypeIndex,setIsAnyItemDragging,setDraggedGroup,} = useActions(releaseConditionsLogic)@@ -926,19 +945,88 @@ export function FeatureFlagReleaseConditionsCollapsible({}const showGroupsOptions = groupTypes.size > 0+ const isDeviceTargeting = bucketingIdentifier === FeatureFlagBucketingIdentifier.DEVICE_ID++ const v2MatchByOptions = [+ {+ value: 'properties',+ icon: <IconBrackets className="text-base shrink-0" />,+ label: 'Properties',+ description: showGroupsOptions+ ? 'Target by user or group property filters. Each condition picks its own targeting type.'+ : 'Target by user property filters.',+ },+ ...(onBucketingIdentifierChange+ ? [+ {+ value: 'device',+ icon: <IconLaptop className="text-base shrink-0" />,+ label: 'Device',+ description: 'Stable assignment per device. Good fit for experiments on anonymous users.',+ badge: { type: 'warning' as const, text: 'BETA' },+ learnMoreUrl: 'https://posthog.com/docs/feature-flags/device-bucketing',+ },+ ]+ : []),+ ] satisfies MatchByOption[]++ const legacyMatchByOptions = [+ {+ value: 'user',+ icon: <IconPerson className="text-base shrink-0" />,+ label: 'User',+ description: 'Stable assignment for logged-in users based on their distinct ID.',+ },+ ...(onBucketingIdentifierChange+ ? [+ {+ value: 'device',+ icon: <IconLaptop className="text-base shrink-0" />,+ label: 'Device',+ description: 'Stable assignment per device. Good fit for experiments on anonymous users.',+ badge: { type: 'warning' as const, text: 'BETA' },+ learnMoreUrl: 'https://posthog.com/docs/feature-flags/device-bucketing',+ },+ ]+ : []),+ ...(showGroupsOptions+ ? [+ {+ value: 'group',+ icon: <IconPeople className="text-base shrink-0" />,+ label: 'Group',+ description:+ 'Stable assignment for everyone in an organization, company, or other custom group type.',+ },+ ]+ : []),+ ] satisfies MatchByOption[]++ const matchByOptions: MatchByOption[] = isTargetingV2Enabled ? v2MatchByOptions : legacyMatchByOptions// Compute current selected option (shared between keyboard navigation and selection rendering)- const currentSelected = isMixedTargeting- ? 'mixed'+ const currentSelected = isTargetingV2Enabled+ ? isDeviceTargeting && onBucketingIdentifierChange+ ? 'device'+ : 'properties': releaseFilters.aggregation_group_type_index != null? 'group'- : bucketingIdentifier === FeatureFlagBucketingIdentifier.DEVICE_ID+ : isDeviceTargeting? 'device': 'user'// Handler for option selection logic (shared by click and keyboard events)const selectMatchByOption = (value: string): void => {const applyChange = (targetValue: string): void => {+ if (isTargetingV2Enabled) {+ if (targetValue === 'properties') {+ onBucketingIdentifierChange?.(FeatureFlagBucketingIdentifier.DISTINCT_ID)+ } else if (targetValue === 'device') {+ setAggregationGroupTypeIndex(null)+ onBucketingIdentifierChange?.(FeatureFlagBucketingIdentifier.DEVICE_ID)+ }+ return+ }if (targetValue === 'user') {setIsMixedTargeting(false)setAggregationGroupTypeIndex(null)@@ -1023,12 +1111,13 @@ export function FeatureFlagReleaseConditionsCollapsible({// Handle arrow key navigation for radio groupif (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {e.preventDefault()- const options = [- 'user',- ...(onBucketingIdentifierChange ? ['device'] : []),- ...(showGroupsOptions ? ['group'] : []),- ...(showGroupsOptions && isMixedTargetingEnabled ? ['mixed'] : []),- ]+ const options = isTargetingV2Enabled+ ? ['properties', ...(onBucketingIdentifierChange ? ['device'] : [])]+ : [+ 'user',+ ...(onBucketingIdentifierChange ? ['device'] : []),+ ...(showGroupsOptions ? ['group'] : []),+ ]const currentIndex = options.indexOf(currentSelected)let nextIndex = currentIndex@@ -1046,49 +1135,7 @@ export function FeatureFlagReleaseConditionsCollapsible({}}}>- {[- {- value: 'user',- icon: <IconPerson className="text-base shrink-0" />,- label: 'User',- description: 'Stable assignment for logged-in users based on their distinct ID.',- },- ...(onBucketingIdentifierChange- ? [- {- value: 'device',- icon: <IconLaptop className="text-base shrink-0" />,- label: 'Device',- description:- 'Stable assignment per device. Good fit for experiments on anonymous users.',- learnMoreUrl: 'https://posthog.com/docs/feature-flags/device-bucketing',- },- ]- : []),- ...(showGroupsOptions- ? [- {- value: 'group',- icon: <IconPeople className="text-base shrink-0" />,- label: 'Group',- description:- 'Stable assignment for everyone in an organization, company, or other custom group type.',- },- ]- : []),- ...(showGroupsOptions && isMixedTargetingEnabled- ? [- {- value: 'mixed',- icon: <IconBalance className="text-base shrink-0" />,- label: 'User & Group',- description:- 'Mix user and group targeting across condition sets. Each condition set picks its own targeting type.',- badge: { type: 'highlight' as const, text: 'NEW' },- },- ]- : []),- ].map((option) => {+ {matchByOptions.map((option) => {const isSelected = option.value === currentSelectedreturn (@@ -1170,29 +1217,6 @@ export function FeatureFlagReleaseConditionsCollapsible({{groupTypeValues[0]?.group_type}</span>))}- {/* Mixed group type selector */}- {option.value === 'mixed' &&- isSelected &&- isMixedTargeting &&- groupTypeValues.length > 1 && (- <div onClick={(e) => e.stopPropagation()}>- <LemonSelect- size="xsmall"- dropdownMatchSelectWidth={false}- data-attr="feature-flag-mixed-group-type-select"- value={mixedGroupTypeIndex}- onChange={(value) => {- if (value != null) {- setMixedGroupTypeIndex(value)- }- }}- options={groupTypeValues.map((groupType) => ({- value: groupType.group_type_index,- label: groupType.group_type,- }))}- />- </div>- )}</div></div>)@@ -1271,8 +1295,8 @@ export function FeatureFlagReleaseConditionsCollapsible({taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}- isMixedTargetingEnabled={isMixedTargeting}- mixedGroupTypeIndex={mixedGroupTypeIndex}+ isTargetingV2Enabled={isTargetingV2Enabled}+ isDeviceTargeting={isDeviceTargeting}onMoveUp={() => moveConditionSetUp(index)}onMoveDown={() => moveConditionSetDown(index)}onDuplicate={() => duplicateConditionSet(index)}@@ -1345,8 +1369,8 @@ export function FeatureFlagReleaseConditionsCollapsible({taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}- isMixedTargetingEnabled={isMixedTargeting}- mixedGroupTypeIndex={mixedGroupTypeIndex}+ isTargetingV2Enabled={isTargetingV2Enabled}+ isDeviceTargeting={isDeviceTargeting}onMoveUp={() => moveConditionSetUp(index)}onMoveDown={() => moveConditionSetDown(index)}onDuplicate={() => duplicateConditionSet(index)}@@ -1395,8 +1419,8 @@ export function FeatureFlagReleaseConditionsCollapsible({taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}- isMixedTargetingEnabled={isMixedTargeting}- mixedGroupTypeIndex={mixedGroupTypeIndex}+ isTargetingV2Enabled={isTargetingV2Enabled}+ isDeviceTargeting={isDeviceTargeting}onMoveUp={() => moveConditionSetUp(index)}onMoveDown={() => moveConditionSetDown(index)}onDuplicate={() => duplicateConditionSet(index)}@@ -1427,8 +1451,8 @@ export function FeatureFlagReleaseConditionsCollapsible({taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}- isMixedTargetingEnabled={isMixedTargeting}- mixedGroupTypeIndex={mixedGroupTypeIndex}+ isTargetingV2Enabled={isTargetingV2Enabled}+ isDeviceTargeting={isDeviceTargeting}onMoveUp={() => moveConditionSetUp(index)}onMoveDown={() => moveConditionSetDown(index)}onDuplicate={() => duplicateConditionSet(index)}