From 479eb2c85078fce5213e6e0e41543aa684757d85 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 23 Nov 2020 10:06:55 -0500 Subject: [PATCH] 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. --- .../client/homescreen/activity-panel/index.js | 8 ++++- .../activity-panel/orders/test/index.js | 1 + .../homescreen/activity-panel/panels.js | 10 ++++-- .../homescreen/activity-panel/test/panels.js | 34 +++++++++++++++++++ .../src/Features/Homescreen.php | 18 ++++++++++ 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 plugins/woocommerce-admin/client/homescreen/activity-panel/test/panels.js diff --git a/plugins/woocommerce-admin/client/homescreen/activity-panel/index.js b/plugins/woocommerce-admin/client/homescreen/activity-panel/index.js index 09e04ba21c4..39aec1db237 100644 --- a/plugins/woocommerce-admin/client/homescreen/activity-panel/index.js +++ b/plugins/woocommerce-admin/client/homescreen/activity-panel/index.js @@ -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 ( diff --git a/plugins/woocommerce-admin/client/homescreen/activity-panel/orders/test/index.js b/plugins/woocommerce-admin/client/homescreen/activity-panel/orders/test/index.js index 0baa3e49938..7d660a984c7 100644 --- a/plugins/woocommerce-admin/client/homescreen/activity-panel/orders/test/index.js +++ b/plugins/woocommerce-admin/client/homescreen/activity-panel/orders/test/index.js @@ -16,6 +16,7 @@ describe( 'OrdersPanel', () => { isError={ false } isRequesting={ false } orderStatuses={ [] } + totalOrderCount={ 10 } /> ); expect( diff --git a/plugins/woocommerce-admin/client/homescreen/activity-panel/panels.js b/plugins/woocommerce-admin/client/homescreen/activity-panel/panels.js index c3dc9086373..c00946699b8 100644 --- a/plugins/woocommerce-admin/client/homescreen/activity-panel/panels.js +++ b/plugins/woocommerce-admin/client/homescreen/activity-panel/panels.js @@ -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 ); } diff --git a/plugins/woocommerce-admin/client/homescreen/activity-panel/test/panels.js b/plugins/woocommerce-admin/client/homescreen/activity-panel/test/panels.js new file mode 100644 index 00000000000..65dfb9edc98 --- /dev/null +++ b/plugins/woocommerce-admin/client/homescreen/activity-panel/test/panels.js @@ -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' } ), + ] ) + ); + } ); +} ); diff --git a/plugins/woocommerce-admin/src/Features/Homescreen.php b/plugins/woocommerce-admin/src/Features/Homescreen.php index 64b25e7ee39..b4981de915b 100644 --- a/plugins/woocommerce-admin/src/Features/Homescreen.php +++ b/plugins/woocommerce-admin/src/Features/Homescreen.php @@ -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; + } }