Download wp-calypso/packages/data-stores/src/onboard/utils.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/onboard/utils.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/data-stores/src/onboard/utils.ts
-
curl -L -o utils.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/onboard/utils.ts
1.55 kB
| import { SiteGoal, SiteIntent } from './constants'; | |
| interface Flags { | |
| isIntentCreateCourseGoalEnabled?: boolean; | |
| } | |
| export const goalsToIntent = ( goals: SiteGoal[], flags?: Flags ): SiteIntent => { | |
| const { isIntentCreateCourseGoalEnabled } = flags ?? {}; | |
| // When DIFM and Import goals are selected together, DIFM Intent will have the priority and will be set. | |
| if ( goals.includes( SiteGoal.DIFM ) ) { | |
| return SiteIntent.DIFM; | |
| } | |
| if ( goals.includes( SiteGoal.Import ) ) { | |
| return SiteIntent.Import; | |
| } | |
| if ( goals.includes( SiteGoal.Courses ) && isIntentCreateCourseGoalEnabled ) { | |
| return SiteIntent.CreateCourseGoal; | |
| } | |
| // Newsletter flow | |
| if ( goals.includes( SiteGoal.Newsletter ) ) { | |
| return SiteIntent.NewsletterGoal; | |
| } | |
| // Prioritize Sell over Build and Write | |
| if ( | |
| goals.some( ( goal ) => | |
| [ SiteGoal.Sell, SiteGoal.SellDigital, SiteGoal.SellPhysical ].includes( goal ) | |
| ) | |
| ) { | |
| return SiteIntent.Sell; | |
| } | |
| // Prioritize Build over Write | |
| if ( goals.includes( SiteGoal.Promote ) ) { | |
| return SiteIntent.Build; | |
| } | |
| if ( goals.includes( SiteGoal.Write ) ) { | |
| return SiteIntent.Write; | |
| } | |
| return SiteIntent.Build; | |
| }; | |
| export const serializeGoals = ( goals: SiteGoal[] ): string => { | |
| // Serialize goals by first + alphabetical order. | |
| const firstGoal = goals.find( ( goal ) => | |
| [ SiteGoal.Write, SiteGoal.Sell, SiteGoal.Promote, SiteGoal.DIFM, SiteGoal.Import ].includes( | |
| goal | |
| ) | |
| ); | |
| return ( firstGoal ? [ firstGoal ] : [] ) | |
| .concat( goals.filter( ( goal ) => goal !== firstGoal ).sort() ) | |
| .join( ',' ); | |
| }; | |