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

Add "show template" to preview dropdown. #66514

Merged
merged 8 commits into from
Nov 5, 2024
Merged
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
11 changes: 10 additions & 1 deletion packages/editor/src/components/document-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
__unstableAnimatePresence as AnimatePresence,
} from '@wordpress/components';
import { BlockIcon } from '@wordpress/block-editor';
import { chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';
import { chevronLeftSmall, chevronRightSmall, layout } from '@wordpress/icons';
import { displayShortcut } from '@wordpress/keycodes';
import { store as coreStore } from '@wordpress/core-data';
import { store as commandsStore } from '@wordpress/commands';
Expand Down Expand Up @@ -58,12 +58,14 @@ export default function DocumentBar( props ) {
isNotFound,
templateTitle,
onNavigateToPreviousEntityRecord,
isTemplatePreview,
} = useSelect( ( select ) => {
const {
getCurrentPostType,
getCurrentPostId,
getEditorSettings,
__experimentalGetTemplateInfo: getTemplateInfo,
getRenderingMode,
} = select( editorStore );
const {
getEditedEntityRecord,
Expand Down Expand Up @@ -95,6 +97,7 @@ export default function DocumentBar( props ) {
templateTitle: _templateInfo.title,
onNavigateToPreviousEntityRecord:
getEditorSettings().onNavigateToPreviousEntityRecord,
isTemplatePreview: getRenderingMode() === 'template-locked',
};
}, [] );

Expand Down Expand Up @@ -143,6 +146,12 @@ export default function DocumentBar( props ) {
</MotionButton>
) }
</AnimatePresence>
{ ! isTemplate && isTemplatePreview && (
<BlockIcon
icon={ layout }
className="editor-document-bar__icon-layout"
/>
) }
{ isNotFound ? (
<Text>{ __( 'Document not found' ) }</Text>
) : (
Expand Down
13 changes: 13 additions & 0 deletions packages/editor/src/components/document-bar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,16 @@
background-color: transparent;
}
}

.editor-document-bar__icon-layout.editor-document-bar__icon-layout {
position: absolute;
margin-left: $grid-unit-15;
display: none;
pointer-events: none;
svg {
fill: $gray-600;
}
@include break-small {
display: flex;
}
}
61 changes: 45 additions & 16 deletions packages/editor/src/components/preview-dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Icon,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { desktop, mobile, tablet, external } from '@wordpress/icons';
import { desktop, mobile, tablet, external, check } from '@wordpress/icons';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as preferencesStore } from '@wordpress/preferences';
Expand All @@ -31,21 +31,32 @@ import PostPreviewButton from '../post-preview-button';
import { unlock } from '../../lock-unlock';

export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
const { deviceType, homeUrl, isTemplate, isViewable, showIconLabels } =
useSelect( ( select ) => {
const { getDeviceType, getCurrentPostType } = select( editorStore );
const { getEntityRecord, getPostType } = select( coreStore );
const { get } = select( preferencesStore );
const _currentPostType = getCurrentPostType();
return {
deviceType: getDeviceType(),
homeUrl: getEntityRecord( 'root', '__unstableBase' )?.home,
isTemplate: _currentPostType === 'wp_template',
isViewable: getPostType( _currentPostType )?.viewable ?? false,
showIconLabels: get( 'core', 'showIconLabels' ),
};
}, [] );
const { setDeviceType } = useDispatch( editorStore );
const {
deviceType,
homeUrl,
isTemplate,
isViewable,
showIconLabels,
isTemplateHidden,
templateId,
} = useSelect( ( select ) => {
const { getDeviceType, getCurrentPostType, getCurrentTemplateId } =
select( editorStore );
const { getRenderingMode } = unlock( select( editorStore ) );
const { getEntityRecord, getPostType } = select( coreStore );
const { get } = select( preferencesStore );
const _currentPostType = getCurrentPostType();
return {
deviceType: getDeviceType(),
homeUrl: getEntityRecord( 'root', '__unstableBase' )?.home,
isTemplate: _currentPostType === 'wp_template',
isViewable: getPostType( _currentPostType )?.viewable ?? false,
showIconLabels: get( 'core', 'showIconLabels' ),
isTemplateHidden: getRenderingMode() === 'post-only',
templateId: getCurrentTemplateId(),
};
}, [] );
const { setDeviceType, setRenderingMode } = useDispatch( editorStore );
const { resetZoomLevel } = unlock( useDispatch( blockEditorStore ) );

const handleDevicePreviewChange = ( newDeviceType ) => {
Expand Down Expand Up @@ -142,6 +153,24 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
</MenuItem>
</MenuGroup>
) }
{ ! isTemplate && !! templateId && (
<MenuGroup>
<MenuItem
icon={ ! isTemplateHidden ? check : undefined }
isSelected={ ! isTemplateHidden }
role="menuitemcheckbox"
onClick={ () => {
setRenderingMode(
isTemplateHidden
? 'template-locked'
: 'post-only'
);
} }
>
{ __( 'Show template' ) }
</MenuItem>
</MenuGroup>
) }
{ isViewable && (
<MenuGroup>
<PostPreviewButton
Expand Down
Loading