Skip to content

Commit

Permalink
Restore filtering for post type
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 12, 2024
1 parent 56adeef commit b5ee816
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
27 changes: 27 additions & 0 deletions packages/core-data/src/private-selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/**
* External dependencies
*/
import createSelector from 'rememo';

/**
* WordPress dependencies
*/
import { createRegistrySelector } from '@wordpress/data';

/**
* Internal dependencies
*/
import type { State } from './selectors';
import { STORE_NAME } from './name';

type EntityRecordKey = string | number;

Expand All @@ -28,3 +39,19 @@ export function getNavigationFallbackId(
): EntityRecordKey | undefined {
return state.navigationFallbackId;
}

export const getBlockPatternsForPostType = createRegistrySelector(
( select: any ) =>
createSelector(
( state, postType ) =>
select( STORE_NAME )
.getBlockPatterns()
.filter(
( { postTypes } ) =>
! postTypes ||
( Array.isArray( postTypes ) &&
postTypes.includes( postType ) )
),
() => [ select( STORE_NAME ).getBlockPatterns() ]
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import { mediaUpload } from '../../utils';
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';

const selectBlockPatterns = ( select ) =>
select( coreStore ).getBlockPatterns();

const EMPTY_BLOCKS_LIST = [];

const BLOCK_EDITOR_SETTINGS = [
Expand Down Expand Up @@ -251,8 +248,10 @@ function useBlockEditorSettings( settings, postType, postId ) {
keepCaretInsideBlock,
mediaUpload: hasUploadPermissions ? mediaUpload : undefined,
__experimentalBlockPatterns: blockPatterns,
[ unlock( privateApis ).selectBlockPatternsKey ]:
selectBlockPatterns,
[ unlock( privateApis ).selectBlockPatternsKey ]: ( select ) =>
unlock( select( coreStore ) ).getBlockPatternsForPostType(
postType
),
__experimentalReusableBlocks: reusableBlocks,
__experimentalBlockPatternCategories: blockPatternCategories,
__experimentalUserPatternCategories: userPatternCategories,
Expand Down

0 comments on commit b5ee816

Please sign in to comment.