Просмотр исходного кода

fix(project-creation): fix frontend logging (#50656)

1. Added new experiment name to frontend code to restart experimentation
2. Made sure the logging happens once (in useEffect)

Test Plan:
1. Integration test
2. Checked with 3 experimentation value, made sure logging is not
happening for unassigned but happens only once for 0 and 1
Athena Moghaddam 1 год назад
Родитель
Сommit
e800cc190e

+ 1 - 1
src/sentry/api/endpoints/organization_projects_experiment.py

@@ -82,7 +82,7 @@ class OrganizationProjectsExperimentEndpoint(OrganizationEndpoint):
 
         result = serializer.validated_data
         exposed = expt_manager.get(
-            "ProjectCreationForAllExperiment", org=organization, actor=request.user
+            "ProjectCreationForAllExperimentV2", org=organization, actor=request.user
         )
 
         if (

+ 3 - 3
static/app/components/projects/useProjectCreationAccess.spec.jsx

@@ -44,7 +44,7 @@ describe('ProjectCreationAccess', function () {
     const experiment_org = TestStubs.Organization({
       access: ['org:read', 'team:read', 'project:read'],
       features: ['team-project-creation-all'],
-      experiments: [{ProjectCreationForAllExperiment: 1}],
+      experiments: [{ProjectCreationForAllExperimentV2: 1}],
     });
 
     jest.spyOn(useExperiment, 'useExperiment').mockReturnValue({
@@ -62,7 +62,7 @@ describe('ProjectCreationAccess', function () {
     const no_exp_org = TestStubs.Organization({
       access: ['org:read', 'team:read', 'project:read'],
       features: ['team-project-creation-all'],
-      experiments: [{ProjectCreationForAllExperiment: 0}],
+      experiments: [{ProjectCreationForAllExperimentV2: 0}],
     });
 
     jest.spyOn(useExperiment, 'useExperiment').mockReturnValue({
@@ -80,7 +80,7 @@ describe('ProjectCreationAccess', function () {
     const no_flag_org = TestStubs.Organization({
       access: ['org:read', 'team:read', 'project:read'],
       features: [],
-      experiments: [{ProjectCreationForAllExperiment: 1}],
+      experiments: [{ProjectCreationForAllExperimentV2: 1}],
     });
 
     jest.spyOn(useExperiment, 'useExperiment').mockReturnValue({

+ 17 - 17
static/app/components/projects/useProjectCreationAccess.tsx

@@ -1,4 +1,4 @@
-import {useMemo} from 'react';
+import {useEffect} from 'react';
 
 import {unassignedValue} from 'sentry/data/experimentConfig';
 import {Organization, Team} from 'sentry/types';
@@ -15,29 +15,29 @@ export function useProjectCreationAccess({
   teams: Team[];
 }) {
   const {experimentAssignment, logExperiment} = useExperiment(
-    'ProjectCreationForAllExperiment',
+    'ProjectCreationForAllExperimentV2',
     {
       logExperimentOnMount: false,
     }
   );
-  const canCreateProject = useMemo(() => {
-    if (
-      organization.access.includes('project:admin') ||
-      teams?.some(tm => tm.access.includes('team:admin'))
-    ) {
-      return true;
-    }
 
-    if (!organization.features.includes('team-project-creation-all')) {
-      return false;
-    }
+  const isAdmin =
+    organization.access.includes('project:admin') ||
+    teams?.some(tm => tm.access.includes('team:admin'));
+
+  const shouldBeInExperiment =
+    !isAdmin &&
+    organization.features.includes('team-project-creation-all') &&
+    experimentAssignment !== unassignedValue;
+
+  const canCreateProject =
+    isAdmin || (shouldBeInExperiment && experimentAssignment === 1);
 
-    if (experimentAssignment === unassignedValue) {
-      return false;
+  useEffect(() => {
+    if (shouldBeInExperiment) {
+      logExperiment();
     }
+  }, [logExperiment, shouldBeInExperiment]);
 
-    logExperiment();
-    return experimentAssignment === 1;
-  }, [organization, teams, experimentAssignment, logExperiment]);
   return {canCreateProject};
 }

+ 1 - 1
static/app/data/experimentConfig.tsx

@@ -25,7 +25,7 @@ export const experimentList = [
     assignments: [0, 1],
   },
   {
-    key: 'ProjectCreationForAllExperiment',
+    key: 'ProjectCreationForAllExperimentV2',
     type: ExperimentType.ORGANIZATION,
     parameter: 'exposed',
     assignments: [0, 1],