diff --git a/plugins/woocommerce-blocks/assets/js/blocks/product-filter/block.json b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/block.json index b701f5d18d3..94b21132302 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/product-filter/block.json +++ b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/block.json @@ -17,9 +17,17 @@ }, "heading": { "type": "string" + }, + "isPreview": { + "type": "boolean", + "default": false + } + }, + "example": { + "attributes": { + "isPreview": true } }, "apiVersion": 2, - "$schema": "https://schemas.wp.org/trunk/block.json", - "example": {} + "$schema": "https://schemas.wp.org/trunk/block.json" } diff --git a/plugins/woocommerce-blocks/assets/js/blocks/product-filter/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/edit.tsx index 009ccf3bdc1..44d009ddc4a 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/product-filter/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/edit.tsx @@ -17,7 +17,11 @@ import type { FilterType } from './types'; const Edit = ( { attributes, clientId, -}: BlockEditProps< { heading: string; filterType: FilterType } > ) => { +}: BlockEditProps< { + heading: string; + filterType: FilterType; + isPreview: boolean; +} > ) => { const blockProps = useBlockProps(); const isNested = useSelect( ( select ) => { @@ -50,6 +54,7 @@ const Edit = ( { lock: { remove: true, }, + isPreview: attributes.isPreview, }, ], ] } diff --git a/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/attribute-filter/constants.ts b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/attribute-filter/constants.ts new file mode 100644 index 00000000000..f5114d59ea6 --- /dev/null +++ b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/attribute-filter/constants.ts @@ -0,0 +1,47 @@ +export const attributeOptionsPreview = [ + { + id: 23, + name: 'Blue', + slug: 'blue', + attr_slug: 'blue', + description: '', + parent: 0, + count: 4, + }, + { + id: 29, + name: 'Gray', + slug: 'gray', + attr_slug: 'gray', + description: '', + parent: 0, + count: 3, + }, + { + id: 24, + name: 'Green', + slug: 'green', + attr_slug: 'green', + description: '', + parent: 0, + count: 3, + }, + { + id: 25, + name: 'Red', + slug: 'red', + attr_slug: 'red', + description: '', + parent: 0, + count: 4, + }, + { + id: 30, + name: 'Yellow', + slug: 'yellow', + attr_slug: 'yellow', + description: '', + parent: 0, + count: 1, + }, +]; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/attribute-filter/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/attribute-filter/edit.tsx index 2be98d1ecdc..e53e5e258bd 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/attribute-filter/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/attribute-filter/edit.tsx @@ -35,6 +35,7 @@ import { getAttributeFromId } from './utils'; import { Inspector } from './components/inspector-controls'; import { AttributeCheckboxList } from './components/attribute-checkbox-list'; import { AttributeDropdown } from './components/attribute-dropdown'; +import { attributeOptionsPreview } from './constants'; import './style.scss'; const ATTRIBUTES = getSetting< AttributeSetting[] >( 'attributes', [] ); @@ -178,6 +179,23 @@ const Edit = ( props: EditProps ) => { setIsEditing( ! isEditing ); }, [ isEditing ] ); + if ( isPreview ) { + return ( + + + + + + ); + } + // Block rendering starts. if ( Object.keys( ATTRIBUTES ).length === 0 ) return ( diff --git a/plugins/woocommerce/changelog/45558-fix-45491-incorrect-product-filter-attribute-block-preview b/plugins/woocommerce/changelog/45558-fix-45491-incorrect-product-filter-attribute-block-preview new file mode 100644 index 00000000000..35cff44f86f --- /dev/null +++ b/plugins/woocommerce/changelog/45558-fix-45491-incorrect-product-filter-attribute-block-preview @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Add block preview to Product Filter: Attribute (Beta) block \ No newline at end of file