Skip to content

Commit

Permalink
refine the separate feature checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianca Yang committed Dec 21, 2023
1 parent ef5b761 commit 6995712
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions frontend/src/scenes/settings/SettingsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export const SettingsMap: SettingSection[] = [
id: 'replay-ingestion',
title: 'Ingestion controls',
component: <ReplayCostControl />,
flag: 'SESSION_RECORDING_SAMPLING',
features: [
AvailableFeature.SESSION_REPLAY_SAMPLING,
AvailableFeature.RECORDING_DURATION_MINIMUM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FlagSelector } from 'lib/components/FlagSelector'
import { FEATURE_FLAGS, SESSION_REPLAY_MINIMUM_DURATION_OPTIONS } from 'lib/constants'
import { IconCancel } from 'lib/lemon-ui/icons'
import { LemonLabel } from 'lib/lemon-ui/LemonLabel/LemonLabel'
import { featureFlagLogic } from 'scenes/feature-flags/featureFlagLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
Expand Down Expand Up @@ -181,12 +181,12 @@ export function ReplayCostControl(): JSX.Element {
const { updateCurrentTeam } = useActions(teamLogic)
const { currentTeam } = useValues(teamLogic)
const { hasAvailableFeature } = useValues(userLogic)
const { featureFlag } = useValues(featureFlagLogic)
const { featureFlags } = useValues(featureFlagLogic)
const samplingControlFeatureEnabled = hasAvailableFeature(AvailableFeature.SESSION_REPLAY_SAMPLING)
const recordingDurationMinimumFeatureEnabled = hasAvailableFeature(AvailableFeature.RECORDING_DURATION_MINIMUM)
const featureFlagRecordingFeatureEnabled = hasAvailableFeature(AvailableFeature.FEATURE_FLAG_BASED_RECORDING)
const costControlFeaturesEnabled =
featureFlag[FEATURE_FLAGS.SESSION_RECORDING_SAMPLING] ||
featureFlags[FEATURE_FLAGS.SESSION_RECORDING_SAMPLING] ||
samplingControlFeatureEnabled ||
recordingDurationMinimumFeatureEnabled ||
featureFlagRecordingFeatureEnabled
Expand All @@ -206,7 +206,7 @@ export function ReplayCostControl(): JSX.Element {
<LemonBanner className="mb-4" type={'info'}>
Requires posthog-js version 1.88.2 or greater
</LemonBanner>
{(featureFlag[FEATURE_FLAGS.SESSION_RECORDING_SAMPLING] || samplingControlFeatureEnabled) && (
{(featureFlags[FEATURE_FLAGS.SESSION_RECORDING_SAMPLING] || samplingControlFeatureEnabled) && (
<>
<div className={'flex flex-row justify-between'}>
<LemonLabel className="text-base">Sampling</LemonLabel>
Expand Down Expand Up @@ -315,7 +315,7 @@ export function ReplayCostControl(): JSX.Element {
</p>
</>
)}
{(featureFlag[FEATURE_FLAGS.SESSION_RECORDING_SAMPLING] || recordingDurationMinimumFeatureEnabled) && (
{(featureFlags[FEATURE_FLAGS.SESSION_RECORDING_SAMPLING] || recordingDurationMinimumFeatureEnabled) && (
<>
<div className={'flex flex-row justify-between'}>
<LemonLabel className="text-base">Minimum session duration (seconds)</LemonLabel>
Expand All @@ -334,7 +334,7 @@ export function ReplayCostControl(): JSX.Element {
</p>
</>
)}
{(featureFlag[FEATURE_FLAGS.SESSION_RECORDING_SAMPLING] || featureFlagRecordingFeatureEnabled) && (
{(featureFlags[FEATURE_FLAGS.SESSION_RECORDING_SAMPLING] || featureFlagRecordingFeatureEnabled) && (
<>
<div className={'flex flex-col space-y-2'}>
<LemonLabel className="text-base">Enable recordings using feature flag</LemonLabel>
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/scenes/settings/settingsLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,19 @@ export const settingsLogic = kea<settingsLogicType>([
settings = sections.find((x) => x.id === selectedSectionId)?.settings || []
}

return settings
.filter((x) => (x.flag ? featureFlags[FEATURE_FLAGS[x.flag]] : true))
.filter((x) => (x.features ? x.features.some((feat) => hasAvailableFeature(feat)) : true))
return settings.filter((x) => {
if (x.flag && x.features) {
return (
x.features.some((feat) => hasAvailableFeature(feat)) || featureFlags[FEATURE_FLAGS[x.flag]]
)
} else if (x.features) {
return x.features.some((feat) => hasAvailableFeature(feat))
} else if (x.flag) {
return featureFlags[FEATURE_FLAGS[x.flag]]
}

return true
})
},
],
}),
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export enum AvailableFeature {
SURVEYS_TEXT_HTML = 'surveys_text_html',
SURVEYS_MULTIPLE_QUESTIONS = 'surveys_multiple_questions',
SESSION_REPLAY_SAMPLING = 'session_replay_sampling',
RECORDING_DURATION_MINIMUM = 'recording_duration_minimum',
FEATURE_FLAG_BASED_RECORDING = 'feature_flag_based_recording',
RECORDING_DURATION_MINIMUM = 'replay_recording_duration_minimum',
FEATURE_FLAG_BASED_RECORDING = 'replay_feature_flag_based_recording',
}

export enum ProductKey {
Expand Down

0 comments on commit 6995712

Please sign in to comment.