Skip to content

Commit

Permalink
Fix: Calling select( 'core/edit-site' ).getCurrentTemplateTemplatePar…
Browse files Browse the repository at this point in the history
…ts() selector throws an error.
  • Loading branch information
jorgefilipecosta committed Jul 22, 2024
1 parent f130e99 commit 4cc89f8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/edit-site/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,20 @@ export function isSaveViewOpened( state ) {
/**
* Returns the template parts and their blocks for the current edited template.
*
* @deprecated
* @param {Object} state Global application state.
* @return {Array} Template parts and their blocks in an array.
*/
export const getCurrentTemplateTemplateParts = createRegistrySelector(
( select ) => () => {
deprecated(
`select( 'core/edit-site' ).getCurrentTemplateTemplateParts()`,
{
since: '6.7',
version: '6.9',
alternative: `select( 'core/block-editor' ).getBlocksByName( 'core/template-part' )`,
}
);
return unlock(
select( editorStore )
).getCurrentTemplateTemplateParts();
Expand Down
29 changes: 29 additions & 0 deletions packages/editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
__experimentalGetDefaultTemplatePartAreas,
} from './selectors';
import { getEntityActions as _getEntityActions } from '../dataviews/store/private-selectors';
import { getFilteredTemplatePartBlocks } from './utils/get-filtered-template-parts';
import { TEMPLATE_PART_POST_TYPE } from './constants';

const EMPTY_INSERTION_POINT = {
rootClientId: undefined,
Expand Down Expand Up @@ -160,3 +162,30 @@ export const hasPostMetaChanges = createRegistrySelector(
export function getEntityActions( state, ...args ) {
return _getEntityActions( state.dataviews, ...args );
}

/**
* Returns the template parts and their blocks for the current edited template.
* This selector is deprecated and not used on the codebase, was just kept because
* it is called inside select( 'core/edit-site' ).getCurrentTemplateTemplateParts()
* which is also deprecated.
*
* @deprecated
* @param {Object} state Global application state.
* @return {Array} Template parts and their blocks in an array.
*/
export const getCurrentTemplateTemplateParts = createRegistrySelector(
( select ) => () => {
const templateParts = select( coreStore ).getEntityRecords(
'postType',
TEMPLATE_PART_POST_TYPE,
{ per_page: -1 }
);

const clientIds =
select( blockEditorStore ).getBlocksByName( 'core/template-part' );
const blocks =
select( blockEditorStore ).getBlocksByClientId( clientIds );

return getFilteredTemplatePartBlocks( blocks, templateParts );
}
);

0 comments on commit 4cc89f8

Please sign in to comment.