Skip to content

Commit

Permalink
Fix post transform panel
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 9, 2024
1 parent fcab8e0 commit 6b8ad4a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
31 changes: 20 additions & 11 deletions packages/editor/src/components/post-transform-panel/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { useSelect } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
import { parse } from '@wordpress/blocks';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { store as editorStore } from '../../store';

const { EXCLUDED_PATTERN_SOURCES, PATTERN_TYPES } =
unlock( patternsPrivateApis );
Expand Down Expand Up @@ -84,22 +84,31 @@ function preparePatterns( patterns, currentThemeStylesheet ) {
}

export function useAvailablePatterns( template ) {
const { blockPatterns, currentThemeStylesheet } = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const { blockPatterns, restBlockPatterns, currentThemeStylesheet } =
useSelect( ( select ) => {
const { getEditorSettings } = select( editorStore );
const settings = getEditorSettings();

return {
blockPatterns: getSettings().__experimentalBlockPatterns,
currentThemeStylesheet:
select( coreStore ).getCurrentTheme().stylesheet,
};
}, [] );
return {
blockPatterns:
settings.__experimentalAdditionalBlockPatterns ??
settings.__experimentalBlockPatterns,
restBlockPatterns: select( coreStore ).getBlockPatterns(),
currentThemeStylesheet:
select( coreStore ).getCurrentTheme().stylesheet,
};
}, [] );

return useMemo( () => {
const filteredPatterns = filterPatterns( blockPatterns, template );
const mergedPatterns = [
...( blockPatterns || [] ),
...( restBlockPatterns || [] ),
];
const filteredPatterns = filterPatterns( mergedPatterns, template );
return preparePatterns(
filteredPatterns,
template,
currentThemeStylesheet
);
}, [ blockPatterns, template, currentThemeStylesheet ] );
}, [ blockPatterns, restBlockPatterns, template, currentThemeStylesheet ] );
}
3 changes: 1 addition & 2 deletions packages/editor/src/components/post-transform-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function PostTransform() {
content: serialize( selectedTemplate.blocks ),
} );
};

if ( ! availablePatterns?.length ) {
return null;
}
Expand Down Expand Up @@ -91,7 +90,7 @@ export default function PostTransformPanel() {
}, [] );

if (
[ TEMPLATE_PART_POST_TYPE, TEMPLATE_POST_TYPE ].includes( postType )
! [ TEMPLATE_PART_POST_TYPE, TEMPLATE_POST_TYPE ].includes( postType )
) {
return null;
}
Expand Down

0 comments on commit 6b8ad4a

Please sign in to comment.