Updates default analytics menu (https://github.com/woocommerce/woocommerce-admin/pull/658)
* Updates default analytics menu * Make revenue the default analytics page * Fix header link to direct to Revenue report * Fix highlighting with additional filters
This commit is contained in:
parent
ec0e49ec10
commit
57e46e3273
|
@ -79,7 +79,9 @@ class Report extends Component {
|
|||
const Container = report.component;
|
||||
return (
|
||||
<Fragment>
|
||||
<Header sections={ [ [ '/analytics', __( 'Analytics', 'wc-admin' ) ], report.title ] } />
|
||||
<Header
|
||||
sections={ [ [ '/analytics/revenue', __( 'Analytics', 'wc-admin' ) ], report.title ] }
|
||||
/>
|
||||
<Container { ...this.props } />
|
||||
</Fragment>
|
||||
);
|
||||
|
|
|
@ -95,25 +95,37 @@ window.wpNavMenuClassChange = function( page ) {
|
|||
item.classList.remove( 'current' );
|
||||
} );
|
||||
|
||||
const submenu = document.querySelector( '.wp-has-current-submenu' );
|
||||
submenu.classList.remove( 'wp-has-current-submenu' );
|
||||
submenu.classList.remove( 'wp-menu-open' );
|
||||
submenu.classList.remove( 'selected' );
|
||||
submenu.classList.add( 'wp-not-current-submenu' );
|
||||
submenu.classList.add( 'menu-top' );
|
||||
const submenu = Array.from( document.querySelectorAll( '.wp-has-current-submenu' ) );
|
||||
submenu.forEach( function( element ) {
|
||||
element.classList.remove( 'wp-has-current-submenu' );
|
||||
element.classList.remove( 'wp-menu-open' );
|
||||
element.classList.remove( 'selected' );
|
||||
element.classList.add( 'wp-not-current-submenu' );
|
||||
element.classList.add( 'menu-top' );
|
||||
} );
|
||||
|
||||
const currentItems = document.querySelectorAll( `li > a[href="${ window.location.href }"]` );
|
||||
const pageHash = window.location.hash.split( '?' )[ 0 ];
|
||||
const currentItems = document.querySelectorAll( `li > a[href$="${ pageHash }"]` );
|
||||
|
||||
Array.from( currentItems ).forEach( function( item ) {
|
||||
item.parentElement.classList.add( 'current' );
|
||||
} );
|
||||
|
||||
// Make revenue the default url
|
||||
if ( page.wpOpenMenu === 'toplevel_page_wc-admin--analytics' ) {
|
||||
page.wpOpenMenu = 'toplevel_page_wc-admin--analytics-revenue';
|
||||
}
|
||||
const currentMenu = document.querySelector( '#' + page.wpOpenMenu );
|
||||
currentMenu.classList.remove( 'wp-not-current-submenu' );
|
||||
currentMenu.classList.add( 'wp-has-current-submenu' );
|
||||
currentMenu.classList.add( 'wp-menu-open' );
|
||||
currentMenu.classList.add( 'current' );
|
||||
|
||||
// Make revenue the default url
|
||||
if ( page.wpClosedMenu === 'toplevel_page_wc-admin--analytics' ) {
|
||||
page.wpClosedMenu = 'toplevel_page_wc-admin--analytics-revenue';
|
||||
}
|
||||
|
||||
// Sometimes navigating from the subMenu to Dashboard does not close subMenu
|
||||
const closedMenu = document.querySelector( '#' + page.wpClosedMenu );
|
||||
closedMenu.classList.remove( 'wp-has-current-submenu' );
|
||||
|
|
|
@ -79,7 +79,7 @@ function wc_admin_register_pages() {
|
|||
__( 'WooCommerce Analytics', 'wc-admin' ),
|
||||
__( 'Analytics', 'wc-admin' ),
|
||||
'manage_options',
|
||||
'wc-admin#/analytics',
|
||||
'wc-admin#/analytics/revenue',
|
||||
'wc_admin_page',
|
||||
'dashicons-chart-bar',
|
||||
56 // After WooCommerce & Product menu items.
|
||||
|
@ -88,7 +88,7 @@ function wc_admin_register_pages() {
|
|||
wc_admin_register_page(
|
||||
array(
|
||||
'title' => __( 'Revenue', 'wc-admin' ),
|
||||
'parent' => '/analytics',
|
||||
'parent' => '/analytics/revenue',
|
||||
'path' => '/analytics/revenue',
|
||||
)
|
||||
);
|
||||
|
@ -96,7 +96,7 @@ function wc_admin_register_pages() {
|
|||
wc_admin_register_page(
|
||||
array(
|
||||
'title' => __( 'Orders', 'wc-admin' ),
|
||||
'parent' => '/analytics',
|
||||
'parent' => '/analytics/revenue',
|
||||
'path' => '/analytics/orders',
|
||||
)
|
||||
);
|
||||
|
@ -104,7 +104,7 @@ function wc_admin_register_pages() {
|
|||
wc_admin_register_page(
|
||||
array(
|
||||
'title' => __( 'Products', 'wc-admin' ),
|
||||
'parent' => '/analytics',
|
||||
'parent' => '/analytics/revenue',
|
||||
'path' => '/analytics/products',
|
||||
)
|
||||
);
|
||||
|
@ -151,9 +151,6 @@ function wc_admin_link_structure() {
|
|||
// Move menu item to top of array.
|
||||
unset( $submenu['woocommerce'][ $wc_admin_key ] );
|
||||
array_unshift( $submenu['woocommerce'], $menu );
|
||||
|
||||
// Rename "Analytics" to Overview (otherwise this reads Analytics > Analytics).
|
||||
$submenu['wc-admin#/analytics'][0][0] = __( 'Overview', 'wc-admin' ); // WPCS: override ok.
|
||||
}
|
||||
|
||||
// priority is 20 to run after https://github.com/woocommerce/woocommerce/blob/a55ae325306fc2179149ba9b97e66f32f84fdd9c/includes/admin/class-wc-admin-menus.php#L165.
|
||||
|
|
Loading…
Reference in New Issue