-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the
launchpad-first
flag with the goals-first cumulative ex…
…periment (#99914) * Replace the launchpad-first flag with the goals-first cumulative experiment * Update makeTestSite so it doesn't overwrite default site options * Add test cases for hiding launchpad for control variants of experiment * Fixed experiment test --------- Co-authored-by: Paulo Trentin <[email protected]>
- Loading branch information
Showing
11 changed files
with
284 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,66 @@ | ||
import config from '@automattic/calypso-config'; | ||
import { SiteDetails, Onboard } from '@automattic/data-stores'; | ||
import { useEffect, useState } from 'react'; | ||
import { loadExperimentAssignment } from 'calypso/lib/explat'; | ||
|
||
const SiteIntent = Onboard.SiteIntent; | ||
|
||
/** | ||
* Determines if the launchpad should be shown first based on site createion flow | ||
* @param {SiteDetails|undefined} site Site object | ||
* @returns {boolean} Whether launchpad should be shown first | ||
* @param site Site object | ||
* @returns Whether launchpad should be shown first | ||
*/ | ||
export const shouldShowLaunchpadFirst = ( site: SiteDetails ) => { | ||
const isLaunchpadFirstEnabled = config.isEnabled( 'home/launchpad-first' ); | ||
const wasSiteCreatedOnboardingFlow = site?.options?.site_creation_flow === 'onboarding'; | ||
const isNotBigSkyIntent = site?.options?.site_intent !== SiteIntent.AIAssembler; | ||
export const shouldShowLaunchpadFirst = async ( site: SiteDetails ): Promise< boolean > => { | ||
const wasSiteCreatedOnboardingFlow = site.options?.site_creation_flow === 'onboarding'; | ||
const createdAfterExperimentStart = | ||
( site.options?.created_at ?? '' ) > '2025-02-03T10:22:45+00:00'; // If created_at is null then this expression is false | ||
const isBigSkyIntent = site?.options?.site_intent === SiteIntent.AIAssembler; | ||
|
||
return isLaunchpadFirstEnabled && wasSiteCreatedOnboardingFlow && isNotBigSkyIntent; | ||
if ( isBigSkyIntent || ! wasSiteCreatedOnboardingFlow || ! createdAfterExperimentStart ) { | ||
return false; | ||
} | ||
|
||
const assignment = await loadExperimentAssignment( | ||
'calypso_signup_onboarding_goals_first_flow_holdout_v2_20250131' | ||
); | ||
|
||
return assignment?.variationName === 'treatment_cumulative'; | ||
}; | ||
|
||
export default shouldShowLaunchpadFirst; | ||
export const useShouldShowLaunchpadFirst = ( site?: SiteDetails | null ): [ boolean, boolean ] => { | ||
const [ state, setState ] = useState< boolean | 'loading' >( 'loading' ); | ||
|
||
useEffect( () => { | ||
let cancel = false; | ||
|
||
const getResponse = async () => { | ||
if ( ! site ) { | ||
return; | ||
} | ||
|
||
try { | ||
setState( 'loading' ); | ||
const result = await shouldShowLaunchpadFirst( site ); | ||
if ( ! cancel ) { | ||
setState( result ); | ||
} | ||
} catch ( err ) { | ||
if ( ! cancel ) { | ||
setState( false ); | ||
} | ||
} | ||
}; | ||
|
||
getResponse(); | ||
|
||
return () => { | ||
cancel = true; | ||
}; | ||
}, [ site ] ); | ||
|
||
if ( ! site ) { | ||
// If the site isn't available yet we'll assume we're still loading | ||
return [ true, false ]; | ||
} | ||
|
||
return [ state === 'loading', state === 'loading' ? false : state ]; | ||
}; |
Oops, something went wrong.