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 a 'View Site' link in the site editor #42331

Merged
merged 12 commits into from
Jul 28, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export default function PreviewOptions( {
className: 'block-editor-post-preview__button-toggle',
disabled: ! isEnabled,
/* translators: button label text should, if possible, be under 16 characters. */
children: __( 'Preview' ),
children: __( 'View' ),
};
const menuProps = {
'aria-label': __( 'Preview options' ),
'aria-label': __( 'View options' ),
};
return (
<DropdownMenu
Expand Down
4 changes: 1 addition & 3 deletions packages/e2e-test-utils-playwright/src/editor/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export async function openPreviewPage( this: Editor ): Promise< Page > {
const editorTopBar = this.page.locator(
'role=region[name="Editor top bar"i]'
);
const previewButton = editorTopBar.locator(
'role=button[name="Preview"i]'
);
const previewButton = editorTopBar.locator( 'role=button[name="View"i]' );
await previewButton.click();

const [ previewPage ] = await Promise.all( [
Expand Down
31 changes: 28 additions & 3 deletions packages/edit-site/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ import {
import { useSelect, useDispatch } from '@wordpress/data';
import { PinnedItems } from '@wordpress/interface';
import { _x, __ } from '@wordpress/i18n';
import { listView, plus } from '@wordpress/icons';
import { Button, ToolbarItem } from '@wordpress/components';
import { listView, plus, external } from '@wordpress/icons';
import {
Button,
ToolbarItem,
MenuGroup,
MenuItem,
VisuallyHidden,
} from '@wordpress/components';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { store as editorStore } from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -48,6 +54,7 @@ export default function Header( {
listViewShortcut,
isLoaded,
isVisualMode,
settings,
} = useSelect( ( select ) => {
const {
__experimentalGetPreviewDeviceType,
Expand All @@ -56,6 +63,7 @@ export default function Header( {
isInserterOpened,
isListViewOpened,
getEditorMode,
getSettings,
} = select( editSiteStore );
const { getEditedEntityRecord } = select( coreStore );
const { __experimentalGetTemplateInfo: getTemplateInfo } =
Expand All @@ -79,6 +87,7 @@ export default function Header( {
'core/edit-site/toggle-list-view'
),
isVisualMode: getEditorMode() === 'visual',
settings: getSettings(),
};
}, [] );

Expand Down Expand Up @@ -200,7 +209,23 @@ export default function Header( {
<PreviewOptions
deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
/>
>
<MenuGroup>
<MenuItem
href={ settings?.siteUrl }
target="_blank"
icon={ external }
>
{ __( 'View site' ) }
<VisuallyHidden as="span">
{
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
</VisuallyHidden>
</MenuItem>
</MenuGroup>
</PreviewOptions>
) }
<SaveButton
openEntitiesSavedStates={ openEntitiesSavedStates }
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/editor/various/new-post.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ test.describe( 'new editor state', () => {
await expect( title ).toBeEditable();
await expect( title ).toHaveText( '' );

// Should display the Preview button.
// Should display the View button.
await expect(
page.locator( 'role=button[name="Preview"i]' )
page.locator( 'role=button[name="View"i]' )
).toBeVisible();

// Should display the Post Formats UI.
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/specs/editor/various/preview.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test.describe( 'Preview', () => {

// Disabled until content present.
await expect(
editorPage.locator( 'role=button[name="Preview"i]' )
editorPage.locator( 'role=button[name="View"i]' )
).toBeDisabled();

await editorPage.type(
Expand Down Expand Up @@ -275,8 +275,8 @@ test.describe( 'Preview with private custom post type', () => {
} ) => {
await admin.createNewPost( { postType: 'not_public', title: 'aaaaa' } );

// Open the preview menu.
await page.click( 'role=button[name="Preview"i]' );
// Open the view menu.
await page.click( 'role=button[name="View"i]' );

await expect(
page.locator( 'role=menuitem[name="Preview in new tab"i]' )
Expand All @@ -291,7 +291,7 @@ class PreviewUtils {

async waitForPreviewNavigation( previewPage ) {
const previewToggle = this.page.locator(
'role=button[name="Preview"i][expanded=false]'
'role=button[name="View"i][expanded=false]'
);
const isDropdownClosed = await previewToggle.isVisible();
if ( isDropdownClosed ) {
Expand Down