Skip to content

Commit

Permalink
feat(flags): add flag persistence as a default setting across the org (
Browse files Browse the repository at this point in the history
…#27527)

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
dmarticus and github-actions[bot] authored Jan 16, 2025
1 parent 7da80e0 commit 4ba47b8
Show file tree
Hide file tree
Showing 64 changed files with 405 additions and 4 deletions.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/src/lib/api.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const MOCK_DEFAULT_TEAM: TeamType = {
live_events_token: '123',
capture_dead_clicks: false,
human_friendly_comparison_periods: false,
flags_persistence_default: false,
}

export const MOCK_DEFAULT_PROJECT: ProjectType = {
Expand Down
55 changes: 55 additions & 0 deletions frontend/src/scenes/feature-flags/FeatureFlagSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { LemonDialog, LemonSwitch, Link } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { teamLogic } from 'scenes/teamLogic'

export type FeatureFlagSettingsProps = {
inModal?: boolean
}

export function FeatureFlagSettings({ inModal = false }: FeatureFlagSettingsProps): JSX.Element {
const { updateCurrentTeam } = useActions(teamLogic)
const { currentTeam } = useValues(teamLogic)

return (
<div className="space-y-4">
<div className="space-y-2">
<LemonSwitch
data-attr="default-flag-persistence-switch"
onChange={(checked) => {
updateCurrentTeam({
flags_persistence_default: checked,
})
}}
label="Enable flag persistence by default"
bordered={!inModal}
fullWidth={inModal}
labelClassName={inModal ? 'text-base font-semibold' : ''}
checked={!!currentTeam?.flags_persistence_default}
/>

<p>
When enabled, all new feature flags will have persistence enabled by default. This ensures
consistent user experiences across authentication steps. Learn more in our{' '}
<Link
to="https://posthog.com/docs/feature-flags/creating-feature-flags#persisting-feature-flags-across-authentication-steps"
target="_blank"
>
documentation
</Link>
.
</p>
</div>
</div>
)
}

export function openFeatureFlagSettingsDialog(): void {
LemonDialog.open({
title: 'Feature flag settings',
content: <FeatureFlagSettings inModal />,
width: 600,
primaryButton: {
children: 'Done',
},
})
}
12 changes: 9 additions & 3 deletions frontend/src/scenes/feature-flags/featureFlagLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
connect((props: FeatureFlagLogicProps) => ({
values: [
teamLogic,
['currentTeamId'],
['currentTeam', 'currentTeamId'],
projectLogic,
['currentProjectId'],
groupsModel,
Expand Down Expand Up @@ -291,7 +291,10 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
}),
forms(({ actions, values }) => ({
featureFlag: {
defaults: { ...NEW_FLAG },
defaults: {
...NEW_FLAG,
ensure_experience_continuity: values.currentTeam?.flags_persistence_default || false,
},
errors: ({ key, filters }) => {
return {
key: validateFeatureFlagKey(key),
Expand Down Expand Up @@ -538,7 +541,10 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
throw e
}
}
return NEW_FLAG
return {
...NEW_FLAG,
ensure_experience_continuity: values.currentTeam?.flags_persistence_default ?? false,
}
},
saveFeatureFlag: async (updatedFlag: Partial<FeatureFlagType>) => {
const { created_at, id, ...flag } = updatedFlag
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/scenes/settings/SettingsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { CorrelationConfig } from './environment/CorrelationConfig'
import { DataAttributes } from './environment/DataAttributes'
import { DataColorThemes } from './environment/DataColorThemes'
import { FeatureFlagSettings } from './environment/FeatureFlagSettings'
import { GroupAnalyticsConfig } from './environment/GroupAnalyticsConfig'
import { HeatmapsSettings } from './environment/HeatmapsSettings'
import { HumanFriendlyComparisonPeriodsSetting } from './environment/HumanFriendlyComparisonPeriodsSetting'
Expand Down Expand Up @@ -299,6 +300,18 @@ export const SETTINGS_MAP: SettingSection[] = [
},
],
},
{
level: 'environment',
id: 'environment-feature-flags',
title: 'Feature flags',
settings: [
{
id: 'feature-flags-interface',
title: 'Feature flags',
component: <FeatureFlagSettings />,
},
],
},
{
level: 'environment',
id: 'environment-error-tracking',
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/scenes/settings/environment/FeatureFlagSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Link } from '@posthog/lemon-ui'
import { FeatureFlagSettings as BasicFeatureFlagSettings } from 'scenes/feature-flags/FeatureFlagSettings'
import { urls } from 'scenes/urls'

export function FeatureFlagSettings(): JSX.Element {
return (
<>
<p>
Configure default behavior for feature flags. Flags can be managed on the{' '}
<Link to={urls.featureFlags()}>feature flags page</Link>.
</p>

<BasicFeatureFlagSettings />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ exports[`verifiedDomainsLogic values has proper defaults 1`] = `
"data-attr",
],
"effective_membership_level": 8,
"flags_persistence_default": false,
"has_group_types": true,
"heatmaps_opt_in": true,
"human_friendly_comparison_periods": false,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/scenes/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type SettingSectionId =
| 'environment-web-analytics'
| 'environment-replay'
| 'environment-surveys'
| 'environment-feature-flags'
| 'environment-error-tracking'
| 'environment-toolbar'
| 'environment-integrations'
Expand Down Expand Up @@ -72,6 +73,7 @@ export type SettingId =
| 'replay-authorized-domains'
| 'replay-ingestion'
| 'surveys-interface'
| 'feature-flags-interface'
| 'error-tracking-user-groups'
| 'authorized-toolbar-urls'
| 'integration-webhooks'
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/teamActivityDescriber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ const teamActionsMapping: Record<
slack_incoming_webhook: () => null,
timezone: () => null,
surveys_opt_in: () => null,
flags_persistence_default: () => null,
week_start_day: () => null,
default_modifiers: () => null,
has_completed_onboarding_for: () => null,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ export interface TeamType extends TeamBasicType {
default_modifiers?: HogQLQueryModifiers
product_intents?: ProductIntentType[]
default_data_theme?: number
flags_persistence_default: boolean
}

export interface ProductIntentType {
Expand Down
1 change: 1 addition & 0 deletions posthog/api/decide.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def get_base_config(token: str, team: Team, request: HttpRequest, skip_db: bool

response["surveys"] = True if team.surveys_opt_in else False
response["heatmaps"] = True if team.heatmaps_opt_in else False
response["flagsPersistenceDefault"] = True if team.flags_persistence_default else False
response["defaultIdentifiedOnly"] = True # Support old SDK versions with setting that is now the default

site_apps = []
Expand Down
2 changes: 2 additions & 0 deletions posthog/api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Meta:
"surveys_opt_in", # Compat with TeamSerializer
"heatmaps_opt_in", # Compat with TeamSerializer
"product_intents", # Compat with TeamSerializer
"flags_persistence_default", # Compat with TeamSerializer
)
read_only_fields = (
"id",
Expand Down Expand Up @@ -184,6 +185,7 @@ class Meta:
"has_completed_onboarding_for",
"surveys_opt_in",
"heatmaps_opt_in",
"flags_persistence_default",
}

def get_effective_membership_level(self, project: Project) -> Optional[OrganizationMembership.Level]:
Expand Down
2 changes: 2 additions & 0 deletions posthog/api/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class Meta:
"surveys_opt_in",
"heatmaps_opt_in",
"capture_dead_clicks",
"flags_persistence_default",
]
read_only_fields = fields

Expand Down Expand Up @@ -211,6 +212,7 @@ class Meta:
"has_completed_onboarding_for",
"surveys_opt_in",
"heatmaps_opt_in",
"flags_persistence_default",
"live_events_token",
"product_intents",
"capture_dead_clicks",
Expand Down
3 changes: 3 additions & 0 deletions posthog/api/test/__snapshots__/test_action.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"posthog_team"."capture_dead_clicks",
"posthog_team"."surveys_opt_in",
"posthog_team"."heatmaps_opt_in",
"posthog_team"."flags_persistence_default",
"posthog_team"."session_recording_version",
"posthog_team"."signup_token",
"posthog_team"."is_demo",
Expand Down Expand Up @@ -377,6 +378,7 @@
"posthog_team"."capture_dead_clicks",
"posthog_team"."surveys_opt_in",
"posthog_team"."heatmaps_opt_in",
"posthog_team"."flags_persistence_default",
"posthog_team"."session_recording_version",
"posthog_team"."signup_token",
"posthog_team"."is_demo",
Expand Down Expand Up @@ -894,6 +896,7 @@
"posthog_team"."capture_dead_clicks",
"posthog_team"."surveys_opt_in",
"posthog_team"."heatmaps_opt_in",
"posthog_team"."flags_persistence_default",
"posthog_team"."session_recording_version",
"posthog_team"."signup_token",
"posthog_team"."is_demo",
Expand Down
3 changes: 3 additions & 0 deletions posthog/api/test/__snapshots__/test_annotation.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"posthog_team"."capture_dead_clicks",
"posthog_team"."surveys_opt_in",
"posthog_team"."heatmaps_opt_in",
"posthog_team"."flags_persistence_default",
"posthog_team"."session_recording_version",
"posthog_team"."signup_token",
"posthog_team"."is_demo",
Expand Down Expand Up @@ -372,6 +373,7 @@
"posthog_team"."capture_dead_clicks",
"posthog_team"."surveys_opt_in",
"posthog_team"."heatmaps_opt_in",
"posthog_team"."flags_persistence_default",
"posthog_team"."session_recording_version",
"posthog_team"."signup_token",
"posthog_team"."is_demo",
Expand Down Expand Up @@ -821,6 +823,7 @@
"posthog_team"."capture_dead_clicks",
"posthog_team"."surveys_opt_in",
"posthog_team"."heatmaps_opt_in",
"posthog_team"."flags_persistence_default",
"posthog_team"."session_recording_version",
"posthog_team"."signup_token",
"posthog_team"."is_demo",
Expand Down
Loading

0 comments on commit 4ba47b8

Please sign in to comment.