/**
* External dependencies
*/
import { registerPlugin } from '@wordpress/plugins';
import {
WooNavigationItem,
getNewPath,
pathIsExcluded,
} from '@woocommerce/navigation';
import { Link } from '@woocommerce/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { NAVIGATION_STORE_NAME } from '@woocommerce/data';
/**
* Internal dependencies
*/
import getReports from '../analytics/report/get-reports';
import { getPages } from './controller';
import { isWCAdmin } from '../dashboard/utils';
import Navigation from '~/navigation';
import { WooHeaderNavigationItem } from '~/header/utils';
const NavigationPlugin = () => {
const { persistedQuery } = useSelect( ( select ) => {
return {
persistedQuery: select( NAVIGATION_STORE_NAME ).getPersistedQuery(),
};
} );
if ( ! window.wcAdminFeatures.navigation ) {
return null;
}
/**
* If the current page is embedded, stay with the default urls
* provided by Navigation because the router isn't present to
* respond to component's manipulation of the url.
*/
if ( ! isWCAdmin( window.location.href ) ) {
return (
);
}
const reports = getReports().filter( ( item ) => item.navArgs );
const pages = getPages()
.filter( ( page ) => page.navArgs )
.map( ( page ) => {
if ( page.path === '/analytics/settings' ) {
return {
...page,
breadcrumbs: [ __( 'Analytics', 'woocommerce' ) ],
};
}
return page;
} );
return (
<>
{ pages.map( ( page ) => (
{ page.breadcrumbs[ page.breadcrumbs.length - 1 ] }
) ) }
{ reports.map( ( item ) => (
{ item.title }
) ) }
>
);
};
registerPlugin( 'wc-admin-navigation', {
render: NavigationPlugin,
scope: 'woocommerce-navigation',
} );