Don't show the Orders panel on the homescreen with the Task List (https://github.com/woocommerce/woocommerce-admin/pull/5552)
* Add order count to shared component settings. * Hide the Orders panel when the store has no orders. * Check for all order statuses except drafts from the checkout block.
This commit is contained in:
parent
a4ed451065
commit
479eb2c850
|
@ -4,6 +4,7 @@
|
|||
import { useSelect } from '@wordpress/data';
|
||||
import { Fragment } from '@wordpress/element';
|
||||
import { Accordion, AccordionPanel } from '@woocommerce/components';
|
||||
import { getSetting } from '@woocommerce/wc-admin-settings';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -14,9 +15,14 @@ import { getAllPanels } from './panels';
|
|||
|
||||
export const ActivityPanel = () => {
|
||||
const panels = useSelect( ( select ) => {
|
||||
const totalOrderCount = getSetting( 'orderCount', 0 );
|
||||
const orderStatuses = getOrderStatuses( select );
|
||||
const countUnreadOrders = getUnreadOrders( select, orderStatuses );
|
||||
return getAllPanels( { countUnreadOrders, orderStatuses } );
|
||||
return getAllPanels( {
|
||||
countUnreadOrders,
|
||||
orderStatuses,
|
||||
totalOrderCount,
|
||||
} );
|
||||
} );
|
||||
return (
|
||||
<Accordion>
|
||||
|
|
|
@ -16,6 +16,7 @@ describe( 'OrdersPanel', () => {
|
|||
isError={ false }
|
||||
isRequesting={ false }
|
||||
orderStatuses={ [] }
|
||||
totalOrderCount={ 10 }
|
||||
/>
|
||||
);
|
||||
expect(
|
||||
|
|
|
@ -8,9 +8,13 @@ import { __ } from '@wordpress/i18n';
|
|||
*/
|
||||
import OrdersPanel from './orders';
|
||||
|
||||
export function getAllPanels( { countUnreadOrders, orderStatuses } ) {
|
||||
export function getAllPanels( {
|
||||
countUnreadOrders,
|
||||
orderStatuses,
|
||||
totalOrderCount,
|
||||
} ) {
|
||||
return [
|
||||
{
|
||||
totalOrderCount > 0 && {
|
||||
className: 'woocommerce-homescreen-card',
|
||||
count: countUnreadOrders,
|
||||
id: 'orders-panel',
|
||||
|
@ -24,5 +28,5 @@ export function getAllPanels( { countUnreadOrders, orderStatuses } ) {
|
|||
title: __( 'Orders', 'woocommerce-admin' ),
|
||||
},
|
||||
// Add another panel row here
|
||||
];
|
||||
].filter( Boolean );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { getAllPanels } from '../panels';
|
||||
|
||||
describe( 'ActivityPanel', () => {
|
||||
it( 'should exclude the orders panel when there are no orders', () => {
|
||||
const panels = getAllPanels( {
|
||||
countUnreadOrders: 0,
|
||||
orderStatuses: [],
|
||||
totalOrderCount: 0,
|
||||
} );
|
||||
|
||||
expect( panels ).toEqual(
|
||||
expect.not.arrayContaining( [
|
||||
expect.objectContaining( { id: 'orders-panel' } ),
|
||||
] )
|
||||
);
|
||||
} );
|
||||
|
||||
it( 'should include the orders panel when there are orders', () => {
|
||||
const panels = getAllPanels( {
|
||||
countUnreadOrders: 1,
|
||||
orderStatuses: [],
|
||||
totalOrderCount: 10,
|
||||
} );
|
||||
|
||||
expect( panels ).toEqual(
|
||||
expect.arrayContaining( [
|
||||
expect.objectContaining( { id: 'orders-panel' } ),
|
||||
] )
|
||||
);
|
||||
} );
|
||||
} );
|
|
@ -44,6 +44,7 @@ class Homescreen {
|
|||
add_action( 'admin_head', array( $this, 'update_link_structure' ), 20 );
|
||||
add_filter( 'woocommerce_admin_plugins_whitelist', array( $this, 'get_homescreen_allowed_plugins' ) );
|
||||
add_filter( 'woocommerce_admin_preload_options', array( $this, 'preload_options' ) );
|
||||
add_filter( 'woocommerce_shared_settings', array( $this, 'component_settings' ), 20 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,4 +135,21 @@ class Homescreen {
|
|||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add data to the shared component settings.
|
||||
*
|
||||
* @param array $settings Shared component settings.
|
||||
*/
|
||||
public function component_settings( $settings ) {
|
||||
$allowed_statuses = Loader::get_order_statuses( wc_get_order_statuses() );
|
||||
|
||||
// Remove the Draft Order status (from the Checkout Block).
|
||||
unset( $allowed_statuses['checkout-draft'] );
|
||||
|
||||
$status_counts = array_map( 'wc_orders_count', array_keys( $allowed_statuses ) );
|
||||
$settings['orderCount'] = array_sum( $status_counts );
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue