diff --git a/packages/admin/components/fields/index.tsx b/packages/admin/components/fields/index.tsx index 60ccb6ca..8a8da827 100644 --- a/packages/admin/components/fields/index.tsx +++ b/packages/admin/components/fields/index.tsx @@ -1,4 +1,4 @@ -import type { AllowedSettingKeys, SettingSchema } from '@/admin/types'; +import type { FieldSchema } from '@/admin/types'; import { Field } from './field'; export const Fields = ( { @@ -9,7 +9,7 @@ export const Fields = ( { }: { excludedProperties?: string[]; values: Record< string, unknown > | undefined; - fields: SettingSchema[ AllowedSettingKeys ]; + fields: Record< string, FieldSchema >; setValue: ( values: Record< string, unknown > ) => void; } ) => { if ( ! values ) { diff --git a/packages/admin/components/layout/header/menu/index.tsx b/packages/admin/components/layout/header/menu/index.tsx index d72a85d8..dfd02277 100644 --- a/packages/admin/components/layout/header/menu/index.tsx +++ b/packages/admin/components/layout/header/menu/index.tsx @@ -2,7 +2,7 @@ import { Button, Icon, NavigableMenu } from '@wordpress/components'; import { link as LinkSVG } from '@wordpress/icons'; import { __ } from '@wordpress/i18n'; import { useCurrentScreen } from '@/admin/components/screen/context'; -import type { AllowedScreens } from '@/admin/components/screen/screen'; +import { getScreenForSetting } from '@/admin/components/screen/utils'; import styles from './styles.module.scss'; @@ -13,43 +13,57 @@ const LinkIcon = () => { return ; }; -const SCREEN_LABELS: Record< AllowedScreens, string > = { - providers: __( 'Login Providers', 'wp-graphql-headless-login' ), - 'access-control': __( 'Access Control', 'wp-graphql-headless-login' ), - 'plugin-settings': __( 'Misc', 'wp-graphql-headless-login' ), +/** + * Builds and returns the menu object from the wpGraphQLLogin.settings global. + */ +export const getMenuObject = (): Record< string, string > => { + const settings = wpGraphQLLogin.settings; + + const menu: Record< string, string > = { + providers: '', // We want this as the first key. + }; + + for ( const key in settings ) { + // @todo get providers from global after the refactor. + const menuTitle = + settings[ key ].label || + __( 'Providers', 'wp-graphql-headless-login' ); + const screen = getScreenForSetting( key ); + + menu[ screen ] = menuTitle; + } + + return menu; }; export const Menu = () => { const { currentScreen, setCurrentScreen } = useCurrentScreen(); + // Build the menu object of screens and labels from the wpGraphQLLogin?.settings. + const menuItems = getMenuObject(); + return (