diff --git a/includes/RestApi/SiteGenController.php b/includes/RestApi/SiteGenController.php index 61e99f664..f83eed0b2 100644 --- a/includes/RestApi/SiteGenController.php +++ b/includes/RestApi/SiteGenController.php @@ -30,6 +30,15 @@ class SiteGenController { * @return void */ public function register_routes() { + \register_rest_route( + $this->namespace, + $this->rest_base . '/get-identifiers', + array( + 'methods' => \WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_valid_identifiers' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + ) + ); \register_rest_route( $this->namespace, $this->rest_base . '/generate', @@ -64,6 +73,15 @@ public function sitegen_meta_args() { ); } + /** + * Gets all the valid Identifiers + * + * @return array + */ + public function get_valid_identifiers() { + return array_keys( array_filter( SiteGenService::get_identifiers() ) ); + } + /** * Generate Sitegen meta data. * diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index ab881654e..0e16ea38d 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -11,7 +11,10 @@ import ToggleDarkMode from '../../ToggleDarkMode'; import { ThemeProvider } from '../../ThemeContextProvider'; import { store as nfdOnboardingStore } from '../../../store'; import { setFlow } from '../../../utils/api/flow'; -import { generateSiteGenMeta } from '../../../utils/api/siteGen'; +import { + generateSiteGenMeta, + getSiteGenIdentifiers, +} from '../../../utils/api/siteGen'; // Wrapping the NewfoldInterfaceSkeleton with the HOC to make theme available const ThemedNewfoldInterfaceSkeleton = themeToggleHOC( @@ -39,7 +42,7 @@ const SiteGen = () => { } } - function generateSiteGenData() { + async function generateSiteGenData() { // Start the API Requests when the loader is shown. if ( ! ( @@ -58,16 +61,8 @@ const SiteGen = () => { return; } - let identifiers = [ - 'siteclassification', - 'targetaudience', - 'contenttones', - 'contentstructure', - 'colorpalette', - 'sitemap', - 'pluginrecommendation', - 'fontpair', - ]; + let identifiers = await getSiteGenIdentifiers(); + identifiers = identifiers.body; const midIndex = Math.floor( identifiers.length / 2 ); if ( location.pathname.includes( 'experience' ) ) { diff --git a/src/OnboardingSPA/utils/api/siteGen.js b/src/OnboardingSPA/utils/api/siteGen.js index 6f150705c..b41fdc75f 100644 --- a/src/OnboardingSPA/utils/api/siteGen.js +++ b/src/OnboardingSPA/utils/api/siteGen.js @@ -3,6 +3,14 @@ import apiFetch from '@wordpress/api-fetch'; import { resolve } from './resolve.js'; import { onboardingRestURL } from './common'; +export async function getSiteGenIdentifiers() { + return await resolve( + apiFetch( { + url: onboardingRestURL( 'sitegen/get-identifiers' ), + } ).then() + ); +} + export async function generateSiteGenMeta( siteInfo, identifier,