: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(feature-flags): link to bulk copy from the per-flag copy section (#124466)
ruby childs6bce72e696f0
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagProjects.test.tsx b/frontend/src/scenes/feature-flags/FeatureFlagProjects.test.tsxnew file mode 100644index 000000000000..e742888f3e26--- /dev/null+++ b/frontend/src/scenes/feature-flags/FeatureFlagProjects.test.tsx@@ -0,0 +1,78 @@+import { MOCK_DEFAULT_ORGANIZATION, MOCK_DEFAULT_TEAM } from 'lib/api.mock'++import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'++import { organizationLogic } from 'scenes/organizationLogic'+import { teamLogic } from 'scenes/teamLogic'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'+import { FeatureFlagType } from '~/types'++import { NEW_FLAG, featureFlagLogic } from './featureFlagLogic'+import FeatureFlagProjects from './FeatureFlagProjects'++const BULK_COPY_LINK_TEXT = 'bulk copy in the feature flags list'++const renderWithState = ({ teams, flag }: { teams: number; flag?: Partial<FeatureFlagType> }): void => {+ teamLogic.mount()+ teamLogic.actions.loadCurrentTeamSuccess(MOCK_DEFAULT_TEAM)+ organizationLogic.mount()+ organizationLogic.actions.loadCurrentOrganizationSuccess({+ ...MOCK_DEFAULT_ORGANIZATION,+ teams: Array.from({ length: teams }, (_, index) => ({+ ...MOCK_DEFAULT_TEAM,+ id: MOCK_DEFAULT_TEAM.id + index,+ project_id: MOCK_DEFAULT_TEAM.id + index,+ name: `Project ${index + 1}`,+ })),+ })+ featureFlagLogic.mount()+ featureFlagLogic.actions.loadFeatureFlagSuccess({+ ...NEW_FLAG,+ id: null,+ key: 'test-flag',+ ...flag,+ } as FeatureFlagType)++ render(<FeatureFlagProjects />)+}++describe('<FeatureFlagProjects />', () => {+ beforeEach(() => {+ useMocks({+ get: {+ '/api/organizations/:organization_id/feature_flags/:feature_flag_key': () => [200, []],+ },+ })+ initKeaTests()+ })++ afterEach(cleanup)++ it('links to bulk copy in the flags list when the copy section renders', () => {+ renderWithState({ teams: 2 })++ expect(screen.getByText('Feature flag copy')).toBeInTheDocument()+ const link = screen.getByText(BULK_COPY_LINK_TEXT).closest('a')+ expect(link).not.toBeNull()+ // Link prefixes the current project path, so assert on the target itself+ expect(link?.getAttribute('href')).toMatch(/\/feature-flags\?tab=projects$/)+ })++ it('does not render the bulk copy link in a single-project organization', () => {+ renderWithState({ teams: 1 })++ expect(screen.queryByText('Feature flag copy')).not.toBeInTheDocument()+ expect(screen.queryByText(BULK_COPY_LINK_TEXT)).not.toBeInTheDocument()+ })++ it('does not render the bulk copy link when the flag cannot be edited', () => {+ renderWithState({ teams: 2, flag: { can_edit: false } })++ expect(screen.queryByText('Feature flag copy')).not.toBeInTheDocument()+ expect(screen.queryByText(BULK_COPY_LINK_TEXT)).not.toBeInTheDocument()+ })+})diff --git a/frontend/src/scenes/feature-flags/FeatureFlagProjects.tsx b/frontend/src/scenes/feature-flags/FeatureFlagProjects.tsxindex 737a0bb2f86d..64285782af65 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagProjects.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagProjects.tsx@@ -1,7 +1,7 @@import { useActions, useValues } from 'kea'import { IconArrowRight } from '@posthog/icons'-import { LemonBanner, LemonButton, LemonCheckbox, LemonDialog, LemonSelect, LemonTag } from '@posthog/lemon-ui'+import { LemonBanner, LemonButton, LemonCheckbox, LemonDialog, LemonSelect, LemonTag, Link } from '@posthog/lemon-ui'import { OrganizationMembershipLevel } from 'lib/constants'import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'@@ -25,6 +25,7 @@ import {hasStaticCohortDependency,} from './featureFlagLogic'import { groupFilters } from './FeatureFlags'+import { FeatureFlagsTab } from './featureFlagsLogic'import { FlagActiveToggleTag } from './FlagActiveToggleTag'import { confirmFlagActiveToggleInProject, flagToggleKey } from './updateFlagActiveInProject'@@ -297,6 +298,13 @@ function FeatureFlagCopySection(): JSX.Element {</LemonButton></div></div>+ <div className="text-secondary mb-4">+ To copy multiple flags at once, use{' '}+ <Link to={urls.featureFlags(FeatureFlagsTab.PROJECTS)} data-attr="feature-flag-bulk-copy-link">+ bulk copy in the feature flags list+ </Link>+ .+ </div></>) : (<></>