Skip to content

Commit

Permalink
feature complete, maybe needs tests?
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarticus committed Jan 14, 2025
1 parent a488b25 commit 8a8fa0e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
20 changes: 9 additions & 11 deletions frontend/src/scenes/feature-flags/featureFlagLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,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 All @@ -314,19 +317,13 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
},
},
})),
reducers(({ values }) => ({
reducers(() => ({
featureFlag: [
{ ...NEW_FLAG } as FeatureFlagType,
{
setFeatureFlag: (_, { featureFlag }) => {
return featureFlag
},
setFeatureFlagDefaults: () => {
return {
...NEW_FLAG,
ensure_experience_continuity: values.currentTeam?.flags_persistence_default || false,
}
},
setFeatureFlagFilters: (state, { filters }) => {
return { ...state, filters }
},
Expand Down Expand Up @@ -538,7 +535,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 Expand Up @@ -1059,8 +1059,6 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
} else if (props.id !== 'new') {
actions.loadFeatureFlag()
actions.loadFeatureFlagStatus()
} else {
actions.setFeatureFlagDefaults()
}
}),
])
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
17 changes: 17 additions & 0 deletions posthog/migrations/0542_team_flags_persistence_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.15 on 2025-01-14 23:21

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("posthog", "0541_usergroup_usergroupmembership_usergroup_members_and_more"),
]

operations = [
migrations.AddField(
model_name="team",
name="flags_persistence_default",
field=models.BooleanField(blank=True, default=False, null=True),
),
]
2 changes: 1 addition & 1 deletion posthog/migrations/max_migration.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0541_usergroup_usergroupmembership_usergroup_members_and_more
0542_team_flags_persistence_default
1 change: 1 addition & 0 deletions posthog/models/team/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class Meta:
capture_dead_clicks = models.BooleanField(null=True, blank=True, default=False)
surveys_opt_in = models.BooleanField(null=True, blank=True)
heatmaps_opt_in = models.BooleanField(null=True, blank=True)
flags_persistence_default = models.BooleanField(null=True, blank=True, default=False)
session_recording_version = models.CharField(null=True, blank=True, max_length=24)
signup_token = models.CharField(max_length=200, null=True, blank=True)
is_demo = models.BooleanField(default=False)
Expand Down

0 comments on commit 8a8fa0e

Please sign in to comment.