Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: separate PropertyValue component for feature flags #28125

Merged
merged 6 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 <></>
}
Comment on lines +56 to +58
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only logic changes on the PR, otherwise I just moved the lines into a new function for easier readability

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
Loading