diff --git a/plugins/woocommerce-admin/client/marketing/overview/knowledge-base/index.js b/plugins/woocommerce-admin/client/marketing/overview/knowledge-base/index.js index 8c86b9bcf09..eee6e487e77 100644 --- a/plugins/woocommerce-admin/client/marketing/overview/knowledge-base/index.js +++ b/plugins/woocommerce-admin/client/marketing/overview/knowledge-base/index.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { Component, Fragment } from '@wordpress/element'; +import { Component } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; import { Spinner } from '@wordpress/components'; @@ -11,7 +11,7 @@ import { withDispatch, withSelect } from '@wordpress/data'; /** * WooCommerce dependencies */ -import { Card, Pagination } from '@woocommerce/components'; +import { Card, Pagination, EmptyContent } from '@woocommerce/components'; /** * Internal dependencies @@ -109,30 +109,54 @@ class KnowledgeBase extends Component { const { posts, isLoading } = this.props; const { page, animate } = this.state; + const renderEmpty = () => { + const title = __( + 'There was an error loading knowledge base posts. Please check again later.', + 'woocommerce-admin' + ); + + return ( + + ); + }; + + const renderPosts = () => { + return ( +
+ + { this.getCurrentSlide() } + + +
+ ) + }; + + const renderCardBody = () => { + if ( isLoading ) { + return ; + } + return posts.length === 0 ? renderEmpty() : renderPosts(); + }; + return ( - - { isLoading ? : ( -
- - { this.getCurrentSlide() } - - -
- ) } -
+ { renderCardBody() }
) } diff --git a/plugins/woocommerce-admin/src/Features/Marketing.php b/plugins/woocommerce-admin/src/Features/Marketing.php index d844d298fe2..d86629607d8 100644 --- a/plugins/woocommerce-admin/src/Features/Marketing.php +++ b/plugins/woocommerce-admin/src/Features/Marketing.php @@ -129,8 +129,13 @@ class Marketing { $plugins = json_decode( $request['body'], true ); } - // Cache an empty result to avoid repeated failed requests. - set_transient( self::RECOMMENDED_PLUGINS_TRANSIENT, $plugins, 3 * DAY_IN_SECONDS ); + set_transient( + self::RECOMMENDED_PLUGINS_TRANSIENT, + $plugins, + // Expire transient in 15 minutes if remote get failed. + // Cache an empty result to avoid repeated failed requests. + empty( $plugins ) ? 900 : 3 * DAY_IN_SECONDS + ); } return array_values( $plugins ); @@ -186,7 +191,12 @@ class Marketing { } } - set_transient( self::KNOWLEDGE_BASE_TRANSIENT, $posts, DAY_IN_SECONDS ); + set_transient( + self::KNOWLEDGE_BASE_TRANSIENT, + $posts, + // Expire transient in 15 minutes if remote get failed. + empty( $posts ) ? 900 : DAY_IN_SECONDS + ); } return $posts;