: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(flags): stop the flag overview misreporting saved targeting (#101315)
posthog[bot]6838e466f1e6
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsxindex e2345c5e7043..0efea6ca0469 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx@@ -45,6 +45,7 @@ import {} from '~/types'import { CohortConditionLink } from 'products/feature_flags/frontend/CohortConditionLink'+import { ConditionSetSummary } from 'products/feature_flags/frontend/ConditionSetSummary'import { FractionalRolloutWarning } from 'products/feature_flags/frontend/FractionalRolloutWarning'import { resolveAggregationGroupTypeIndex } from './aggregation'@@ -202,27 +203,11 @@ export function FeatureFlagReleaseConditions({<div className="flex items-center"><LemonSnack className="mr-2">Set {index + 1}</LemonSnack><div>- {group.properties?.length ? (- <>- {readOnly ? (- <>- Match <b>{aggregationTargetName(group.aggregation_group_type_index)}</b>{' '}- against <b>all</b> criteria- </>- ) : (- <>- Matching{' '}- <b>{aggregationTargetName(group.aggregation_group_type_index)}</b>{' '}- against the criteria- </>- )}- </>- ) : (- <>- Condition set will match{' '}- <b>all {aggregationTargetName(group.aggregation_group_type_index)}</b>- </>- )}+ <ConditionSetSummary+ group={group}+ aggregationTargetName={aggregationTargetName(group.aggregation_group_type_index)}+ readOnly={readOnly}+ /></div></div>{!readOnly && (diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.tsindex 9817d49bafb8..4e86d1de0b07 100644--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts@@ -1836,6 +1836,36 @@ describe('the feature flag release conditions logic', () => {})})+ describe('readonly and editable instances of one flag', () => {+ it('keeps separate filters so the overview does not show the edit form state', () => {+ logic?.unmount()++ logic = featureFlagReleaseConditionsLogic({+ id: 'mode-key-test',+ filters: generateFeatureFlagFilters([+ { properties: [], rollout_percentage: 100, variant: null, sort_key: 'group-1' },+ ]),+ })+ logic.mount()++ const readonlyLogic = featureFlagReleaseConditionsLogic({+ id: 'mode-key-test',+ readOnly: true,+ filters: generateFeatureFlagFilters([+ { properties: [], rollout_percentage: 25, variant: null, sort_key: 'group-1' },+ ]),+ })+ readonlyLogic.mount()++ expect(readonlyLogic.values.filters.groups[0].rollout_percentage).toEqual(25)++ logic.actions.updateConditionSet(0, 70)+ expect(readonlyLogic.values.filters.groups[0].rollout_percentage).toEqual(25)++ readonlyLogic.unmount()+ })+ })+describe('propsChanged does not clobber fresher local edits', () => {it('keeps a local rollout edit when the parent prop has not caught up', async () => {logic?.unmount()diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.tsindex 1c04bbd439a3..7815a16f188b 100644--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts@@ -390,7 +390,9 @@ export type featureFlagReleaseConditionsLogicType = MakeLogicType<export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseConditionsLogicType>([path(['scenes', 'feature-flags', 'featureFlagReleaseConditionsLogic']),props({} as FeatureFlagReleaseConditionsLogicProps),- key(({ id }) => id ?? 'unknown'),+ // The readonly overview and the edit form render the same flag at the same time. They must not+ // share one filters reducer, or the overview keeps showing the state the form was seeded with.+ key(({ id, readOnly }) => `${id ?? 'unknown'}${readOnly ? '-readonly' : ''}`),connect(() => ({values: [projectLogic, ['currentProjectId'], groupsModel, ['groupTypes', 'aggregationLabel']],})),diff --git a/products/feature_flags/frontend/ConditionSetSummary.test.tsx b/products/feature_flags/frontend/ConditionSetSummary.test.tsxnew file mode 100644index 000000000000..b2ee23444779--- /dev/null+++ b/products/feature_flags/frontend/ConditionSetSummary.test.tsx@@ -0,0 +1,48 @@+import '@testing-library/jest-dom'++import { cleanup, render } from '@testing-library/react'++import { FeatureFlagGroupType, PropertyFilterType, PropertyOperator } from '~/types'++import { ConditionSetSummary } from './ConditionSetSummary'++function group(rolloutPercentage: number | null, withProperties = false): FeatureFlagGroupType {+ return {+ properties: withProperties+ ? [+ {+ type: PropertyFilterType.Person,+ key: 'email',+ operator: PropertyOperator.IContains,+ value: 'example.com',+ },+ ]+ : [],+ rollout_percentage: rolloutPercentage,+ variant: null,+ sort_key: 'group-1',+ }+}++describe('ConditionSetSummary', () => {+ afterEach(() => {+ cleanup()+ })++ it.each<[number | null, string]>([+ [100, 'Condition set will match all users'],+ [null, 'Condition set will match all users'],+ [25, 'Condition set will match 25% of all users'],+ [0, 'Condition set will match no users'],+ ])('summarises a set without criteria at %s%% rollout', (rolloutPercentage, expected) => {+ render(<ConditionSetSummary group={group(rolloutPercentage)} aggregationTargetName="users" />)++ expect(document.body).toHaveTextContent(expected)+ })++ it('summarises a set with criteria', () => {+ render(<ConditionSetSummary group={group(25, true)} aggregationTargetName="users" />)++ expect(document.body).toHaveTextContent('Match users against all criteria')+ })+})diff --git a/products/feature_flags/frontend/ConditionSetSummary.tsx b/products/feature_flags/frontend/ConditionSetSummary.tsxnew file mode 100644index 000000000000..bbba229f4c25--- /dev/null+++ b/products/feature_flags/frontend/ConditionSetSummary.tsx@@ -0,0 +1,59 @@+import { FeatureFlagGroupType } from '~/types'++import { rolloutOf } from './releaseConditionsDiff'++export interface ConditionSetSummaryProps {+ group: FeatureFlagGroupType+ aggregationTargetName: string+ /** The editor phrases the criteria line as an edit in progress instead of a finished state. */+ readOnly?: boolean+}++/**+ * One line summary of who a condition set matches. For a set without criteria, the rollout+ * percentage decides the wording.+ */+export function ConditionSetSummary({+ group,+ aggregationTargetName,+ readOnly = true,+}: ConditionSetSummaryProps): JSX.Element {+ if (group.properties?.length) {+ return readOnly ? (+ <>+ Match <b>{aggregationTargetName}</b> against <b>all</b> criteria+ </>+ ) : (+ <>+ Matching <b>{aggregationTargetName}</b> against the criteria+ </>+ )+ }++ const rollout = rolloutOf(group)++ if (rollout === 100) {+ return (+ <>+ Condition set will match <b>all {aggregationTargetName}</b>+ </>+ )+ }++ if (rollout === 0) {+ return (+ <>+ Condition set will match <b>no {aggregationTargetName}</b>+ </>+ )+ }++ return (+ <>+ Condition set will match{' '}+ <b>+ <span className="tabular-nums">{rollout}%</span> of all {aggregationTargetName}+ </b>+ </>+ )+}diff --git a/products/feature_flags/frontend/FeatureFlagConditionSetCard.tsx b/products/feature_flags/frontend/FeatureFlagConditionSetCard.tsxindex ddd9ee7680b0..0fe9a8fa5449 100644--- a/products/feature_flags/frontend/FeatureFlagConditionSetCard.tsx+++ b/products/feature_flags/frontend/FeatureFlagConditionSetCard.tsx@@ -11,6 +11,7 @@ import { getFilterLabel } from '~/taxonomy/helpers'import { AnyPropertyFilter, FeatureFlagGroupType, PropertyFilterType } from '~/types'import { CohortConditionLink } from './CohortConditionLink'+import { ConditionSetSummary } from './ConditionSetSummary'import { rolloutOf } from './releaseConditionsDiff'export interface FeatureFlagConditionSetCardProps {@@ -116,26 +117,13 @@ export function FeatureFlagConditionSetCard({const rollout = rolloutOf(group)const rolloutChanged = previousRolloutPercentage !== undefined && previousRolloutPercentage !== rollout- const getSummary = (): JSX.Element => {- if (properties.length === 0) {- return (- <>- Condition set will match <b>all {aggregationTargetName}</b>- </>- )- }- return (- <>- Match <b>{aggregationTargetName}</b> against <b>all</b> criteria- </>- )- }-return (<div className="border rounded p-4 bg-surface-primary"><div className="flex items-center gap-2 flex-wrap"><LemonSnack>{label ?? `Set ${index + 1}`}</LemonSnack>- <span className="text-sm">{getSummary()}</span>+ <span className="text-sm">+ <ConditionSetSummary group={group} aggregationTargetName={aggregationTargetName} />+ </span>{tag}</div>