Skip to content

Commit

Permalink
Update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Apr 3, 2022
1 parent 99e0bde commit 6057b86
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function BlockContentOverlay( {
useEffect( () => {
// The overlay is always active when editing is locked.
if ( ! canEdit ) {
setIsOverlayActive( true );
return;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/block-lock/menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function BlockLockMenuItem( { clientId } ) {
const { canLockBlock, isLocked } = useSelect(
( select ) => {
const {
canEditBlock,
canMoveBlock,
canRemoveBlock,
canLockBlockType,
Expand All @@ -29,7 +30,8 @@ export default function BlockLockMenuItem( { clientId } ) {
canLockBlock: canLockBlockType( getBlockName( clientId ) ),
isLocked:
! canMoveBlock( clientId, rootClientId ) ||
! canRemoveBlock( clientId, rootClientId ),
! canRemoveBlock( clientId, rootClientId ) ||
! canEditBlock( clientId ),
};
},
[ clientId ]
Expand Down
39 changes: 35 additions & 4 deletions packages/block-editor/src/components/block-lock/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
Icon,
Modal,
} from '@wordpress/components';
import { dragHandle, trash } from '@wordpress/icons';
import { edit as editIcon, dragHandle, trash } from '@wordpress/icons';
import { useInstanceId } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { isReusableBlock, getBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -22,19 +23,28 @@ import useBlockDisplayInformation from '../use-block-display-information';
import { store as blockEditorStore } from '../../store';

export default function BlockLockModal( { clientId, onClose } ) {
const [ lock, setLock ] = useState( { move: false, remove: false } );
const { canMove, canRemove } = useSelect(
const [ lock, setLock ] = useState( {
edit: false,
move: false,
remove: false,
} );
const { canEdit, canMove, canRemove, isReusable } = useSelect(
( select ) => {
const {
canEditBlock,
canMoveBlock,
canRemoveBlock,
getBlockName,
getBlockRootClientId,
} = select( blockEditorStore );
const rootClientId = getBlockRootClientId( clientId );
const blockName = getBlockName( clientId );

return {
canEdit: canEditBlock( clientId ),
canMove: canMoveBlock( clientId, rootClientId ),
canRemove: canRemoveBlock( clientId, rootClientId ),
isReusable: isReusableBlock( getBlockType( blockName ) ),
};
},
[ clientId ]
Expand All @@ -48,10 +58,11 @@ export default function BlockLockModal( { clientId, onClose } ) {

useEffect( () => {
setLock( {
edit: ! canEdit,
move: ! canMove,
remove: ! canRemove,
} );
}, [ canMove, canRemove ] );
}, [ canEdit, canMove, canRemove ] );

const isAllChecked = Object.values( lock ).every( Boolean );

Expand Down Expand Up @@ -101,12 +112,32 @@ export default function BlockLockModal( { clientId, onClose } ) {
aria-checked={ ariaChecked }
onChange={ ( newValue ) =>
setLock( {
edit: isReusable ? newValue : undefined,
move: newValue,
remove: newValue,
} )
}
/>
<ul className="block-editor-block-lock-modal__checklist">
{ isReusable && (
<li className="block-editor-block-lock-modal__checklist-item">
<CheckboxControl
label={
<>
{ __( 'Restrict editing' ) }
<Icon icon={ editIcon } />
</>
}
checked={ lock.edit }
onChange={ ( edit ) =>
setLock( ( prevLock ) => ( {
...prevLock,
edit,
} ) )
}
/>
</li>
) }
<li className="block-editor-block-lock-modal__checklist-item">
<CheckboxControl
label={
Expand Down
6 changes: 4 additions & 2 deletions packages/block-editor/src/components/block-lock/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import { store as blockEditorStore } from '../../store';

export default function BlockLockToolbar( { clientId } ) {
const blockInformation = useBlockDisplayInformation( clientId );
const { canMove, canRemove, canLockBlock } = useSelect(
const { canEdit, canMove, canRemove, canLockBlock } = useSelect(
( select ) => {
const {
canEditBlock,
canMoveBlock,
canRemoveBlock,
canLockBlockType,
getBlockName,
} = select( blockEditorStore );

return {
canEdit: canEditBlock( clientId ),
canMove: canMoveBlock( clientId ),
canRemove: canRemoveBlock( clientId ),
canLockBlock: canLockBlockType( getBlockName( clientId ) ),
Expand All @@ -43,7 +45,7 @@ export default function BlockLockToolbar( { clientId } ) {
return null;
}

if ( canMove && canRemove ) {
if ( canEdit && canMove && canRemove ) {
return null;
}

Expand Down

0 comments on commit 6057b86

Please sign in to comment.