/** * External dependencies */ import { registerPlugin } from '@wordpress/plugins'; import { WooNavigationItem, getNewPath, getPersistedQuery, } from '@woocommerce/navigation'; import { Link } from '@woocommerce/components'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import getReports from '../analytics/report/get-reports'; import { getPages } from './controller'; import { isWCAdmin } from '../dashboard/utils'; const NavigationPlugin = () => { /** * 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 null; } const pagesWithoutNavigation = [ '/analytics/:report', '/setup-wizard' ]; const reports = getReports(); const pages = getPages() .filter( ( page ) => ! pagesWithoutNavigation.includes( page.path ) ) .map( ( page ) => { if ( page.path === '/analytics/settings' ) { return { ...page, id: 'wc-admin&path=' + page.path, breadcrumbs: [ __( 'Analytics', 'woocommerce-admin' ) ], }; } return { ...page, id: 'wc-admin&path=' + page.path, }; } ); const persistedQuery = getPersistedQuery( {} ); return ( <> { pages.map( ( page ) => ( { page.breadcrumbs[ page.breadcrumbs.length - 1 ] } ) ) } { reports.map( ( item ) => { const id = 'wc-admin&path=/analytics/' + item.report; return ( { item.title } ); } ) } ); }; registerPlugin( 'wc-admin-navigation', { render: NavigationPlugin } );