From 1cd849291fc92bc087ade0750ce64780e6ff3b63 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Mon, 16 Nov 2026 22:28:05 +0100 Subject: [PATCH 01/11] feat(Flags): Show flag dependencies on the Value tab The Value tab warns when prerequisites serve the flag off, linking to its dependencies, and the Dependencies tab counts the prerequisites met. --- .../e2e/tests/flag-dependencies-test.pw.ts | 14 ++++++ .../modals/create-feature/index.tsx | 35 +++++++++++++- .../FeatureDependenciesTab/BlockedBanner.tsx | 10 +++- .../DependenciesTabLabel.tsx | 36 ++++++++++++++ .../__tests__/prerequisiteState.test.ts | 21 ++++++++ .../hooks/usePrerequisiteStatus.ts | 48 +++++++++++++++++++ .../tabs/FeatureDependenciesTab/index.ts | 2 + .../prerequisiteState.ts | 11 +++++ .../create-feature/tabs/FeatureValueTab.tsx | 21 ++++++++ 9 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx create mode 100644 frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/hooks/usePrerequisiteStatus.ts diff --git a/frontend/e2e/tests/flag-dependencies-test.pw.ts b/frontend/e2e/tests/flag-dependencies-test.pw.ts index e76c4d94ea31..74b14b7d5667 100644 --- a/frontend/e2e/tests/flag-dependencies-test.pw.ts +++ b/frontend/e2e/tests/flag-dependencies-test.pw.ts @@ -1,5 +1,6 @@ import { test, expect } from '../test-setup' import { + byId, createHelpers, log, LONG_TIMEOUT, @@ -68,6 +69,18 @@ test.describe('Flag Dependencies', () => { await expect(page.getByText(/Serving off in/)).toBeVisible() await visualSnapshot(page, 'dependencies-blocked', testInfo) + log('The tab counts the prerequisites met, and the Value tab says why') + const metCount = page.locator(byId('dependencies-met-count')) + await expect(metCount).toHaveText('0/1') + await page.getByRole('button', { exact: true, name: 'Value' }).click() + await expect(page.getByText(/Serving off in/)).toBeVisible() + await visualSnapshot(page, 'dependencies-blocked-value', testInfo) + await page + .getByRole('button', { exact: true, name: 'View dependencies' }) + .click() + await expect(page).toHaveURL(/tab=dependencies/) + await expect(row).toBeVisible() + log('Turning the prerequisite on satisfies it') await closeModal() await waitForModalToClose() @@ -76,6 +89,7 @@ test.describe('Flag Dependencies', () => { await expect(row.getByRole('img', { name: 'On' })).toBeVisible() await expect(row.getByText('Yes', { exact: true })).toBeVisible() await expect(page.getByText(/Serving off in/)).toBeHidden() + await expect(metCount).toHaveText('1/1') await visualSnapshot(page, 'dependencies-satisfied', testInfo) log('The prerequisite names its dependent and cannot take one of its own') diff --git a/frontend/web/components/modals/create-feature/index.tsx b/frontend/web/components/modals/create-feature/index.tsx index 1d45759ce455..401d5047f2a0 100644 --- a/frontend/web/components/modals/create-feature/index.tsx +++ b/frontend/web/components/modals/create-feature/index.tsx @@ -46,7 +46,10 @@ import SegmentOverridesTab, { SegmentOverrideValue, } from './tabs/SegmentOverridesTab' import UsageTab from './tabs/UsageTab' -import FeatureDependenciesTab from './tabs/FeatureDependenciesTab' +import FeatureDependenciesTab, { + DependenciesTabLabel, + usePrerequisiteStatus, +} from './tabs/FeatureDependenciesTab' import { useStagedPrerequisites } from './tabs/FeatureDependenciesTab/hooks/useStagedPrerequisites' import FeatureLimitAlert from './components/FeatureLimitAlert' import FeatureUpdateSummary from './components/FeatureUpdateSummary' @@ -461,6 +464,16 @@ const CreateFeatureModal: FC = (props) => { setSkipSaveProjectFeature(!createFeaturePermission) }, [createFeaturePermission]) + // Shown on the Value tab and the Dependencies tab's label, as + // prerequisites that are off serve the flag off. Dependencies don't apply + // to identity overrides, nor show for change requests. + const prerequisites = usePrerequisiteStatus({ + environmentId, + featureId: projectFlag.id, + projectId, + skip: !isEdit || !!identity || !!existingChangeRequest, + }) + if (!environment || !project) { return (
@@ -479,6 +492,19 @@ const CreateFeatureModal: FC = (props) => { const isVersionedChangeRequest = existingChangeRequest && isVersioned const hideIdentityOverridesTab = Utils.getShouldHideIdentityOverridesTab() const isDependenciesTabEnabled = !existingChangeRequest + // Shows the Dependencies tab, as `Tabs` does when it's clicked. + const showDependencies = + isDependenciesTabEnabled && props.history + ? () => { + const searchParams = new URLSearchParams(window.location.search) + searchParams.set('tab', 'dependencies') + props.history?.replace({ + pathname: window.location.pathname, + search: searchParams.toString(), + }) + setTabKey((k) => k + 1) + } + : undefined let regexValid = true try { @@ -816,6 +842,8 @@ const CreateFeatureModal: FC = (props) => { > = (props) => { {isDependenciesTabEnabled && ( + } isDirty={dependenciesChanged} > = ({ environmentName, rows }) => +const BlockedBanner: FC = ({ + action, + environmentName, + rows, +}) => isBlocked(rows) ? ( {describeOffCount(rows)} diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx new file mode 100644 index 000000000000..4e4d2160dccf --- /dev/null +++ b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx @@ -0,0 +1,36 @@ +import { FC } from 'react' +import cn from 'classnames' +import { PrerequisiteRow, countMet } from './prerequisiteState' + +type DependenciesTabLabelProps = { + // Undefined while loading, when there's nothing to count yet. + prerequisites?: PrerequisiteRow[] +} + +// Counts the prerequisites met, as the flag is served off while any isn't. +const DependenciesTabLabel: FC = ({ + prerequisites, +}) => { + const { met, total } = countMet(prerequisites ?? []) + return ( + <> + Dependencies + {!!total && ( + + {met}/{total} + + )} + + ) +} + +export default DependenciesTabLabel diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/__tests__/prerequisiteState.test.ts b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/__tests__/prerequisiteState.test.ts index 3cf2f26a09ce..4e633ec994d7 100644 --- a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/__tests__/prerequisiteState.test.ts +++ b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/__tests__/prerequisiteState.test.ts @@ -1,5 +1,6 @@ import { DependencyEdge, ProjectFlag } from 'common/types/responses' import { + countMet, describeOffCount, isBlocked, toPrerequisiteRow, @@ -108,6 +109,26 @@ describe('isBlocked', () => { }) }) +describe('countMet', () => { + it('counts the prerequisites met', () => { + expect(countMet([row(true, true), row(false, false)])).toEqual({ + met: 1, + total: 2, + }) + }) + + it('leaves out those that cannot be judged', () => { + expect(countMet([row(true, true), row(false, undefined)])).toEqual({ + met: 1, + total: 1, + }) + }) + + it('counts nothing with no prerequisites', () => { + expect(countMet([])).toEqual({ met: 0, total: 0 }) + }) +}) + describe('describeOffCount', () => { it('names a single prerequisite rather than counting it', () => { expect(describeOffCount([row(false, false)])).toBe( diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/hooks/usePrerequisiteStatus.ts b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/hooks/usePrerequisiteStatus.ts new file mode 100644 index 000000000000..1a7a5e5f4ae4 --- /dev/null +++ b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/hooks/usePrerequisiteStatus.ts @@ -0,0 +1,48 @@ +import { useMemo } from 'react' +import { useGetFeatureDependenciesQuery } from 'common/services/useFeatureDependency' +import { useFeatureStates } from 'common/hooks/useFeatureStates' +import { + PrerequisiteRow, + toPrerequisiteRows, +} from 'components/modals/create-feature/tabs/FeatureDependenciesTab/prerequisiteState' + +type UsePrerequisiteStatusArgs = { + environmentId: string + featureId: number + projectId: number + skip?: boolean +} + +/** + * Whether each of a flag's prerequisites is on, for showing outside the + * Dependencies tab. Shares its requests with useDependencies. + * + * Undefined until both the dependencies and the feature list are in, as every + * prerequisite reads as off without the latter. + */ +export const usePrerequisiteStatus = ({ + environmentId, + featureId, + projectId, + skip, +}: UsePrerequisiteStatusArgs): PrerequisiteRow[] | undefined => { + const { + data: dependencies, + isError, + isLoading, + } = useGetFeatureDependenciesQuery({ environmentId, featureId }, { skip }) + const featureStates = useFeatureStates({ environmentId, projectId, skip }) + const rows = useMemo( + () => + toPrerequisiteRows(dependencies?.results ?? [], featureStates.features), + [dependencies, featureStates.features], + ) + const isReady = + !skip && + !!dependencies && + !isLoading && + !isError && + !featureStates.isLoading && + !featureStates.isError + return isReady ? rows : undefined +} diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/index.ts b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/index.ts index f15752e6820f..db52e3ac7e02 100644 --- a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/index.ts +++ b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/index.ts @@ -1,5 +1,6 @@ export { default } from './FeatureDependenciesTab' export { default as BlockedBanner } from './BlockedBanner' +export { default as DependenciesTabLabel } from './DependenciesTabLabel' export { default as DependenciesPanel } from './DependenciesPanel' export { default as DependentFeatures } from './DependentFeatures' export { default as FeatureDependenciesSkeleton } from './FeatureDependenciesSkeleton' @@ -9,4 +10,5 @@ export { PrerequisitesEmptyState, } from './DependenciesEmptyStates' export { toPrerequisiteRow } from './prerequisiteState' +export { usePrerequisiteStatus } from './hooks/usePrerequisiteStatus' export type { PrerequisiteRow } from './prerequisiteState' diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/prerequisiteState.ts b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/prerequisiteState.ts index 4545aaf77d67..e5ba1c9217db 100644 --- a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/prerequisiteState.ts +++ b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/prerequisiteState.ts @@ -75,6 +75,17 @@ export const withStagedChanges = ( export const isBlocked = (rows: PrerequisiteRow[]): boolean => rows.some((row) => row.isMet === false) +// How many prerequisites are met, of those whose rule can be read. +export const countMet = ( + rows: PrerequisiteRow[], +): { met: number; total: number } => { + const judged = rows.filter((row) => row.isMet !== undefined) + return { + met: judged.filter((row) => row.isMet).length, + total: judged.length, + } +} + export const describeOffCount = (rows: PrerequisiteRow[]): string => { const total = rows.length const offCount = rows.filter((row) => !row.isEnabled).length diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureValueTab.tsx b/frontend/web/components/modals/create-feature/tabs/FeatureValueTab.tsx index 172cefada982..5774595466b3 100644 --- a/frontend/web/components/modals/create-feature/tabs/FeatureValueTab.tsx +++ b/frontend/web/components/modals/create-feature/tabs/FeatureValueTab.tsx @@ -33,6 +33,7 @@ import { import { FeatureExperimentFreeze } from 'common/hooks/useFeatureExperimentFreeze' import { useExperimentationEnabled } from 'common/hooks/useExperimentationEnabled' import ExperimentFreezeNotice from 'components/modals/create-feature/components/ExperimentFreezeNotice' +import { BlockedBanner, PrerequisiteRow } from './FeatureDependenciesTab' import { useHasPermission } from 'common/providers/Permission' import { ProjectPermission } from 'common/types/permissions.types' @@ -49,6 +50,11 @@ function isNegativeNumberString(str: any) { type FeatureValueTabProps = { error: any + // The flag's prerequisites in the environment, which serve it off while any + // is off. Undefined where they don't apply, e.g. to identity overrides. + prerequisites?: PrerequisiteRow[] + // Shows the flag's dependencies, where they can be changed. + onViewDependencies?: () => void projectId: number | string identity?: string noPermissions: boolean @@ -105,7 +111,9 @@ const FeatureValueTab: FC = ({ onRemoveMultivariateOption, onSaveFeatureValue, onSaveVariationValues, + onViewDependencies, originalMultivariateOptions, + prerequisites, preventFlagDefaults, projectFlag, projectId, @@ -367,6 +375,19 @@ const FeatureValueTab: FC = ({ return (
+ {prerequisites && environmentName && ( + + View dependencies + + ) + } + /> + )} {freeze?.isFrozen && freeze.experiment && environmentId && ( Date: Wed, 18 Nov 2026 12:13:42 +0100 Subject: [PATCH 02/11] test(Flags): Match only the open tab's banner in the dependencies E2E The Value tab's stays in the page behind the Dependencies tab. --- frontend/e2e/tests/flag-dependencies-test.pw.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/e2e/tests/flag-dependencies-test.pw.ts b/frontend/e2e/tests/flag-dependencies-test.pw.ts index 83f475e723aa..5073ef3fdc75 100644 --- a/frontend/e2e/tests/flag-dependencies-test.pw.ts +++ b/frontend/e2e/tests/flag-dependencies-test.pw.ts @@ -66,14 +66,19 @@ test.describe('Flag Dependencies', () => { log('The prerequisite is off, so the flag is held off') await expect(row.getByRole('img', { name: 'Off' })).toBeVisible() await expect(row.getByText('No', { exact: true })).toBeVisible() - await expect(page.getByText(/Serving off in/)).toBeVisible() + // The Value tab's banner stays in the page behind the open tab, and the + // role skips hidden elements, so this only matches the open tab's. + const servingOff = page + .getByRole('status') + .filter({ hasText: /Serving off in/ }) + await expect(servingOff).toBeVisible() await visualSnapshot(page, 'dependencies-blocked', testInfo) log('The tab counts the prerequisites met, and the Value tab says why') const metCount = page.locator(byId('dependencies-met-count')) await expect(metCount).toHaveText('0/1') await page.getByRole('button', { exact: true, name: 'Value' }).click() - await expect(page.getByText(/Serving off in/)).toBeVisible() + await expect(servingOff).toBeVisible() await visualSnapshot(page, 'dependencies-blocked-value', testInfo) await page .getByRole('button', { exact: true, name: 'View dependencies' }) @@ -88,7 +93,7 @@ test.describe('Flag Dependencies', () => { await openDependencies(DEPENDENT) await expect(row.getByRole('img', { name: 'On' })).toBeVisible() await expect(row.getByText('Yes', { exact: true })).toBeVisible() - await expect(page.getByText(/Serving off in/)).toBeHidden() + await expect(servingOff).toBeHidden() await expect(metCount).toHaveText('1/1') await visualSnapshot(page, 'dependencies-satisfied', testInfo) From e709f606a06d6b439a1feafb292162637287b573 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Wed, 18 Nov 2026 12:14:08 +0100 Subject: [PATCH 03/11] refactor(Flags): Count prerequisites met with the design system's chip --- .../FeatureDependenciesTab/DependenciesTabLabel.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx index 4e4d2160dccf..c135eb7d06b5 100644 --- a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx +++ b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx @@ -1,5 +1,5 @@ import { FC } from 'react' -import cn from 'classnames' +import Chip from 'components/base/Chip' import { PrerequisiteRow, countMet } from './prerequisiteState' type DependenciesTabLabelProps = { @@ -19,14 +19,11 @@ const DependenciesTabLabel: FC = ({ - {met}/{total} + + {met}/{total} + )} From f312f1211bf40bda41665a69a414aeb4cdef3214 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Wed, 18 Nov 2026 12:14:57 +0100 Subject: [PATCH 04/11] fix(Flags): Declare showing the Dependencies tab once #8792 added the same helper. --- .../web/components/modals/create-feature/index.tsx | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/frontend/web/components/modals/create-feature/index.tsx b/frontend/web/components/modals/create-feature/index.tsx index 8aba7d118d49..db2089ac75aa 100644 --- a/frontend/web/components/modals/create-feature/index.tsx +++ b/frontend/web/components/modals/create-feature/index.tsx @@ -506,20 +506,6 @@ const CreateFeatureModal: FC = (props) => { } : undefined - // Shows the Dependencies tab, as `Tabs` does when it's clicked. - const showDependencies = - isDependenciesTabEnabled && props.history - ? () => { - const searchParams = new URLSearchParams(window.location.search) - searchParams.set('tab', 'dependencies') - props.history?.replace({ - pathname: window.location.pathname, - search: searchParams.toString(), - }) - setTabKey((k) => k + 1) - } - : undefined - let regexValid = true try { if (!isEdit && projectFlag.name && regex) { From bd4c754524c69da2f9f903dffa39893bc8b81cae Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Wed, 18 Nov 2026 12:15:11 +0100 Subject: [PATCH 05/11] fix(Flags): Name the prerequisites met in the Dependencies tab's name Screen readers don't reliably announce labels on plain spans, so the count is read out in full as visually hidden text, which the E2E test also finds the tab by. --- .../e2e/tests/flag-dependencies-test.pw.ts | 12 +++++++---- .../DependenciesTabLabel.tsx | 20 ++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/frontend/e2e/tests/flag-dependencies-test.pw.ts b/frontend/e2e/tests/flag-dependencies-test.pw.ts index 5073ef3fdc75..1f50d151e12e 100644 --- a/frontend/e2e/tests/flag-dependencies-test.pw.ts +++ b/frontend/e2e/tests/flag-dependencies-test.pw.ts @@ -38,7 +38,8 @@ test.describe('Flag Dependencies', () => { const openDependencies = async (feature: string) => { await gotoFeature(feature) - await page.getByRole('button', { name: 'Dependencies' }).click() + // The tab's name goes on to count the prerequisites met. + await page.getByRole('button', { name: /^Dependencies/ }).click() } log('The dependent has no prerequisites yet') @@ -75,8 +76,9 @@ test.describe('Flag Dependencies', () => { await visualSnapshot(page, 'dependencies-blocked', testInfo) log('The tab counts the prerequisites met, and the Value tab says why') - const metCount = page.locator(byId('dependencies-met-count')) - await expect(metCount).toHaveText('0/1') + await expect( + page.getByRole('button', { name: /0 of 1 prerequisites met/ }), + ).toBeVisible() await page.getByRole('button', { exact: true, name: 'Value' }).click() await expect(servingOff).toBeVisible() await visualSnapshot(page, 'dependencies-blocked-value', testInfo) @@ -94,7 +96,9 @@ test.describe('Flag Dependencies', () => { await expect(row.getByRole('img', { name: 'On' })).toBeVisible() await expect(row.getByText('Yes', { exact: true })).toBeVisible() await expect(servingOff).toBeHidden() - await expect(metCount).toHaveText('1/1') + await expect( + page.getByRole('button', { name: /1 of 1 prerequisites met/ }), + ).toBeVisible() await visualSnapshot(page, 'dependencies-satisfied', testInfo) log('The dependency manages its segment override') diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx index c135eb7d06b5..a861c3c450d5 100644 --- a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx +++ b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx @@ -16,15 +16,17 @@ const DependenciesTabLabel: FC = ({ <> Dependencies {!!total && ( - - - {met}/{total} - - + <> + {/* Read out in full instead, as part of the tab's name. */} + + + {met}/{total} + + + + {met} of {total} prerequisites met + + )} ) From 5ced13719c4385e8cf7100a198c168313b514f2f Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Wed, 18 Nov 2026 12:16:07 +0100 Subject: [PATCH 06/11] fix(Flags): Read flag states for the current environment only RTK Query keeps the previous arguments' data while new ones load, so a changed environment or flag could briefly show the previous one's prerequisites. --- .../hooks/__tests__/useFeatureStates.test.ts | 65 +++++++++++++++++++ frontend/common/hooks/useFeatureStates.ts | 14 ++-- .../hooks/usePrerequisiteStatus.ts | 4 +- 3 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 frontend/common/hooks/__tests__/useFeatureStates.test.ts diff --git a/frontend/common/hooks/__tests__/useFeatureStates.test.ts b/frontend/common/hooks/__tests__/useFeatureStates.test.ts new file mode 100644 index 000000000000..c738d83939a7 --- /dev/null +++ b/frontend/common/hooks/__tests__/useFeatureStates.test.ts @@ -0,0 +1,65 @@ +jest.mock('common/services/useProjectFlag', () => ({ + useGetFeatureListQuery: jest.fn(), +})) + +jest.mock('common/hooks/useProjectEnvironments', () => ({ + useProjectEnvironments: jest.fn(), +})) + +import { useFeatureStates } from 'common/hooks/useFeatureStates' +import { useGetFeatureListQuery } from 'common/services/useProjectFlag' +import { useProjectEnvironments } from 'common/hooks/useProjectEnvironments' +import { ProjectFlag } from 'common/types/responses' + +const mockUseGetFeatureListQuery = + useGetFeatureListQuery as jest.MockedFunction +const mockUseProjectEnvironments = + useProjectEnvironments as jest.MockedFunction + +const enabledFeature = { + environment_feature_state: { enabled: true }, + id: 1, +} as unknown as ProjectFlag + +describe('useFeatureStates', () => { + beforeEach(() => { + mockUseProjectEnvironments.mockReturnValue({ + error: undefined, + getEnvironmentIdFromKey: () => 2, + isLoading: false, + } as any) + }) + + it("ignores another environment's list while this one's loads", () => { + // Given + mockUseGetFeatureListQuery.mockReturnValue({ + currentData: undefined, + data: { results: [enabledFeature] }, + isError: false, + isLoading: false, + } as any) + + // When + const states = useFeatureStates({ environmentId: 'key', projectId: 1 }) + + // Then + expect(states.isLoading).toBe(true) + expect(states.features).toEqual([]) + }) + + it("reads this environment's list once loaded", () => { + // Given + mockUseGetFeatureListQuery.mockReturnValue({ + currentData: { results: [enabledFeature] }, + isError: false, + isLoading: false, + } as any) + + // When + const states = useFeatureStates({ environmentId: 'key', projectId: 1 }) + + // Then + expect(states.isLoading).toBe(false) + expect(states.isEnabled(1)).toBe(true) + }) +}) diff --git a/frontend/common/hooks/useFeatureStates.ts b/frontend/common/hooks/useFeatureStates.ts index 5d1a6a593775..c80223eb7663 100644 --- a/frontend/common/hooks/useFeatureStates.ts +++ b/frontend/common/hooks/useFeatureStates.ts @@ -25,8 +25,11 @@ export const useFeatureStates = ({ isLoading: isLoadingEnvironments, } = useProjectEnvironments(projectId) const numericEnvId = getEnvironmentIdFromKey(environmentId) + const shouldSkip = skip || !numericEnvId + // currentData, not data, which keeps another environment's list while this + // one's loads. const { - data, + currentData, isError: isFeatureListError, isLoading: isLoadingFeatureList, } = useGetFeatureListQuery( @@ -37,10 +40,10 @@ export const useFeatureStates = ({ page_size: 999, projectId, }, - { skip: skip || !numericEnvId }, + { skip: shouldSkip }, ) - const features = data?.results ?? NO_FEATURES + const features = currentData?.results ?? NO_FEATURES return { features, isEnabled: (featureId: number) => @@ -52,6 +55,9 @@ export const useFeatureStates = ({ // The lookup finished without finding the environment, so the feature // list will never run and nothing is coming. (!isLoadingEnvironments && !numericEnvId), - isLoading: isLoadingEnvironments || isLoadingFeatureList, + isLoading: + isLoadingEnvironments || + isLoadingFeatureList || + (!shouldSkip && !currentData && !isFeatureListError), } } diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/hooks/usePrerequisiteStatus.ts b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/hooks/usePrerequisiteStatus.ts index 1a7a5e5f4ae4..a6abe2038221 100644 --- a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/hooks/usePrerequisiteStatus.ts +++ b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/hooks/usePrerequisiteStatus.ts @@ -26,8 +26,10 @@ export const usePrerequisiteStatus = ({ projectId, skip, }: UsePrerequisiteStatusArgs): PrerequisiteRow[] | undefined => { + // currentData, not data, which keeps another flag's or environment's + // dependencies while these load. const { - data: dependencies, + currentData: dependencies, isError, isLoading, } = useGetFeatureDependenciesQuery({ environmentId, featureId }, { skip }) From 8d74c070f3e02a1886e928bed54708a2a2bfdd4b Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Wed, 18 Nov 2026 13:13:35 +0100 Subject: [PATCH 07/11] fix(Flags): Read flag states from every page of the feature list Only the first 999 flags were loaded, so a prerequisite beyond them read as off, holding its dependent off in the Value and Dependencies tabs. --- .../hooks/__tests__/useFeatureStates.test.ts | 30 +++++++++++++++---- frontend/common/hooks/useFeatureStates.ts | 17 ++++------- frontend/common/services/useProjectFlag.ts | 6 ++++ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/frontend/common/hooks/__tests__/useFeatureStates.test.ts b/frontend/common/hooks/__tests__/useFeatureStates.test.ts index c738d83939a7..60eb95e43484 100644 --- a/frontend/common/hooks/__tests__/useFeatureStates.test.ts +++ b/frontend/common/hooks/__tests__/useFeatureStates.test.ts @@ -1,5 +1,5 @@ jest.mock('common/services/useProjectFlag', () => ({ - useGetFeatureListQuery: jest.fn(), + useGetProjectFlagsQuery: jest.fn(), })) jest.mock('common/hooks/useProjectEnvironments', () => ({ @@ -7,12 +7,12 @@ jest.mock('common/hooks/useProjectEnvironments', () => ({ })) import { useFeatureStates } from 'common/hooks/useFeatureStates' -import { useGetFeatureListQuery } from 'common/services/useProjectFlag' +import { useGetProjectFlagsQuery } from 'common/services/useProjectFlag' import { useProjectEnvironments } from 'common/hooks/useProjectEnvironments' import { ProjectFlag } from 'common/types/responses' -const mockUseGetFeatureListQuery = - useGetFeatureListQuery as jest.MockedFunction +const mockUseGetProjectFlagsQuery = + useGetProjectFlagsQuery as jest.MockedFunction const mockUseProjectEnvironments = useProjectEnvironments as jest.MockedFunction @@ -32,7 +32,7 @@ describe('useFeatureStates', () => { it("ignores another environment's list while this one's loads", () => { // Given - mockUseGetFeatureListQuery.mockReturnValue({ + mockUseGetProjectFlagsQuery.mockReturnValue({ currentData: undefined, data: { results: [enabledFeature] }, isError: false, @@ -47,9 +47,27 @@ describe('useFeatureStates', () => { expect(states.features).toEqual([]) }) + it('reads every page of the feature list for the environment', () => { + // Given + mockUseGetProjectFlagsQuery.mockReturnValue({ + currentData: { results: [] }, + isError: false, + isLoading: false, + } as any) + + // When + useFeatureStates({ environmentId: 'key', projectId: 1 }) + + // Then + expect(mockUseGetProjectFlagsQuery).toHaveBeenCalledWith( + { environment: 2, project: '1' }, + { skip: false }, + ) + }) + it("reads this environment's list once loaded", () => { // Given - mockUseGetFeatureListQuery.mockReturnValue({ + mockUseGetProjectFlagsQuery.mockReturnValue({ currentData: { results: [enabledFeature] }, isError: false, isLoading: false, diff --git a/frontend/common/hooks/useFeatureStates.ts b/frontend/common/hooks/useFeatureStates.ts index c80223eb7663..d7ce97378827 100644 --- a/frontend/common/hooks/useFeatureStates.ts +++ b/frontend/common/hooks/useFeatureStates.ts @@ -1,4 +1,4 @@ -import { useGetFeatureListQuery } from 'common/services/useProjectFlag' +import { useGetProjectFlagsQuery } from 'common/services/useProjectFlag' import { useProjectEnvironments } from './useProjectEnvironments' import { ProjectFlag } from 'common/types/responses' @@ -12,8 +12,9 @@ type UseFeatureStatesArgs = { skip?: boolean } -// Whether each of a project's features is on in one environment, from the -// feature list. getFeatureList takes the numeric environment id, not the key. +// Whether each of a project's features is on in one environment, from every +// page of the feature list, as a feature missing from it reads as off. +// getProjectFlags takes the numeric environment id, not the key. export const useFeatureStates = ({ environmentId, projectId, @@ -32,14 +33,8 @@ export const useFeatureStates = ({ currentData, isError: isFeatureListError, isLoading: isLoadingFeatureList, - } = useGetFeatureListQuery( - { - environmentId: String(numericEnvId ?? ''), - page: 1, - // One page has to cover every feature, or one outside it reads as off. - page_size: 999, - projectId, - }, + } = useGetProjectFlagsQuery( + { environment: numericEnvId, project: String(projectId) }, { skip: shouldSkip }, ) diff --git a/frontend/common/services/useProjectFlag.ts b/frontend/common/services/useProjectFlag.ts index b1b7e41ef959..a934236bc570 100644 --- a/frontend/common/services/useProjectFlag.ts +++ b/frontend/common/services/useProjectFlag.ts @@ -149,6 +149,12 @@ export const projectFlagService = service .join('-'), type: 'ProjectFlag', }, + // Refreshed with the feature list, as it carries the same states. + { + id: `${req?.project}-${req?.environment}`, + type: 'FeatureList', + }, + { id: 'LIST', type: 'FeatureList' }, ], queryFn: async (args, _, _2, baseQuery) => { return await recursivePageGet( From 8ecf60a774946b305a6c3ba34e38cf300b0f8667 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Wed, 18 Nov 2026 15:06:54 +0100 Subject: [PATCH 08/11] fix(Flags): Clear save errors when following links to the Dependencies tab As clicking a tab does, since an error belongs to the tab it occurred on. --- .../modals/create-feature/index.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/frontend/web/components/modals/create-feature/index.tsx b/frontend/web/components/modals/create-feature/index.tsx index db2089ac75aa..8950d0bdd27f 100644 --- a/frontend/web/components/modals/create-feature/index.tsx +++ b/frontend/web/components/modals/create-feature/index.tsx @@ -492,6 +492,16 @@ const CreateFeatureModal: FC = (props) => { const isVersionedChangeRequest = existingChangeRequest && isVersioned const hideIdentityOverridesTab = Utils.getShouldHideIdentityOverridesTab() const isDependenciesTabEnabled = !existingChangeRequest + const onTabChange = () => { + setTabKey((k) => k + 1) + // A save error belongs to the tab it occurred on — the + // other tabs cannot render its shape meaningfully. + if (FeatureListStore.error) { + FeatureListStore.error = null + FeatureListStore.trigger('change') + } + } + // Shows the Dependencies tab, as `Tabs` does when it's clicked. const showDependencies = isDependenciesTabEnabled && props.history @@ -502,7 +512,7 @@ const CreateFeatureModal: FC = (props) => { pathname: window.location.pathname, search: searchParams.toString(), }) - setTabKey((k) => k + 1) + onTabChange() } : undefined @@ -824,15 +834,7 @@ const CreateFeatureModal: FC = (props) => { { - setTabKey((k) => k + 1) - // A save error belongs to the tab it occurred on — the - // other tabs cannot render its shape meaningfully. - if (FeatureListStore.error) { - FeatureListStore.error = null - FeatureListStore.trigger('change') - } - }} + onChange={onTabChange} overflowX > Date: Wed, 18 Nov 2026 15:16:24 +0100 Subject: [PATCH 09/11] test(Flags): Cover following every page of a list The hook's test only checks what it requests, as the query is mocked. --- .../hooks/__tests__/useFeatureStates.test.ts | 2 +- .../utils/__tests__/recursivePageGet.test.ts | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 frontend/common/utils/__tests__/recursivePageGet.test.ts diff --git a/frontend/common/hooks/__tests__/useFeatureStates.test.ts b/frontend/common/hooks/__tests__/useFeatureStates.test.ts index 60eb95e43484..5667e4aa1379 100644 --- a/frontend/common/hooks/__tests__/useFeatureStates.test.ts +++ b/frontend/common/hooks/__tests__/useFeatureStates.test.ts @@ -47,7 +47,7 @@ describe('useFeatureStates', () => { expect(states.features).toEqual([]) }) - it('reads every page of the feature list for the environment', () => { + it('requests project flags for the resolved environment', () => { // Given mockUseGetProjectFlagsQuery.mockReturnValue({ currentData: { results: [] }, diff --git a/frontend/common/utils/__tests__/recursivePageGet.test.ts b/frontend/common/utils/__tests__/recursivePageGet.test.ts new file mode 100644 index 000000000000..b669532e5008 --- /dev/null +++ b/frontend/common/utils/__tests__/recursivePageGet.test.ts @@ -0,0 +1,47 @@ +import { recursivePageGet } from 'common/utils/recursivePageGet' + +describe('recursivePageGet', () => { + it('follows next links, concatenating the pages', async () => { + // Given + const baseQuery = jest + .fn() + .mockResolvedValueOnce({ + data: { + count: 3, + next: 'items/?page=2', + previous: null, + results: [1, 2], + }, + }) + .mockResolvedValueOnce({ + data: { count: 3, next: null, previous: 'items/?page=1', results: [3] }, + }) + + // When + const res = await recursivePageGet('items/?page=1', null, baseQuery) + + // Then + expect(baseQuery.mock.calls.map(([arg]) => arg)).toEqual([ + { method: 'GET', url: 'items/?page=1' }, + { method: 'GET', url: 'items/?page=2' }, + ]) + expect(res.data?.results).toEqual([1, 2, 3]) + }) + + it('returns the error of a failing page', async () => { + // Given + const error = { status: 500 } + const baseQuery = jest + .fn() + .mockResolvedValueOnce({ + data: { count: 3, next: 'items/?page=2', previous: null, results: [1] }, + }) + .mockResolvedValueOnce({ error }) + + // When + const res = await recursivePageGet('items/?page=1', null, baseQuery) + + // Then + expect(res.error).toBe(error) + }) +}) From 3f4b8f19105c7f5823c6e989f3a0db7154d7b664 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Wed, 18 Nov 2026 15:23:54 +0100 Subject: [PATCH 10/11] test(Flags): Assert a failed page returns only its error --- frontend/common/utils/__tests__/recursivePageGet.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/common/utils/__tests__/recursivePageGet.test.ts b/frontend/common/utils/__tests__/recursivePageGet.test.ts index b669532e5008..ec49f6371e45 100644 --- a/frontend/common/utils/__tests__/recursivePageGet.test.ts +++ b/frontend/common/utils/__tests__/recursivePageGet.test.ts @@ -42,6 +42,6 @@ describe('recursivePageGet', () => { const res = await recursivePageGet('items/?page=1', null, baseQuery) // Then - expect(res.error).toBe(error) + expect(res).toEqual({ error }) }) }) From aad90cec65d343357b416ec0c04f8ca282c08ec9 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Wed, 18 Nov 2026 15:27:03 +0100 Subject: [PATCH 11/11] fix(Flags): Stop the prerequisites chip taking the tab's height The chip inherited the tab's line height, 42px, which stretched it. --- .../tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx index a861c3c450d5..9408daf446ad 100644 --- a/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx +++ b/frontend/web/components/modals/create-feature/tabs/FeatureDependenciesTab/DependenciesTabLabel.tsx @@ -17,8 +17,9 @@ const DependenciesTabLabel: FC = ({ Dependencies {!!total && ( <> - {/* Read out in full instead, as part of the tab's name. */} - + {/* Read out in full instead, as part of the tab's name. The body's + line height stops the chip taking the tab's, which is its height. */} + {met}/{total}