Skip to content

Commit

Permalink
provide rootClientId for pattern fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Apr 16, 2021
1 parent ba1113a commit 6a86ff3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const BlockPatternSetup = ( {
const [ activeSlide, setActiveSlide ] = useState( 0 );
const [ showBlank, setShowBlank ] = useState( false );
const { replaceBlock } = useDispatch( blockEditorStore );
const patterns = usePatternsSetup( blockName, filterPatternsFn );
const patterns = usePatternsSetup( clientId, blockName, filterPatternsFn );

if ( ! patterns?.length || showBlank ) {
return startBlankComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ import { useSelect } from '@wordpress/data';
*/
import { store as blockEditorStore } from '../../store';

function usePatternsSetup( blockName, filterPatternsFn ) {
function usePatternsSetup( clientId, blockName, filterPatternsFn ) {
const { patterns } = useSelect(
( select ) => {
const {
getBlockRootClientId,
__experimentalGetPatternsByBlockTypes,
__experimentalGetAllowedPatterns,
} = select( blockEditorStore );
const rootClientId = getBlockRootClientId( clientId );
let _patterns;
// TODO maybe support combination of scoped and provided function??
if ( filterPatternsFn ) {
// TODO check rootClientId
_patterns = __experimentalGetAllowedPatterns().filter(
filterPatternsFn
);
_patterns = __experimentalGetAllowedPatterns(
rootClientId
).filter( filterPatternsFn );
} else {
// TODO check and rootClientId
_patterns = __experimentalGetPatternsByBlockTypes( blockName );
_patterns = __experimentalGetPatternsByBlockTypes(
blockName,
rootClientId
);
}
return { patterns: _patterns };
},
[ blockName ]
[ clientId, blockName, filterPatternsFn ]
);

return patterns;
Expand Down

0 comments on commit 6a86ff3

Please sign in to comment.