Skip to content

Commit 8c2e6e8

Browse files
committed
Remove orderCount and publishedProductCount setting and make use of data stores
1 parent 414b31b commit 8c2e6e8

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

plugins/woocommerce-admin/client/homescreen/activity-panel/index.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010
PanelRow,
1111
__experimentalText as Text,
1212
} from '@wordpress/components';
13-
import { ONBOARDING_STORE_NAME } from '@woocommerce/data';
13+
import {
14+
ONBOARDING_STORE_NAME,
15+
ORDERS_STORE_NAME,
16+
PRODUCTS_STORE_NAME,
17+
} from '@woocommerce/data';
1418
import { recordEvent } from '@woocommerce/tracks';
1519
import { useEffect } from '@wordpress/element';
1620
import { snakeCase } from 'lodash';
@@ -29,22 +33,46 @@ import { getUnapprovedReviews } from './reviews/utils';
2933
import { getUrlParams } from '../../utils';
3034
import { getAdminSetting } from '~/utils/admin-settings';
3135

36+
const ORDERS_QUERY_PARAMS = { _fields: [ 'id' ] };
37+
const PUBLISHED_PRODUCTS_QUERY_PARAMS = {
38+
status: 'publish',
39+
_fields: [ 'id' ],
40+
};
41+
3242
export const ActivityPanel = () => {
3343
const panelsData = useSelect( ( select ) => {
34-
const totalOrderCount = getAdminSetting( 'orderCount', 0 );
44+
const {
45+
getOrdersTotalCount,
46+
hasFinishedResolution: hasFinishedOrdersResolution,
47+
} = select( ORDERS_STORE_NAME );
48+
const {
49+
getProductsTotalCount,
50+
hasFinishedResolution: hasFinishedProductsResolution,
51+
} = select( PRODUCTS_STORE_NAME );
52+
const totalOrderCount = getOrdersTotalCount( ORDERS_QUERY_PARAMS, 0 );
3553
const orderStatuses = getOrderStatuses( select );
3654
const reviewsEnabled = getAdminSetting( 'reviewsEnabled', 'no' );
3755
const unreadOrdersCount = getUnreadOrders( select, orderStatuses );
3856
const manageStock = getAdminSetting( 'manageStock', 'no' );
3957
const lowStockProductsCount = getLowStockCount( select );
4058
const unapprovedReviewsCount = getUnapprovedReviews( select );
41-
const publishedProductCount = getAdminSetting(
42-
'publishedProductCount',
59+
const publishedProductCount = getProductsTotalCount(
60+
PUBLISHED_PRODUCTS_QUERY_PARAMS,
4361
0
4462
);
63+
const loadingOrderAndProductCount =
64+
! hasFinishedOrdersResolution( 'getOrdersTotalCount', [
65+
ORDERS_QUERY_PARAMS,
66+
0,
67+
] ) ||
68+
! hasFinishedProductsResolution( 'getProductsTotalCount', [
69+
PUBLISHED_PRODUCTS_QUERY_PARAMS,
70+
0,
71+
] );
4572
const taskList = select( ONBOARDING_STORE_NAME ).getTaskList( 'setup' );
4673

4774
return {
75+
loadingOrderAndProductCount,
4876
lowStockProductsCount,
4977
unapprovedReviewsCount,
5078
unreadOrdersCount,
@@ -57,7 +85,9 @@ export const ActivityPanel = () => {
5785
};
5886
} );
5987

60-
const panels = getAllPanels( panelsData );
88+
const panels = panelsData.loadingOrderAndProductCount
89+
? []
90+
: getAllPanels( panelsData );
6191

6292
useEffect( () => {
6393
if ( panelsData.isTaskListHidden !== undefined ) {

plugins/woocommerce/src/Internal/Admin/Homescreen.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public function __construct() {
5050
add_action( 'admin_head', array( $this, 'update_link_structure' ), 20 );
5151
}
5252
add_filter( 'woocommerce_admin_preload_options', array( $this, 'preload_options' ) );
53-
54-
add_filter( 'woocommerce_admin_shared_settings', array( $this, 'component_settings' ), 20 );
5553
}
5654

5755
/**
@@ -179,23 +177,4 @@ public function preload_options( $options ) {
179177

180178
return $options;
181179
}
182-
183-
/**
184-
* Add data to the shared component settings.
185-
*
186-
* @param array $settings Shared component settings.
187-
*/
188-
public function component_settings( $settings ) {
189-
$allowed_statuses = Settings::get_order_statuses( wc_get_order_statuses() );
190-
191-
// Remove the Draft Order status (from the Checkout Block).
192-
unset( $allowed_statuses['checkout-draft'] );
193-
194-
$status_counts = array_map( 'wc_orders_count', array_keys( $allowed_statuses ) );
195-
$product_counts = wp_count_posts( 'product' );
196-
$settings['orderCount'] = array_sum( $status_counts );
197-
$settings['publishedProductCount'] = $product_counts->publish;
198-
199-
return $settings;
200-
}
201180
}

0 commit comments

Comments
 (0)