Skip to content

Commit

Permalink
Changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed Nov 29, 2023
1 parent aacb51e commit 2eefa36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
29 changes: 15 additions & 14 deletions packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 ) => {
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 2eefa36

Please sign in to comment.