Improve empty state in Editor by providing meaningful instruction

This commit is contained in:
Karol Manijak 2024-09-18 17:45:52 +08:00 committed by Christopher Allford
parent 3a3927676a
commit f8a18cfe83
No known key found for this signature in database
GPG Key ID: 80E44C778F08A88E
1 changed files with 18 additions and 8 deletions

View File

@ -16,7 +16,10 @@ import {
} from '@wordpress/block-editor';
import { Spinner } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { ProductCollectionAttributes } from '@woocommerce/blocks/product-collection/types';
import {
ProductCollectionAttributes,
CoreCollectionNames,
} from '@woocommerce/blocks/product-collection/types';
import { getSettingWithCoercion } from '@woocommerce/settings';
import { isNumber, ProductResponseItem } from '@woocommerce/types';
import { ProductDataContextProvider } from '@woocommerce/shared-context';
@ -35,6 +38,16 @@ import './editor.scss';
import { getDefaultStockStatuses } from '../product-collection/constants';
const DEFAULT_QUERY_CONTEXT_ATTRIBUTES = [ 'collection' ];
const getNoResultsText = ( collection?: CoreCollectionNames | string ) => {
if ( collection === CoreCollectionNames.HAND_PICKED ) {
return __(
'No products chosen yet. Use "Hand-Picked Products" in Inspector Controls to choose products to display',
'woocommerce'
);
}
return __( 'No results found.', 'woocommerce' );
};
const ProductTemplateInnerBlocks = () => {
const innerBlocksProps = useInnerBlocksProps(
@ -161,6 +174,7 @@ const ProductTemplateEdit = (
columns: 3,
shrinkColumns: false,
},
collection,
queryContextIncludes = [],
__privateProductCollectionPreviewState,
},
@ -312,7 +326,8 @@ const ProductTemplateEdit = (
const hasLayoutFlex = layoutType === 'flex' && columns > 1;
let customClassName = '';
if ( hasLayoutFlex ) {
// We don't want to apply layout styles if there's no products.
if ( products && products.length && hasLayoutFlex ) {
const dynamicGrid = `wc-block-product-template__responsive columns-${ columns }`;
const staticGrid = `is-flex-container columns-${ columns }`;
@ -337,12 +352,7 @@ const ProductTemplateEdit = (
}
if ( ! products.length ) {
return (
<p { ...blockProps }>
{ ' ' }
{ __( 'No results found.', 'woocommerce' ) }
</p>
);
return <p { ...blockProps }> { getNoResultsText( collection ) }</p>;
}
// To avoid flicker when switching active block contexts, a preview is rendered