Skip to content

Commit

Permalink
useBlockLock: Always check inherited 'templateLock' status (#40263)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Apr 14, 2022
1 parent 5424ec0 commit 89ed605
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/block-lock/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 );
Expand All @@ -44,6 +40,6 @@ export default function useBlockLock( clientId, checkParent = false ) {
isLocked: ! canEdit || ! canMove || ! canRemove,
};
},
[ clientId, checkParent ]
[ clientId ]
);
}

0 comments on commit 89ed605

Please sign in to comment.