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

Hide the "View" button when previewing a theme #50986

Closed
Closed
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
71 changes: 41 additions & 30 deletions packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
useHasEditorCanvasContainer,
} from '../editor-canvas-container';
import { unlock } from '../../private-apis';
import { isPreviewingTheme } from '../../utils/is-previewing-theme';

const { useShouldContextualToolbarShow } = unlock( blockEditorPrivateApis );

Expand Down Expand Up @@ -258,37 +259,47 @@ export default function HeaderEditMode() {

<div className="edit-site-header-edit-mode__end">
<div className="edit-site-header-edit-mode__actions">
{ ! isFocusMode && hasDefaultEditorCanvasView && (
<div
className={ classnames(
'edit-site-header-edit-mode__preview-options',
{ 'is-zoomed-out': isZoomedOutView }
) }
>
<PreviewOptions
deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
/* translators: button label text should, if possible, be under 16 characters. */
viewLabel={ __( 'View' ) }
{ ! isFocusMode &&
/**
* This isPreviewingTheme() condition can be removed
* once the issues below are fixed
* and previewing the front of the site works well.
*
* https://github.com/WordPress/gutenberg/issues/50713
* https://github.com/WordPress/gutenberg/issues/50712
*/
! isPreviewingTheme() &&
hasDefaultEditorCanvasView && (
<div
className={ classnames(
'edit-site-header-edit-mode__preview-options',
{ 'is-zoomed-out': isZoomedOutView }
) }
>
<MenuGroup>
<MenuItem
href={ homeUrl }
target="_blank"
icon={ external }
>
{ __( 'View site' ) }
<VisuallyHidden as="span">
{
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
</VisuallyHidden>
</MenuItem>
</MenuGroup>
</PreviewOptions>
</div>
) }
<PreviewOptions
deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
/* translators: button label text should, if possible, be under 16 characters. */
viewLabel={ __( 'View' ) }
>
Comment on lines +279 to +284
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These preview options work on within the editor, so I think we should leave them as they are useful here.

<MenuGroup>
<MenuItem
href={ homeUrl }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding the isPreviewingTheme() check here and appending the ?theme_preview URL query would work well to resolve #50712. I think #50713 can be addressed later as a separate PR. The View and Previewing the site links are legitimately useful as is, even if the preview link isn't (yet) appended to all links on the site when previewing.

target="_blank"
icon={ external }
>
{ __( 'View site' ) }
<VisuallyHidden as="span">
{
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
</VisuallyHidden>
</MenuItem>
</MenuGroup>
</PreviewOptions>
</div>
) }
<SaveButton />
<PinnedItems.Slot scope="core/edit-site" />
<MoreMenu showIconLabels={ showIconLabels } />
Expand Down