Skip to content

Commit

Permalink
feat(multi-project flags): add info banner when copying a flag with a…
Browse files Browse the repository at this point in the history
… static cohort (#18957)
  • Loading branch information
jurajmajerik authored Nov 29, 2023
1 parent 7295b73 commit 10e91e0
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion frontend/src/scenes/feature-flags/FeatureFlagProjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,33 @@ import { useEffect } from 'react'
import { teamLogic } from 'scenes/teamLogic'
import { userLogic } from 'scenes/userLogic'

import { cohortsModel } from '~/models/cohortsModel'
import { groupsModel } from '~/models/groupsModel'
import { OrganizationFeatureFlag } from '~/types'
import { FeatureFlagType, OrganizationFeatureFlag } from '~/types'

import { organizationLogic } from '../organizationLogic'
import { featureFlagLogic } from './featureFlagLogic'
import { groupFilters } from './FeatureFlags'

function checkHasStaticCohort(featureFlag: FeatureFlagType): boolean {
const { cohorts } = useValues(cohortsModel)
const staticCohorts = new Set()
cohorts.forEach((cohort) => {
if (cohort.is_static) {
staticCohorts.add(cohort.id)
}
})

for (const group of featureFlag.filters.groups) {
for (const prop of group.properties || []) {
if (prop.type === 'cohort' && staticCohorts.has(prop.value)) {
return true
}
}
}
return false
}

const getColumns = (): LemonTableColumns<OrganizationFeatureFlag> => {
const { currentTeamId } = useValues(teamLogic)
const { currentOrganization } = useValues(organizationLogic)
Expand Down Expand Up @@ -115,12 +135,20 @@ function FeatureFlagCopySection(): JSX.Element {
const { currentOrganization } = useValues(organizationLogic)
const { currentTeam } = useValues(teamLogic)

const hasStaticCohort = checkHasStaticCohort(featureFlag)
const hasMultipleProjects = (currentOrganization?.teams?.length ?? 0) > 1

return hasMultipleProjects && featureFlag.can_edit ? (
<>
<h3 className="l3">Feature flag copy</h3>
<div className="ant-row">Copy your flag and its configuration to another project.</div>
{hasStaticCohort && (
<LemonBanner type="info" className="mt-4">
The flag you are about to copy references a static cohort. If the cohort with identical name does
not exist in the target project, it will be copied as an empty cohort. This is because the
associated persons might not exist in the target project.
</LemonBanner>
)}
<div className="inline-flex gap-4 my-6">
<div>
<div className="font-semibold leading-6 h-6">Key</div>
Expand Down

0 comments on commit 10e91e0

Please sign in to comment.