Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Fix Stylebook filter blocks preview #8295

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions assets/js/blocks/cart-checkout-shared/use-forced-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
BlockInstance,
} from '@wordpress/blocks';
import type { Block, TemplateArray } from '@wordpress/blocks';
import { isEqual } from 'lodash';
import { MutableRefObject } from 'react';

interface LockableBlock extends Block {
Expand Down Expand Up @@ -116,6 +115,7 @@ export const useForcedLayout = ( {

const registry = useRegistry();
useEffect( () => {
let templateSynced = false;
const { replaceInnerBlocks } = dispatch( 'core/block-editor' );
return registry.subscribe( () => {
const innerBlocks = registry
Expand All @@ -125,12 +125,14 @@ export const useForcedLayout = ( {
// If there are NO inner blocks, sync with the given template.
if (
innerBlocks.length === 0 &&
currentDefaultTemplate.current.length > 0
currentDefaultTemplate.current.length > 0 &&
! templateSynced
) {
const nextBlocks = createBlocksFromInnerBlocksTemplate(
currentDefaultTemplate.current
);
if ( ! isEqual( nextBlocks, innerBlocks ) ) {
if ( nextBlocks.length !== 0 ) {
templateSynced = true;
replaceInnerBlocks( clientId, nextBlocks );
return;
}
Expand Down Expand Up @@ -178,6 +180,6 @@ export const useForcedLayout = ( {
.dispatch( 'core/block-editor' )
.insertBlocks( blockConfig, insertAtPosition, clientId );
} );
} );
}, 'core/block-editor' );
}, [ clientId, registry ] );
};
2 changes: 1 addition & 1 deletion assets/js/blocks/filter-wrapper/upgrade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const UpgradeNotice = ( {
} );
};

if ( isInsideFilterWrapper || ! filterType ) {
if ( isInsideFilterWrapper || ! filterType || attributes?.isPreview ) {
return null;
}

Expand Down
4 changes: 4 additions & 0 deletions assets/js/blocks/price-filter/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"headingLevel": {
"type": "number",
"default": 3
},
"isPreview": {
"type": "boolean",
"default": false
}
},
"textdomain": "woo-gutenberg-products-block",
Expand Down