Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { store as noticesStore } from '@wordpress/notices';
*/
import { store as blockEditorStore } from '../../../store';
import { unlock } from '../../../lock-unlock';
import { isNavigationOverlayContextKey } from '../../../store/private-keys';
import {
isNavigationOverlayContextKey,
userPatternCategoriesSelectKey,
} from '../../../store/private-keys';
import { INSERTER_PATTERN_TYPES } from '../block-patterns-tab/utils';
import { isFiltered } from '../../../store/utils';

Expand Down Expand Up @@ -51,17 +54,19 @@ const usePatternsState = (
const { getSettings, __experimentalGetAllowedPatterns } = unlock(
select( blockEditorStore )
);
const {
__experimentalUserPatternCategories,
__experimentalBlockPatternCategories,
} = getSettings();
const settings = getSettings();
const userPatternCategoriesSelect =
settings[ userPatternCategoriesSelectKey ];
return {
patterns: __experimentalGetAllowedPatterns(
rootClientId,
options
),
userPatternCategories: __experimentalUserPatternCategories,
patternCategories: __experimentalBlockPatternCategories,
userPatternCategories: userPatternCategoriesSelect
? userPatternCategoriesSelect( select )
: settings.__experimentalUserPatternCategories,
patternCategories:
settings.__experimentalBlockPatternCategories,
};
},
[ rootClientId, options ]
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { useFlashEditableBlocks } from './components/use-flash-editable-blocks';
import {
selectBlockPatternsKey,
reusableBlocksSelectKey,
userPatternCategoriesSelectKey,
globalStylesDataKey,
globalStylesLinksDataKey,
sectionRootClientIdKey,
Expand Down Expand Up @@ -119,6 +120,7 @@ lock( privateApis, {
PrivateRichText,
PrivateInserterLibrary,
reusableBlocksSelectKey,
userPatternCategoriesSelectKey,
PrivateBlockPopover,
PrivatePublishDateTimePicker,
useSpacingSizes,
Expand Down
3 changes: 3 additions & 0 deletions packages/block-editor/src/store/private-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ export const globalStylesDataKey = Symbol( 'globalStylesDataKey' );
export const globalStylesLinksDataKey = Symbol( 'globalStylesLinks' );
export const selectBlockPatternsKey = Symbol( 'selectBlockPatternsKey' );
export const reusableBlocksSelectKey = Symbol( 'reusableBlocksSelect' );
export const userPatternCategoriesSelectKey = Symbol(
'userPatternCategoriesSelect'
);
export const sectionRootClientIdKey = Symbol( 'sectionRootClientIdKey' );
export const mediaEditKey = Symbol( 'mediaEditKey' );
export const getMediaSelectKey = Symbol( 'getMediaSelect' );
Expand Down
9 changes: 7 additions & 2 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { unlock } from '../lock-unlock';
import {
selectBlockPatternsKey,
reusableBlocksSelectKey,
userPatternCategoriesSelectKey,
sectionRootClientIdKey,
isIsolatedEditorKey,
} from './private-keys';
Expand Down Expand Up @@ -361,7 +362,9 @@ export const getPatternBySlug = createRegistrySelector( ( select ) =>

return mapUserPattern(
block,
state.settings.__experimentalUserPatternCategories
state.settings[ userPatternCategoriesSelectKey ]?.(
select
) ?? state.settings.__experimentalUserPatternCategories
);
}

Expand Down Expand Up @@ -393,7 +396,9 @@ export const getAllPatterns = createRegistrySelector( ( select ) =>
.map( ( userPattern ) =>
mapUserPattern(
userPattern,
state.settings.__experimentalUserPatternCategories
state.settings[ userPatternCategoriesSelectKey ]?.(
select
) ?? state.settings.__experimentalUserPatternCategories
)
),
// This setting is left for back compat.
Expand Down
8 changes: 6 additions & 2 deletions packages/block-editor/src/store/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { parse as grammarParse } from '@wordpress/block-serialization-default-pa
/**
* Internal dependencies
*/
import { selectBlockPatternsKey } from './private-keys';
import {
selectBlockPatternsKey,
userPatternCategoriesSelectKey,
} from './private-keys';
import { unlock } from '../lock-unlock';
import { STORE_NAME } from './constants';
import {
Expand Down Expand Up @@ -128,7 +131,8 @@ export const checkAllowListRecursive = ( blocks, allowedBlockTypes ) => {
export const getAllPatternsDependants = ( select ) => ( state ) => {
return [
state.settings.__experimentalBlockPatterns,
state.settings.__experimentalUserPatternCategories,
state.settings[ userPatternCategoriesSelectKey ]?.( select ) ??
state.settings.__experimentalUserPatternCategories,
state.settings.__experimentalReusableBlocks,
state.settings[ selectBlockPatternsKey ]?.( select ),
state.blockPatterns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function __experimentalReusableBlocksSelect( select ) {
} );
}

function __experimentalUserPatternCategoriesSelect( select ) {
return select( coreStore ).getUserPatternCategories();
}

const BLOCK_EDITOR_SETTINGS = [
'__experimentalBlockBindingsSupportedAttributes',
'__experimentalBlockDirectory',
Expand Down Expand Up @@ -103,6 +107,7 @@ const {
globalStylesLinksDataKey,
selectBlockPatternsKey,
reusableBlocksSelectKey,
userPatternCategoriesSelectKey,
sectionRootClientIdKey,
mediaEditKey,
getMediaSelectKey,
Expand Down Expand Up @@ -142,7 +147,6 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
userCanCreatePages,
pageOnFront,
pageForPosts,
userPatternCategories,
restBlockPatternCategories,
sectionRootClientId,
deviceType,
Expand All @@ -154,7 +158,6 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
canUser,
getRawEntityRecord,
getEntityRecord,
getUserPatternCategories,
getBlockPatternCategories,
} = select( coreStore );
const { get } = select( preferencesStore );
Expand Down Expand Up @@ -217,7 +220,6 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
} ),
pageOnFront: siteSettings?.page_on_front,
pageForPosts: siteSettings?.page_for_posts,
userPatternCategories: getUserPatternCategories(),
restBlockPatternCategories: getBlockPatternCategories(),
sectionRootClientId: getSectionRootBlock(),
deviceType: getDeviceType(),
Expand Down Expand Up @@ -370,8 +372,9 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
: undefined;
},
[ reusableBlocksSelectKey ]: __experimentalReusableBlocksSelect,
[ userPatternCategoriesSelectKey ]:
__experimentalUserPatternCategoriesSelect,
__experimentalBlockPatternCategories: blockPatternCategories,
__experimentalUserPatternCategories: userPatternCategories,
__experimentalFetchLinkSuggestions: ( search, searchOptions ) =>
fetchLinkSuggestions( search, searchOptions, settings ),
inserterMediaCategories,
Expand Down Expand Up @@ -435,7 +438,6 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
keepCaretInsideBlock,
settings,
hasUploadPermissions,
userPatternCategories,
blockPatterns,
blockPatternCategories,
canUseUnfilteredHTML,
Expand Down
1 change: 0 additions & 1 deletion test/e2e/specs/preload/post-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ test.describe( 'Preload', () => {
expect( Array.from( new Set( requests ) ).sort() ).toEqual(
[
`GET /wp/v2/comments?context=edit&post=${ postId }&type=note&status=all&per_page=100`,
'GET /wp/v2/wp_pattern_category?context=view&per_page=100&_fields=id%2Cname%2Cdescription%2Cslug',
`POST /wp/v2/posts/${ postId }`,
'POST /wp-sync/v1/updates',
'POST /wp/v2/users/me',
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/specs/preload/site-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ test.describe( 'Preload', () => {
expect( Array.from( new Set( requests ) ).sort() ).toEqual(
[
'GET /wp/v2/posts?context=edit&offset=0&order=desc&orderby=date&per_page=10&ignore_sticky=false',
'GET /wp/v2/taxonomies?context=view',
'GET /wp/v2/template-parts/emptytheme//header?context=edit',
'GET /wp/v2/wp_pattern_category?context=view&per_page=100&_fields=id%2Cname%2Cdescription%2Cslug',
'OPTIONS /wp/v2/settings',
'POST /wp/v2/users/me',
].sort()
Expand Down Expand Up @@ -87,13 +85,11 @@ test.describe( 'Preload', () => {
`GET /wp/v2/comments?context=edit&post=${ pageId }&type=note&status=all&per_page=100`,
`GET /wp/v2/pages/${ pageId }/autosaves?context=edit`,
'GET /wp/v2/taxonomies?context=edit',
'GET /wp/v2/taxonomies?context=view',
'GET /wp/v2/templates/lookup?slug=front-page',
'GET /wp/v2/types/page?context=edit',
'GET /wp/v2/users/1?context=view&_fields=id%2Cname',
'GET /wp/v2/users/me',
'GET /wp/v2/view-config?kind=postType&name=page',
'GET /wp/v2/wp_pattern_category?context=view&per_page=100&_fields=id%2Cname%2Cdescription%2Cslug',
'OPTIONS /wp/v2/settings',
'OPTIONS /wp/v2/templates',
'POST /wp/v2/users/me',
Expand Down
Loading