From 2eefa3691026129d46a0f540141cd8ecc3cd3112 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 29 Nov 2023 21:44:46 +1300 Subject: [PATCH] Changes from code review --- packages/block-library/src/block/edit.js | 29 ++++++++++--------- .../document-actions/index.js | 11 ++++--- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index 899147508228a..9bcd39d4e0b04 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -27,7 +27,7 @@ import { Warning, privateApis as blockEditorPrivateApis, BlockControls, - store as editorStore, + store as blockEditorStore, } from '@wordpress/block-editor'; import { useRef, useMemo, useEffect } from '@wordpress/element'; import { useSelect, useDispatch } from '@wordpress/data'; @@ -50,12 +50,14 @@ function isPartiallySynced( block ) { ); } -function setBlockEditMode( setEditMode, block ) { - const editMode = isPartiallySynced( block ) ? 'contentOnly' : 'disabled'; - setEditMode( block.clientId, editMode ); - block.innerBlocks.forEach( ( innerBlock ) => - setBlockEditMode( setEditMode, innerBlock ) - ); +function setBlockEditMode( setEditMode, blocks ) { + blocks.forEach( ( block ) => { + const editMode = isPartiallySynced( block ) + ? 'contentOnly' + : 'disabled'; + setEditMode( block.clientId, editMode ); + setBlockEditMode( setEditMode, block.innerBlocks ); + } ); } const useInferredLayout = ( blocks, parentLayout ) => { @@ -94,11 +96,11 @@ export default function ReusableBlockEdit( { context: { postId }, clientId: patternClientId, } ) { - const { setBlockEditingMode } = useDispatch( editorStore ); + const { setBlockEditingMode } = useDispatch( blockEditorStore ); const { editUrl, innerBlocks, userCanEdit } = useSelect( ( select ) => { const { canUser } = select( coreStore ); - const { getSettings, getBlocks } = select( editorStore ); + const { getSettings, getBlocks } = select( blockEditorStore ); const blocks = getBlocks( patternClientId ); const isBlockTheme = getSettings().__unstableIsBlockBasedTheme; const canEdit = canUser( 'update', 'blocks', ref ); @@ -127,11 +129,10 @@ export default function ReusableBlockEdit( { [ patternClientId, postId, ref ] ); - useEffect( () => { - innerBlocks.forEach( ( block ) => - setBlockEditMode( setBlockEditingMode, block ) - ); - }, [ innerBlocks, setBlockEditingMode ] ); + useEffect( + () => setBlockEditMode( setBlockEditingMode, innerBlocks ), + [ innerBlocks, setBlockEditingMode ] + ); const hasAlreadyRendered = useHasRecursion( ref ); const { record, hasResolved } = useEntityRecord( diff --git a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js index e9960657053a1..eca5abb729be6 100644 --- a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js +++ b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js @@ -27,7 +27,7 @@ import { displayShortcut } from '@wordpress/keycodes'; import { store as coreStore } from '@wordpress/core-data'; import { store as editorStore } from '@wordpress/editor'; import { useRef, useState, useEffect } from '@wordpress/element'; -import { getQueryArgs } from '@wordpress/url'; +import { getQueryArgs, addQueryArgs } from '@wordpress/url'; /** * Internal dependencies @@ -147,9 +147,12 @@ function TemplateDocumentActions( { className, onBack } ) { const { refererId } = getQueryArgs( window.location.href ); - if ( ! onBack && refererId ) { - onBack = () => - ( document.location = `post.php?post=${ refererId }&action=edit` ); + if ( ! onBack && ! isNaN( refererId ) ) { + const url = addQueryArgs( 'post.php', { + action: 'edit', + post: refererId, + } ); + onBack = () => ( document.location = url ); } return (