Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove isolated template editing actions in write mode #68258

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,24 @@ function ReusableBlockControl( {
handleEditOriginal,
resetContent,
} ) {
const canUserEdit = useSelect(
( select ) =>
!! select( coreStore ).canUser( 'update', {
kind: 'postType',
name: 'wp_block',
id: recordId,
} ),
const { canUserEdit, isNavigationMode } = useSelect(
( select ) => {
const { canUser } = select( coreStore );
return {
canUserEdit: !! canUser( 'update', {
kind: 'postType',
name: 'wp_block',
id: recordId,
} ),
isNavigationMode: select( blockEditorStore ).isNavigationMode(),
};
},
[ recordId ]
);

return (
<>
{ canUserEdit && !! handleEditOriginal && (
{ canUserEdit && ! isNavigationMode && !! handleEditOriginal && (
<BlockControls>
<ToolbarGroup>
<ToolbarButton onClick={ handleEditOriginal }>
Expand Down
9 changes: 8 additions & 1 deletion packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ export default function TemplatePartEdit( {
onNavigateToEntityRecord,
title,
canUserEdit,
isNavigationMode,
} = useSelect(
( select ) => {
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const { getBlockCount, getSettings } = select( blockEditorStore );
const {
getBlockCount,
getSettings,
isNavigationMode: _isNavigationMode,
} = select( blockEditorStore );

const getEntityArgs = [
'postType',
Expand Down Expand Up @@ -168,6 +173,7 @@ export default function TemplatePartEdit( {
getSettings().onNavigateToEntityRecord,
title: entityRecord?.title,
canUserEdit: !! _canUserEdit,
isNavigationMode: _isNavigationMode(),
};
},
[ templatePartId, attributes.area, clientId ]
Expand Down Expand Up @@ -236,6 +242,7 @@ export default function TemplatePartEdit( {
<>
<RecursionProvider uniqueId={ templatePartId }>
{ isEntityAvailable &&
! isNavigationMode &&
onNavigateToEntityRecord &&
canUserEdit && (
<BlockControls group="other">
Expand Down
17 changes: 13 additions & 4 deletions packages/block-library/src/template-part/edit/inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ function EditableTemplatePartInnerBlocks( {
tagName: TagName,
blockProps,
} ) {
const onNavigateToEntityRecord = useSelect(
( select ) =>
select( blockEditorStore ).getSettings().onNavigateToEntityRecord,
const { onNavigateToEntityRecord, isNavigationMode } = useSelect(
( select ) => {
const { getSettings, isNavigationMode: _isNavigationMode } =
select( blockEditorStore );
return {
onNavigateToEntityRecord:
getSettings().onNavigateToEntityRecord,
isNavigationMode: _isNavigationMode(),
};
},
[]
);

Expand All @@ -123,7 +130,9 @@ function EditableTemplatePartInnerBlocks( {
const blockEditingMode = useBlockEditingMode();

const customProps =
blockEditingMode === 'contentOnly' && onNavigateToEntityRecord
! isNavigationMode &&
blockEditingMode === 'contentOnly' &&
onNavigateToEntityRecord
? {
onDoubleClick: () =>
onNavigateToEntityRecord( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
Expand All @@ -27,34 +28,48 @@ import { store as editorStore } from '../../store';
* editor iframe canvas.
*/
export default function EditTemplateBlocksNotification( { contentRef } ) {
const { onNavigateToEntityRecord, templateId } = useSelect( ( select ) => {
const {
onNavigateToEntityRecord,
templateId,
canEditTemplate,
isNavigationMode,
} = useSelect( ( select ) => {
const { getEditorSettings, getCurrentTemplateId } =
select( editorStore );

return {
onNavigateToEntityRecord:
getEditorSettings().onNavigateToEntityRecord,
templateId: getCurrentTemplateId(),
};
}, [] );

const canEditTemplate = useSelect(
( select ) =>
!! select( coreStore ).canUser( 'create', {
canEditTemplate: !! select( coreStore ).canUser( 'create', {
kind: 'postType',
name: 'wp_template',
} ),
[]
isNavigationMode: select( blockEditorStore ).isNavigationMode(),
};
}, [] );

if ( ! canEditTemplate || isNavigationMode ) {
return null;
}

return (
<EditTemplateBlocksDialog
contentRef={ contentRef }
onNavigateToEntityRecord={ onNavigateToEntityRecord }
templateId={ templateId }
/>
);
}

function EditTemplateBlocksDialog( {
contentRef,
onNavigateToEntityRecord,
templateId,
} ) {
const [ isDialogOpen, setIsDialogOpen ] = useState( false );

useEffect( () => {
const handleDblClick = ( event ) => {
if ( ! canEditTemplate ) {
return;
}

if (
! event.target.classList.contains( 'is-root-container' ) ||
event.target.dataset?.type === 'core/template-part'
Expand All @@ -73,11 +88,7 @@ export default function EditTemplateBlocksNotification( { contentRef } ) {
return () => {
canvas?.removeEventListener( 'dblclick', handleDblClick );
};
}, [ contentRef, canEditTemplate ] );

if ( ! canEditTemplate ) {
return null;
}
}, [ contentRef ] );

return (
<ConfirmDialog
Expand Down
Loading