8000 feat(flags): add flag persistence as a default setting across the org by dmarticus · Pull Request #27527 · PostHog/posthog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(flags): add flag persistence as a default setting across the org #27527

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

Merged
merged 32 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a488b25
making an attempt, not quite working yet
dmarticus Jan 14, 2025
8a8fa0e
feature complete, maybe needs tests?
dmarticus Jan 14, 2025
9aa03e0
Update query snapshots
github-actions[bot] Jan 15, 2025
5728ec8
Update query snapshots
github-actions[bot] Jan 15, 2025
3e4c0fa
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 15, 2025
b4cc4cd
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 15, 2025
7fdf8f2
Update query snapshots
github-actions[bot] Jan 15, 2025
0322726
Update query snapshots
github-actions[bot] Jan 15, 2025
1889fbf
update tests
dmarticus Jan 15, 2025
c8662cd
Merge branch 'master' into feat/enable-default-flag-persistence
dmarticus Jan 15, 2025
f826984
merge conflicts
dmarticus Jan 15, 2025
4bdfeb5
Update query snapshots
github-actions[bot] Jan 15, 2025
3bb01e0
resolve stuff
dmarticus Jan 15, 2025
572a5bc
resolve more stuff
dmarticus Jan 15, 2025
f5b211f
pretty good
dmarticus Jan 15, 2025
5aae85f
Update query snapshots
github-actions[bot] Jan 15, 2025
f5b2221
resolve conflicts
dmarticus Jan 15, 2025
dca00e0
Merge branch 'master' into feat/enable-default-flag-persistence 8000
dmarticus Jan 15, 2025
00f30bb
fixing migrations
dmarticus Jan 15, 2025
b206086
Merge branch 'master' into feat/enable-default-flag-persistence
dmarticus Jan 15, 2025
8aab0df
Merge branch 'master' into feat/enable-default-flag-persistence
dmarticus Jan 15, 2025
1182b9d
Merge branch 'feat/enable-default-flag-persistence' of github.com:Pos…
dmarticus Jan 15, 2025
8586745
Update query snapshots
github-actions[bot] Jan 15, 2025
efe4122
Update query snapshots
github-actions[bot] Jan 15, 2025
cfb6ec0
Merge branch 'master' into feat/enable-default-flag-persistence
dmarticus Jan 15, 2025
d733a04
fixing up the migrations
dmarticus Jan 15, 2025
fb3ce10
Merge branch 'master' into feat/enable-default-flag-persistence
dmarticus Jan 15, 2025
6060926
Update UI snapshots for `chromium` (1)
github-actions[bot] Jan 15, 2025
e3d8cd5
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 15, 2025
41f727f
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 15, 2025
51136b7
might try this eh
dmarticus Jan 15, 2025
79a8bb6
Update UI snapshots for `chromium` (2)
github-actions[bot] Jan 15, 2025
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.
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"
=> {
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
Loading
0