forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract usePublishedProductsCount hook and use it in about-the-editor…
…-menu-item (woocommerce#38742)
- Loading branch information
Showing
4 changed files
with
45 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
plugins/woocommerce-admin/client/products/tour/block-editor/use-published-products-count.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { PRODUCTS_STORE_NAME } from '@woocommerce/data'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
const PUBLISHED_PRODUCTS_QUERY_PARAMS = { | ||
status: 'publish', | ||
_fields: [ 'id' ], | ||
}; | ||
|
||
export const usePublishedProductsCount = () => { | ||
return useSelect( ( select ) => { | ||
const { getProductsTotalCount, hasFinishedResolution } = | ||
select( PRODUCTS_STORE_NAME ); | ||
|
||
const publishedProductsCount = getProductsTotalCount( | ||
PUBLISHED_PRODUCTS_QUERY_PARAMS, | ||
0 | ||
) as number; | ||
|
||
const loadingPublishedProductsCount = ! hasFinishedResolution( | ||
'getProductsTotalCount', | ||
[ PUBLISHED_PRODUCTS_QUERY_PARAMS, 0 ] | ||
); | ||
|
||
return { | ||
publishedProductsCount, | ||
loadingPublishedProductsCount, | ||
// we consider a user new if they have no published products | ||
isNewUser: publishedProductsCount < 1, | ||
}; | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: fix | ||
Comment: Consider if user is new or not when clicking in "About the editor" | ||
|
||
|