2021-02-22 18:54:27 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { NavigationMenu, NavigationGroup } from '@woocommerce/experimental';
|
2021-03-05 16:34:17 +00:00
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
2021-02-22 18:54:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import CategoryTitle from '../category-title';
|
|
|
|
import Item from '../../components/Item';
|
|
|
|
|
|
|
|
export const PrimaryMenu = ( {
|
|
|
|
category,
|
|
|
|
onBackClick,
|
|
|
|
pluginItems,
|
|
|
|
primaryItems,
|
|
|
|
} ) => {
|
|
|
|
if ( ! primaryItems.length && ! pluginItems.length ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* Navigation's exit button WooCommerce label.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_navigation_root_back_label
|
|
|
|
* @param {string} label Back button label.
|
|
|
|
*/
|
2021-03-05 16:34:17 +00:00
|
|
|
const rootBackLabel = applyFilters(
|
|
|
|
'woocommerce_navigation_root_back_label',
|
|
|
|
__( 'WordPress Dashboard', 'woocommerce-admin' )
|
|
|
|
);
|
|
|
|
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* Navigation's exit button url.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_navigation_root_back_url
|
|
|
|
* @param {string} url Back button url.
|
|
|
|
*/
|
2021-03-05 16:34:17 +00:00
|
|
|
const rootBackUrl = applyFilters(
|
|
|
|
'woocommerce_navigation_root_back_url',
|
|
|
|
window.wcNavigation.rootBackUrl
|
|
|
|
);
|
|
|
|
|
2021-02-22 18:54:27 +00:00
|
|
|
const isRootBackVisible = category.id === 'woocommerce' && rootBackUrl;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<NavigationMenu
|
|
|
|
title={ <CategoryTitle category={ category } /> }
|
|
|
|
menu={ category.id }
|
|
|
|
parentMenu={ category.parent }
|
|
|
|
backButtonLabel={
|
|
|
|
isRootBackVisible
|
|
|
|
? rootBackLabel
|
|
|
|
: category.backButtonLabel || null
|
|
|
|
}
|
|
|
|
onBackButtonClick={
|
|
|
|
isRootBackVisible
|
|
|
|
? () => {
|
|
|
|
onBackClick( 'woocommerce' );
|
|
|
|
window.location = rootBackUrl;
|
|
|
|
}
|
|
|
|
: () => onBackClick( category.id )
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{ !! primaryItems.length && (
|
|
|
|
<NavigationGroup>
|
|
|
|
{ primaryItems.map( ( item ) => (
|
|
|
|
<Item key={ item.id } item={ item } />
|
|
|
|
) ) }
|
|
|
|
</NavigationGroup>
|
|
|
|
) }
|
|
|
|
{ !! pluginItems.length && (
|
|
|
|
<NavigationGroup
|
|
|
|
title={
|
|
|
|
category.id === 'woocommerce'
|
|
|
|
? __( 'Extensions', 'woocommerce-admin' )
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{ pluginItems.map( ( item ) => (
|
|
|
|
<Item key={ item.id } item={ item } />
|
|
|
|
) ) }
|
|
|
|
</NavigationGroup>
|
|
|
|
) }
|
|
|
|
</NavigationMenu>
|
|
|
|
);
|
|
|
|
};
|