From d5444f6351f3c2e68211e333114945c12152c07f Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Tue, 14 Jan 2020 18:19:35 +0800 Subject: [PATCH] Updating unread stock indicator on stock update (https://github.com/woocommerce/woocommerce-admin/pull/3550) * Force refetch of low product query after updating stock * Continue showing unread indicator while fetching --- .../header/activity-panel/unread-indicators.js | 5 ++--- .../client/wc-api/items/operations.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/plugins/woocommerce-admin/client/header/activity-panel/unread-indicators.js b/plugins/woocommerce-admin/client/header/activity-panel/unread-indicators.js index 17960450833..d5d03f57d6c 100644 --- a/plugins/woocommerce-admin/client/header/activity-panel/unread-indicators.js +++ b/plugins/woocommerce-admin/client/header/activity-panel/unread-indicators.js @@ -88,7 +88,7 @@ export function getUnapprovedReviews( select ) { } export function getUnreadStock( select ) { - const { getItems, getItemsError, getItemsTotalCount, isGetItemsRequesting } = select( 'wc-api' ); + const { getItems, getItemsError, getItemsTotalCount } = select( 'wc-api' ); const productsQuery = { page: 1, per_page: 1, @@ -98,9 +98,8 @@ export function getUnreadStock( select ) { getItems( 'products', productsQuery ); const lowInStockCount = getItemsTotalCount( 'products', productsQuery ); const isError = Boolean( getItemsError( 'products', productsQuery ) ); - const isRequesting = isGetItemsRequesting( 'products', productsQuery ); - if ( isError || isRequesting ) { + if ( isError ) { return null; } diff --git a/plugins/woocommerce-admin/client/wc-api/items/operations.js b/plugins/woocommerce-admin/client/wc-api/items/operations.js index bf0bb133bec..d0bc2e6b50f 100644 --- a/plugins/woocommerce-admin/client/wc-api/items/operations.js +++ b/plugins/woocommerce-admin/client/wc-api/items/operations.js @@ -117,8 +117,19 @@ function updateLocally( resourceNames, data ) { return updateableTypes.includes( getResourcePrefix( name ) ); } ); + const lowStockResourceName = getResourceName( 'items-query-products', { + page: 1, + per_page: 1, + low_in_stock: true, + status: 'publish', + } ); + return filteredNames.map( async resourceName => { - return { [ resourceName ]: { data: data[ resourceName ] } }; + return { + [ resourceName ]: { data: data[ resourceName ] }, + // Force low stock products to be re-fetched after updating an item. + [ lowStockResourceName ]: { lastReceived: null }, + }; } ); }