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.

fix(flags): make recent feature flags selectable in match criteria (#67198)

Gustavo H. Strassburgere7a8990dff7e
diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicGroupsContext.test.tsx b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicGroupsContext.test.tsx
index 8cdb60411997..71d0d3b39def 100644
--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicGroupsContext.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicGroupsContext.test.tsx
@@ -101,4 +101,36 @@ describe('useTaxonomicGroupsContext', () => {
expect(types.has(TaxonomicFilterGroupType.HogQLExpression)).toBe(true)
expect(types.has(TaxonomicFilterGroupType.SuggestedFilters)).toBe(true)
})
+
+ it.each([
+ {
+ description: 'an active flag is selectable',
+ flag: { id: 1, key: 'my-flag', name: 'My flag', active: true },
+ expectedDisabled: false,
+ expectedName: 'my-flag',
+ },
+ {
+ description: 'an explicitly inactive flag is disabled',
+ flag: { id: 1, key: 'my-flag', name: 'My flag', active: false },
+ expectedDisabled: true,
+ expectedName: 'my-flag (disabled)',
+ },
+ {
+ // Recents/pinned entries are persisted stripped to { name, id }, so they carry no
+ // `active` field; a missing `active` must not read as disabled or recently-used
+ // flags can no longer be picked as flag-dependency match criteria in this (rebuild)
+ // group definition either. See the same guard in taxonomicFilterLogic.test.ts.
+ description: 'a recently-used flag missing the active field stays selectable',
+ flag: { name: '732889', id: 732889 },
+ expectedDisabled: false,
+ expectedName: '732889',
+ },
+ ])('Feature Flags group getIsDisabled/getName: $description', ({ flag, expectedDisabled, expectedName }) => {
+ const { result } = renderHook(() => useTaxonomicGroupsContext({}), { wrapper })
+ const groups = buildTaxonomicGroups(result.current)
+ const flagGroup = groups.find((g) => g.type === TaxonomicFilterGroupType.FeatureFlags)
+ expect(flagGroup?.getIsDisabled).toBeDefined() // oxlint-disable-line jest/no-restricted-matchers
+ expect(flagGroup?.getIsDisabled?.(flag as any)).toBe(expectedDisabled)
+ expect(flagGroup?.getName?.(flag as any)).toBe(expectedName)
+ })
})
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
index 68548d7acd8c..100b1710315d 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
@@ -1203,6 +1203,54 @@ describe('taxonomicFilterLogic', () => {
})
})
+ describe('Feature Flags group keeps recently-used flags selectable', () => {
+ let flagLogic: ReturnType<typeof taxonomicFilterLogic.build>
+
+ beforeEach(() => {
+ flagLogic = taxonomicFilterLogic({
+ taxonomicFilterLogicKey: 'featureFlagDependencyTest',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.FeatureFlags],
+ })
+ flagLogic.mount()
+ })
+
+ afterEach(() => {
+ flagLogic.unmount()
+ })
+
+ it.each([
+ {
+ description: 'an active flag is selectable',
+ flag: { id: 1, key: 'my-flag', name: 'My flag', active: true },
+ expectedDisabled: false,
+ expectedName: 'my-flag',
+ },
+ {
+ description: 'an explicitly inactive flag is disabled',
+ flag: { id: 1, key: 'my-flag', name: 'My flag', active: false },
+ expectedDisabled: true,
+ expectedName: 'my-flag (disabled)',
+ },
+ {
+ // Recents/pinned entries are persisted stripped to { name, id }, so they carry no
+ // `active` field; a missing `active` must not read as disabled or recently-used
+ // flags can no longer be picked as flag-dependency match criteria. The same guard
+ // applies to getName, which would otherwise render "732889 (disabled)".
+ description: 'a recently-used flag missing the active field stays selectable',
+ flag: { name: '732889', id: 732889 },
+ expectedDisabled: false,
+ expectedName: '732889',
+ },
+ ])('getIsDisabled/getName: $description', ({ flag, expectedDisabled, expectedName }) => {
+ const flagGroup = flagLogic.values.taxonomicGroups.find(
+ (g) => g.type === TaxonomicFilterGroupType.FeatureFlags
+ )
+ expect(flagGroup?.getIsDisabled).toBeDefined() // oxlint-disable-line jest/no-restricted-matchers
+ expect(flagGroup?.getIsDisabled?.(flag as any)).toBe(expectedDisabled)
+ expect(flagGroup?.getName?.(flag as any)).toBe(expectedName)
+ })
+ })
+
describe('SQL expression (HogQLExpression) group commits its value', () => {
let hogqlLogic: ReturnType<typeof taxonomicFilterLogic.build>
const onChange = jest.fn()
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
index 7a9700ab39ed..1cee43e111c0 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
@@ -1314,15 +1314,20 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
endpoint: combineUrl(`api/projects/${projectId}/feature_flags/`).url,
getName: (featureFlag: FeatureFlagType) => {
const name = featureFlag.key || featureFlag.name
- const isInactive = !featureFlag.active
+ const isInactive = featureFlag.active === false
return isInactive ? `${name} (disabled)` : name
},
getValue: (featureFlag: FeatureFlagType) => featureFlag.id || '',
getPopoverHeader: () => `Feature Flags`,
getIcon: (featureFlag: FeatureFlagType) => (
- <IconFlag className={clsx('size-4', !featureFlag.active && 'text-muted-alt opacity-50')} />
+ <IconFlag
+ className={clsx('size-4', featureFlag.active === false && 'text-muted-alt opacity-50')}
+ />
),
- getIsDisabled: (featureFlag: FeatureFlagType) => !featureFlag.active,
+ // Recently-used entries are stored stripped of `active`, so treat only an explicit
+ // `false` as disabled — otherwise recent flags are wrongly disabled and unselectable.
+ // Keep in sync with the Feature Flags group in utils/buildTaxonomicGroups.tsx.
+ getIsDisabled: (featureFlag: FeatureFlagType) => featureFlag.active === false,
localItemsSearch: (items, query) => {
if (!query) {
return items
diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx
index d28849eb4979..97f8852d3fa1 100644
--- a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx
@@ -836,15 +836,18 @@ export function buildTaxonomicGroups(ctx: BuildTaxonomicGroupsContext): Taxonomi
endpoint: combineUrl(`api/projects/${projectId}/feature_flags/`).url,
getName: (featureFlag: FeatureFlagType) => {
const name = featureFlag.key || featureFlag.name
- const isInactive = !featureFlag.active
+ const isInactive = featureFlag.active === false
return isInactive ? `${name} (disabled)` : name
},
getValue: (featureFlag: FeatureFlagType) => featureFlag.id || '',
getPopoverHeader: () => `Feature Flags`,
getIcon: (featureFlag: FeatureFlagType) => (
- <IconFlag className={clsx('size-4', !featureFlag.active && 'text-muted-alt opacity-50')} />
+ <IconFlag className={clsx('size-4', featureFlag.active === false && 'text-muted-alt opacity-50')} />
),
- getIsDisabled: (featureFlag: FeatureFlagType) => !featureFlag.active,
+ // Recently-used entries are stored stripped of `active`, so treat only an explicit
+ // `false` as disabled — otherwise recent flags are wrongly disabled and unselectable.
+ // Keep in sync with the Feature Flags group in taxonomicFilterLogic.tsx.
+ getIsDisabled: (featureFlag: FeatureFlagType) => featureFlag.active === false,
localItemsSearch: (items: TaxonomicDefinitionTypes[], query: string): TaxonomicDefinitionTypes[] => {
// Note: This function doesn't have direct access to the current value
// The actual filtering logic needs to be implemented in the infinite list logic