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 nested level when selecting templates or template parts #47777

Merged
merged 16 commits into from
Feb 13, 2023
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
27 changes: 27 additions & 0 deletions lib/compat/wordpress-6.3/site-editor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Overrides the site editor initialization for WordPress 6.3.
*
* @package gutenberg
*/

/**
* Overrides the site editor initialization for WordPress 6.3 and cancels the redirection.
* The logic of this function is not important, we just need to remove the redirection from core.
*
* @param string $location Location.
*
* @return string Updated location.
*/
function gutenberg_prevent_site_editor_redirection( $location ) {
if ( strpos( $location, 'site-editor.php' ) !== false && strpos( $location, '?' ) !== false ) {
return add_query_arg(
array( 'postId' => 'none' ),
admin_url( 'site-editor.php' )
);
}

return $location;
}

add_filter( 'wp_redirect', 'gutenberg_prevent_site_editor_redirection', 1 );
3 changes: 3 additions & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.2/html-api/class-wp-html-tag-processor.php';
}

// WordPress 6.3 compat.
require __DIR__ . '/compat/wordpress-6.3/site-editor.php';

// Experimental features.
remove_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); // Turns off WP 6.0's stopgap handler for Webfonts API.
require __DIR__ . '/experimental/block-editor-settings-mobile.php';
Expand Down
1 change: 0 additions & 1 deletion packages/e2e-test-utils-playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export { Admin } from './admin';
export { Editor } from './editor';
export { PageUtils } from './page-utils';
export { RequestUtils } from './request-utils';
export { SiteEditor } from './site-editor';
export { test, expect } from './test';
23 changes: 0 additions & 23 deletions packages/e2e-test-utils-playwright/src/site-editor/index.ts

This file was deleted.

This file was deleted.

6 changes: 1 addition & 5 deletions packages/e2e-test-utils-playwright/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ConsoleMessage } from '@playwright/test';
/**
* Internal dependencies
*/
import { Admin, Editor, PageUtils, RequestUtils, SiteEditor } from './index';
import { Admin, Editor, PageUtils, RequestUtils } from './index';

const STORAGE_STATE_PATH =
process.env.STORAGE_STATE_PATH ||
Expand Down Expand Up @@ -102,7 +102,6 @@ const test = base.extend<
editor: Editor;
pageUtils: PageUtils;
snapshotConfig: void;
siteEditor: SiteEditor;
},
{
requestUtils: RequestUtils;
Expand All @@ -114,9 +113,6 @@ const test = base.extend<
editor: async ( { page }, use ) => {
await use( new Editor( { page } ) );
},
siteEditor: async ( { page }, use ) => {
await use( new SiteEditor( { page } ) );
},
page: async ( { page }, use ) => {
page.on( 'console', observeConsoleLogging );

Expand Down
10 changes: 6 additions & 4 deletions packages/e2e-test-utils/src/site-editor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { visitAdminPage } from '@wordpress/e2e-test-utils';
import { canvas, visitAdminPage } from '@wordpress/e2e-test-utils';
import { addQueryArgs } from '@wordpress/url';

/**
Expand Down Expand Up @@ -166,11 +166,13 @@ export async function openPreviousGlobalStylesPanel() {
* Enters edit mode.
*/
export async function enterEditMode() {
const editSiteToggle = await page.$( '.edit-site-site-hub__edit-button' );
const isViewMode = await page.$(
'.edit-site-visual-editor__editor-canvas[role="button"]'
);
// This check is necessary for the performance tests in old branches
// where the site editor toggle was not implemented yet.
if ( ! editSiteToggle ) {
if ( ! isViewMode ) {
return;
}
await page.click( '.edit-site-site-hub__edit-button' );
await canvas().click( 'body' );
}
6 changes: 5 additions & 1 deletion packages/e2e-tests/specs/performance/site-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ describe( 'Site Editor Performance', () => {
} );

beforeEach( async () => {
await visitSiteEditor( { postId: id, postType: 'page' } );
await visitSiteEditor( {
postId: id,
postType: 'page',
path: '/navigation/single',
} );
} );

it( 'Loading', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ describe( 'Multi-entity save flow', () => {
await visitSiteEditor( {
postId: 'emptytheme//index',
postType: 'wp_template',
path: '/templates/single',
} );

await enterEditMode();
Expand Down Expand Up @@ -304,6 +305,7 @@ describe( 'Multi-entity save flow', () => {
await visitSiteEditor( {
postId: 'emptytheme//index',
postType: 'wp_template',
path: '/templates/single',
} );

await enterEditMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe( 'Settings sidebar', () => {
await visitSiteEditor( {
postId: 'emptytheme//singular',
postType: 'wp_template',
path: '/templates/single',
} );
await enterEditMode();
const templateCardAfterNavigation = await getTemplateCard();
Expand Down
81 changes: 34 additions & 47 deletions packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
useResizeObserver,
} from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { useState, useEffect, useRef } from '@wordpress/element';
import { useState, useRef } from '@wordpress/element';
import { NavigableRegion } from '@wordpress/interface';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

Expand Down Expand Up @@ -87,21 +87,20 @@ export default function Layout() {
} );
const disableMotion = useReducedMotion();
const isMobileViewport = useViewportMatch( 'medium', '<' );
const [ isMobileCanvasVisible, setIsMobileCanvasVisible ] =
useState( false );
const canvasPadding = isMobileViewport ? 0 : 24;
const showSidebar =
( isMobileViewport && ! isMobileCanvasVisible ) ||
( isMobileViewport && ! isListPage ) ||
( ! isMobileViewport && ( canvasMode === 'view' || ! isEditorPage ) );
const showCanvas =
( isMobileViewport && isMobileCanvasVisible ) || ! isMobileViewport;
( isMobileViewport && isEditorPage && canvasMode === 'edit' ) ||
! isMobileViewport ||
! isEditorPage;
const showFrame =
! isEditorPage || ( canvasMode === 'view' && ! isMobileViewport );

( ! isEditorPage && ! isMobileViewport ) ||
( ! isMobileViewport && isEditorPage && canvasMode === 'view' );
const isFullCanvas =
( isEditorPage && canvasMode === 'edit' && ! isMobileViewport ) ||
isMobileCanvasVisible;
// Ideally this effect could be removed if we move the "isMobileCanvasVisible" into the store.
( isMobileViewport && isListPage ) ||
( isEditorPage && canvasMode === 'edit' );
const [ canvasResizer, canvasSize ] = useResizeObserver();
const [ fullResizer, fullSize ] = useResizeObserver();
const [ forcedWidth, setForcedWidth ] = useState( null );
Expand All @@ -112,15 +111,6 @@ export default function Layout() {
if ( showFrame && ! isResizing ) {
canvasWidth = canvasSize.width - canvasPadding;
}
useEffect( () => {
if ( canvasMode === 'view' && isMobileViewport ) {
setIsMobileCanvasVisible( false );
}

if ( canvasMode === 'edit' && isMobileViewport ) {
setIsMobileCanvasVisible( true );
}
}, [ canvasMode, isMobileViewport ] );

// Synchronizing the URL with the store value of canvasMode happens in an effect
// This condition ensures the component is only rendered after the synchronization happens
Expand Down Expand Up @@ -153,37 +143,34 @@ export default function Layout() {
? forcedWidth - 48
: undefined,
} }
isMobileCanvasVisible={ isMobileCanvasVisible }
setIsMobileCanvasVisible={ setIsMobileCanvasVisible }
/>

<AnimatePresence initial={ false }>
{ isEditorPage &&
( canvasMode === 'edit' || isMobileCanvasVisible ) && (
<NavigableRegion
className="edit-site-layout__header"
ariaLabel={ __( 'Editor top bar' ) }
as={ motion.div }
animate={ {
y: 0,
} }
initial={ {
y: '-100%',
} }
exit={ {
y: '-100%',
} }
transition={ {
type: 'tween',
duration: disableMotion
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
>
{ canvasMode === 'edit' && <Header /> }
</NavigableRegion>
) }
{ isEditorPage && canvasMode === 'edit' && (
<NavigableRegion
className="edit-site-layout__header"
ariaLabel={ __( 'Editor top bar' ) }
as={ motion.div }
animate={ {
y: 0,
} }
initial={ {
y: '-100%',
} }
exit={ {
y: '-100%',
} }
transition={ {
type: 'tween',
duration: disableMotion
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
>
{ canvasMode === 'edit' && <Header /> }
</NavigableRegion>
) }
</AnimatePresence>

<div className="edit-site-layout__content">
Expand Down
34 changes: 11 additions & 23 deletions packages/edit-site/src/components/layout/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
$hub-height: $grid-unit-20 * 2 + $button-size;

.edit-site-layout {
height: 100%;
background: $gray-900;
Expand All @@ -10,24 +8,23 @@ $hub-height: $grid-unit-20 * 2 + $button-size;

.edit-site-layout__hub {
position: fixed;
top: $canvas-padding;
left: $canvas-padding;
top: 0;
left: 0;
width: calc(100vw - #{$canvas-padding * 2});
height: $hub-height;
height: $header-height;
z-index: z-index(".edit-site-layout__hub");

background: $black;
padding: $grid-unit-20;
padding-left: 0;
border-radius: $radius-block-ui * 4;
box-shadow: $shadow-modal;
.edit-site-layout.is-full-canvas.is-edit-mode & {
width: auto;
padding-right: 0;
}

@include break-medium {
width: calc(#{$nav-sidebar-width} - #{$canvas-padding * 2});
}

.edit-site-layout.is-full-canvas & {
top: 0;
left: 0;
padding: 0;
padding-right: $grid-unit-20;
height: $header-height;
border-radius: 0;
width: 100vw;
box-shadow: none;
Expand All @@ -37,15 +34,6 @@ $hub-height: $grid-unit-20 * 2 + $button-size;
padding-right: 0;
}
}

.edit-site-layout.is-full-canvas.is-edit-mode & {
width: auto;
padding-right: 0;
}

@include break-medium {
width: calc(#{$nav-sidebar-width} - #{$canvas-padding * 2});
}
}

.edit-site-layout__header {
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-site/src/components/list/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export default function Table( { templateType } ) {
<Heading level={ 4 }>
<Link
params={ {
path:
template.type === 'wp_template'
? '/templates/single'
: '/template-parts/single',
postId: template.id,
postType: template.type,
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default function SidebarNavigationScreenNavigationMenus() {
return (
<SidebarNavigationScreen
path="/navigation"
parentTitle={ __( 'Design' ) }
title={ __( 'Navigation' ) }
content={
<div className="edit-site-sidebar-navigation-screen-navigation-menus">
Expand Down
Loading