Skip to content

Commit

Permalink
fix: separate PropertyValue component for feature flags (PostHog#28125)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
lucasheriques and github-actions[bot] authored Feb 1, 2025
1 parent eb8e1a9 commit 3969faa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 41 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 55 additions & 41 deletions frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,67 @@ import { urls } from 'scenes/urls'

import { cohortsModel } from '~/models/cohortsModel'
import { groupsModel } from '~/models/groupsModel'
import { AnyPropertyFilter, FeatureFlagGroupType } from '~/types'
import { AnyPropertyFilter, FeatureFlagGroupType, PropertyOperator } from '~/types'

import { featureFlagLogic } from './featureFlagLogic'
import {
featureFlagReleaseConditionsLogic,
FeatureFlagReleaseConditionsLogicProps,
} from './FeatureFlagReleaseConditionsLogic'

function PropertyValueComponent({
property,
cohortsById,
}: {
property: AnyPropertyFilter
cohortsById: Record<string, any>
}): JSX.Element {
if (property.type === 'cohort') {
return (
<LemonButton
type="secondary"
size="xsmall"
to={urls.cohort(property.value)}
sideIcon={<IconOpenInNew />}
targetBlank
>
{(property.value && cohortsById[property.value]?.name) || `ID ${property.value}`}
</LemonButton>
)
}

if (property.value === PropertyOperator.IsNotSet || property.value === PropertyOperator.IsSet) {
return <></>
}
const propertyValues = Array.isArray(property.value) ? property.value : [property.value]

return (
<>
{propertyValues.map((val, idx) => (
<LemonSnack key={idx}>
{val}
<span>
{isPropertyFilterWithOperator(property) &&
['is_date_before', 'is_date_after'].includes(property.operator) &&
dateStringToComponents(String(val)) // check it's a relative date
? ` ( ${dateFilterToText(
String(val),
undefined,
'',
[],
false,
String(val).slice(-1) === 'h' ? 'MMMM D, YYYY HH:mm:ss' : 'MMMM D, YYYY',
true
)}{' '}
)`
: ''}
</span>
</LemonSnack>
))}
</>
)
}

export function FeatureFlagReleaseConditions({
id,
readOnly,
Expand Down Expand Up @@ -187,46 +240,7 @@ export function FeatureFlagReleaseConditions({
<span>{allOperatorsToHumanName(property.operator)} </span>
) : null}

{property.type === 'cohort' ? (
<LemonButton
type="secondary"
size="xsmall"
to={urls.cohort(property.value)}
sideIcon={<IconOpenInNew />}
targetBlank
>
{(property.value && cohortsById[property.value]?.name) ||
`ID ${property.value}`}
</LemonButton>
) : (
[...(Array.isArray(property.value) ? property.value : [property.value])].map(
(val, idx) => (
<LemonSnack key={idx}>
{val}
<span>
{isPropertyFilterWithOperator(property) &&
['is_date_before', 'is_date_after'].includes(
property.operator
) &&
dateStringToComponents(String(val)) // check it's a relative date
? ` ( ${dateFilterToText(
String(val),
undefined,
'',
[],
false,
String(val).slice(-1) === 'h'
? 'MMMM D, YYYY HH:mm:ss'
: 'MMMM D, YYYY',
true
)}{' '}
)`
: ''}
</span>
</LemonSnack>
)
)
)}
<PropertyValueComponent property={property} cohortsById={cohortsById} />
</div>
))}
</>
Expand Down

0 comments on commit 3969faa

Please sign in to comment.