: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
fix(feature-flags): allow "not in cohort" release conditions in UI (#61486)
Patriciof32c49649822
diff --git a/frontend/src/lib/components/DefinitionPopover/utils.test.ts b/frontend/src/lib/components/DefinitionPopover/utils.test.tsnew file mode 100644index 000000000000..97c11882010b--- /dev/null+++ b/frontend/src/lib/components/DefinitionPopover/utils.test.ts@@ -0,0 +1,20 @@+import { PropertyOperator } from '~/types'++import { allOperatorsToHumanName } from './utils'++describe('allOperatorsToHumanName', () => {+ it.each([+ // Cohort operators have no symbol prefix and must not be sliced+ [PropertyOperator.In, 'in'],+ [PropertyOperator.NotIn, 'not in'],+ // Regular operators drop their 2-char symbol prefix+ [PropertyOperator.Exact, 'equals'],+ [PropertyOperator.IsNot, "doesn't equal"],+ [PropertyOperator.GreaterThan, 'greater than'],+ // Unknown / missing operator falls back to 'equals'+ [undefined, 'equals'],+ [null, 'equals'],+ ])('maps %s to "%s"', (operator, expected) => {+ expect(allOperatorsToHumanName(operator)).toBe(expected)+ })+})diff --git a/frontend/src/lib/components/DefinitionPopover/utils.ts b/frontend/src/lib/components/DefinitionPopover/utils.tsindex 26c00ad80aa5..1b55b3ed62af 100644--- a/frontend/src/lib/components/DefinitionPopover/utils.ts+++ b/frontend/src/lib/components/DefinitionPopover/utils.ts@@ -21,12 +21,19 @@ export function genericOperatorToHumanName(property?: AnyPropertyFilter | null):return 'equals'}+// Most operator labels carry a 2-char "<symbol> " prefix that slice(2) strips (e.g. "= equals"+// -> "equals"). Cohort operators are stored without that prefix ("user in" / "user not in"), so+// slicing would mangle them. Any future prefix-less label must be added here too.+const prefixlessOperatorLabels: Partial<Record<PropertyOperator, string>> = {+ [PropertyOperator.In]: 'in',+ [PropertyOperator.NotIn]: 'not in',+}+export function allOperatorsToHumanName(operator?: PropertyOperator | null): string {+ if (operator && prefixlessOperatorLabels[operator]) {+ return prefixlessOperatorLabels[operator]+ }if (operator && allOperatorsMapping[operator]) {- // for the case of cohort matching, we want to return the operator name without the "In" prefix- if (operator === PropertyOperator.In) {- return 'in'- }return allOperatorsMapping[operator].slice(2)}return 'equals'diff --git a/frontend/src/lib/components/TaxonomicFilter/types.ts b/frontend/src/lib/components/TaxonomicFilter/types.tsindex b2afb655891c..e67ade987d05 100644--- a/frontend/src/lib/components/TaxonomicFilter/types.ts+++ b/frontend/src/lib/components/TaxonomicFilter/types.ts@@ -86,10 +86,9 @@ export type ExcludedOperators = { [key in TaxonomicFilterGroupType]?: PropertyOp/*** Tells `TaxonomicPropertyFilter` to render a row as key-only — the picked* value IS the answer, no operator+value pair alongside it. Used when a- * specific filter type's operator is implicit (e.g. feature flag release- * conditions accept any operator on event properties but treat cohort rows- * as key-only because the cohort *is* the value and the operator is- * implicitly `in`).+ * specific filter type's operator is implicit (e.g. workflow event triggers+ * accept any operator on event properties but treat cohort rows as key-only+ * because the cohort *is* the value and the operator is implicitly `in`).** - `true` — every row in this `PropertyFilters` is key-only.* - `Partial<Record<TaxonomicFilterGroupType, boolean>>` — per-group switch.diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.cohortOperator.test.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.cohortOperator.test.tsxnew file mode 100644index 000000000000..70d814b16269--- /dev/null+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.cohortOperator.test.tsx@@ -0,0 +1,100 @@+import '@testing-library/jest-dom'++import { cleanup, render, waitFor } from '@testing-library/react'+import { Provider } from 'kea'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'+import { mockGetEventDefinitions, mockGetPropertyDefinitions } from '~/test/mocks'+import {+ CohortPropertyFilter,+ CohortType,+ FeatureFlagGroupType,+ FilterLogicalOperator,+ FeatureFlagType,+ PropertyFilterType,+ PropertyOperator,+} from '~/types'++import { FeatureFlagReleaseConditions } from './FeatureFlagReleaseConditions'+import { FeatureFlagReleaseConditionsCollapsible } from './FeatureFlagReleaseConditionsCollapsible'++jest.mock('lib/components/AutoSizer', () => ({+ AutoSizer: ({ renderProp }: { renderProp: (size: { height: number; width: number }) => React.ReactNode }) =>+ renderProp({ height: 400, width: 400 }),+}))++const cohortPowerUsers: Partial<CohortType> = {+ id: 1,+ name: 'Power Users',+ filters: { properties: { id: 'root', type: FilterLogicalOperator.Or, values: [] } },+}++const cohortFilter: CohortPropertyFilter = {+ type: PropertyFilterType.Cohort,+ key: 'id',+ value: 1,+ operator: PropertyOperator.NotIn,+ cohort_name: 'Power Users',+}++function buildFilters(): FeatureFlagType['filters'] {+ const group: FeatureFlagGroupType = {+ properties: [cohortFilter],+ rollout_percentage: 100,+ variant: null,+ sort_key: 'group-1',+ }+ return { groups: [group], multivariate: null, payloads: {} }+}++describe('feature flag release conditions cohort operator', () => {+ beforeEach(() => {+ initKeaTests()+ useMocks({+ get: {+ '/api/projects/:team/event_definitions': mockGetEventDefinitions,+ '/api/projects/:team/property_definitions': mockGetPropertyDefinitions,+ '/api/projects/:team/cohorts/': { results: [cohortPowerUsers], next: null, count: 1 },+ '/api/projects/:team/actions': { results: [] },+ },+ post: {+ '/api/environments/:team/query': { results: [] },+ '/api/projects/:team/feature_flags/user_blast_radius': () => [200, { affected: 0, total: 2 }],+ },+ })+ })++ afterEach(() => {+ cleanup()+ })++ it('renders the in/not-in operator dropdown for a cohort row in FeatureFlagReleaseConditions', async () => {+ render(+ <Provider>+ <FeatureFlagReleaseConditions id="1234" filters={buildFilters()} onChange={jest.fn()} />+ </Provider>+ )++ await waitFor(() => {+ expect(document.querySelector('[data-attr="taxonomic-operator"]')).toBeInTheDocument()+ })+ })++ it('renders the in/not-in operator dropdown for a cohort row in FeatureFlagReleaseConditionsCollapsible', async () => {+ render(+ <Provider>+ <FeatureFlagReleaseConditionsCollapsible+ id="1234"+ flagId={1234}+ filters={buildFilters()}+ onChange={jest.fn()}+ />+ </Provider>+ )++ await waitFor(() => {+ expect(document.querySelector('[data-attr="taxonomic-operator"]')).toBeInTheDocument()+ })+ })+})diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsxindex 04aac8b670ee..3fb0bb20b42d 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx@@ -42,7 +42,6 @@ import {PropertyOperator,} from '~/types'-import { COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS } from './cohortPickerProps'import { featureFlagLogic } from './featureFlagLogic'import {FeatureFlagReleaseConditionsLogicProps,@@ -386,7 +385,6 @@ export function FeatureFlagReleaseConditions({}): null}- {...COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS}hideBehavioralCohorts={!realtimeCohortFlagTargeting}/></div>diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsxindex 33f1d5d37006..5d65f1ffbed1 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx@@ -71,7 +71,6 @@ import {import { INTENT_METADATA } from 'products/feature_flags/frontend/featureFlagTemplateConstants'-import { COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS } from './cohortPickerProps'import { EarlyExitIndicator } from './EarlyExitIndicator'import { FeatureFlagConditionDragHandle } from './FeatureFlagConditionDragHandle'import { FeatureFlagConditionWarning } from './FeatureFlagConditionWarning'@@ -592,7 +591,6 @@ const ConditionContent = ({)}taxonomicFilterOptionsFromProp={filtersTaxonomicOptions}hasRowOperator={false}- {...COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS}hideBehavioralCohorts={!realtimeCohortFlagTargeting}/></div>diff --git a/frontend/src/scenes/feature-flags/cohortPickerProps.ts b/frontend/src/scenes/feature-flags/cohortPickerProps.tsindex 6b5f7ea064fd..c34ac8990f03 100644--- a/frontend/src/scenes/feature-flags/cohortPickerProps.ts+++ b/frontend/src/scenes/feature-flags/cohortPickerProps.ts@@ -4,18 +4,21 @@ import { PropertyOperator } from '~/types'/*** Picker props for surfaces where cohort filters are restricted to `in` only —- * feature flag release conditions and workflow event triggers. Hides recents- * carrying any other cohort operator and renders cohort rows as key-only- * (the cohort *is* the value, operator is implicit).+ * workflow event triggers and heatmap filters. Hides recents carrying any other+ * cohort operator and renders cohort rows as key-only (the cohort *is* the value,+ * operator is implicit).*- * Three call sites use this preset:- * - `FeatureFlagReleaseConditions.tsx`- * - `FeatureFlagReleaseConditionsCollapsible.tsx`+ * Call sites using this preset:* - `products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx`+ * - `frontend/src/scenes/heatmaps/components/FilterPanel.tsx`*- * Spread into `PropertyFilters` / `TaxonomicPropertyFilter` rather than- * passing each prop individually so the configuration travels as one named- * idea and a future change (e.g. allowing `not_in`) edits one place.+ * Feature flag release conditions deliberately do NOT use this preset: flag+ * matching supports `not_in` cohorts (see the Rust cohort-membership evaluation+ * in `rust/feature-flags/src/cohorts/cohort_operations.rs`), so the flag UI+ * shows the full `user in` / `user not in` operator dropdown.+ *+ * Spread into `PropertyFilters` / `TaxonomicPropertyFilter` rather than passing+ * each prop individually so the configuration travels as one named idea.*/export const COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS = {excludedOperators: { [TaxonomicFilterGroupType.Cohorts]: [PropertyOperator.NotIn] },