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
This commit is contained in:
Joshua T Flowers 2020-01-14 18:19:35 +08:00 committed by GitHub
parent 7164e021fc
commit d5444f6351
2 changed files with 14 additions and 4 deletions

View File

@ -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;
}

View File

@ -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 },
};
} );
}