From 89ed605383a568d0e975dbde375a455adb462964 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 14 Apr 2022 09:21:26 +0400 Subject: [PATCH] useBlockLock: Always check inherited 'templateLock' status (#40263) --- .../src/components/block-lock/menu-item.js | 2 +- .../block-editor/src/components/block-lock/modal.js | 2 +- .../src/components/block-lock/use-block-lock.js | 12 ++++-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/block-editor/src/components/block-lock/menu-item.js b/packages/block-editor/src/components/block-lock/menu-item.js index 6a7a1517cf409..665d9bfbc91a4 100644 --- a/packages/block-editor/src/components/block-lock/menu-item.js +++ b/packages/block-editor/src/components/block-lock/menu-item.js @@ -13,7 +13,7 @@ import useBlockLock from './use-block-lock'; import BlockLockModal from './modal'; export default function BlockLockMenuItem( { clientId } ) { - const { canLock, isLocked } = useBlockLock( clientId, true ); + const { canLock, isLocked } = useBlockLock( clientId ); const [ isModalOpen, toggleModal ] = useReducer( ( isActive ) => ! isActive, diff --git a/packages/block-editor/src/components/block-lock/modal.js b/packages/block-editor/src/components/block-lock/modal.js index 311254d9c3e75..0efb69b5bda0e 100644 --- a/packages/block-editor/src/components/block-lock/modal.js +++ b/packages/block-editor/src/components/block-lock/modal.js @@ -25,7 +25,7 @@ import { store as blockEditorStore } from '../../store'; export default function BlockLockModal( { clientId, onClose } ) { const [ lock, setLock ] = useState( { move: false, remove: false } ); - const { canEdit, canMove, canRemove } = useBlockLock( clientId, true ); + const { canEdit, canMove, canRemove } = useBlockLock( clientId ); const { isReusable } = useSelect( ( select ) => { const { getBlockName } = select( blockEditorStore ); diff --git a/packages/block-editor/src/components/block-lock/use-block-lock.js b/packages/block-editor/src/components/block-lock/use-block-lock.js index 6d4d7d8e86095..ced310ebf5404 100644 --- a/packages/block-editor/src/components/block-lock/use-block-lock.js +++ b/packages/block-editor/src/components/block-lock/use-block-lock.js @@ -11,13 +11,11 @@ import { store as blockEditorStore } from '../../store'; /** * Return details about the block lock status. * - * @param {string} clientId The block client Id. - * @param {boolean} checkParent Optional. The status is derived from the parent `templateLock` - * when the current block's lock state isn't defined. + * @param {string} clientId The block client Id. * * @return {Object} Block lock status */ -export default function useBlockLock( clientId, checkParent = false ) { +export default function useBlockLock( clientId ) { return useSelect( ( select ) => { const { @@ -28,9 +26,7 @@ export default function useBlockLock( clientId, checkParent = false ) { getBlockName, getBlockRootClientId, } = select( blockEditorStore ); - const rootClientId = checkParent - ? getBlockRootClientId( clientId ) - : null; + const rootClientId = getBlockRootClientId( clientId ); const canEdit = canEditBlock( clientId ); const canMove = canMoveBlock( clientId, rootClientId ); @@ -44,6 +40,6 @@ export default function useBlockLock( clientId, checkParent = false ) { isLocked: ! canEdit || ! canMove || ! canRemove, }; }, - [ clientId, checkParent ] + [ clientId ] ); }