Skip to content

Commit

Permalink
Refactor the site editor URLs for better backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Feb 15, 2023
1 parent 3bcfbfe commit 558a900
Show file tree
Hide file tree
Showing 23 changed files with 206 additions and 177 deletions.
1 change: 0 additions & 1 deletion packages/e2e-tests/specs/performance/site-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ describe( 'Site Editor Performance', () => {
await visitSiteEditor( {
postId: id,
postType: 'page',
path: '/navigation/single',
} );
} );

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

await enterEditMode();
Expand Down Expand Up @@ -305,7 +304,6 @@ 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,7 +69,6 @@ describe( 'Settings sidebar', () => {
await visitSiteEditor( {
postId: 'emptytheme//singular',
postType: 'wp_template',
path: '/templates/single',
} );
await enterEditMode();
const templateCardAfterNavigation = await getTemplateCard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ export default function NewTemplatePart( {
setCanvasMode( 'edit' );

// Navigate to the created template part editor.
window.queueMicrotask( () => {
history.push( {
postId: templatePart.id,
postType: 'wp_template_part',
path: '/template-parts/single',
} );
history.push( {
postId: templatePart.id,
postType: 'wp_template_part',
} );

// TODO: Add a success notice?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,9 @@ export default function NewTemplate( {
setCanvasMode( 'edit' );

// Navigate to the created template editor.
window.queueMicrotask( () => {
history.push( {
postId: newTemplate.id,
postType: newTemplate.type,
path: '/templates/single',
} );
history.push( {
postId: newTemplate.id,
postType: newTemplate.type,
} );

createSuccessNotice(
Expand Down
4 changes: 0 additions & 4 deletions packages/edit-site/src/components/list/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ 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 @@ -29,7 +29,7 @@ export default function SidebarNavigationScreenMain() {

return (
<SidebarNavigationScreen
path="/"
isRoot
title={ __( 'Design' ) }
content={
<ItemGroup>
Expand All @@ -45,15 +45,15 @@ export default function SidebarNavigationScreenMain() {
) }
<NavigatorButton
as={ SidebarNavigationItem }
path="/templates"
path="/wp_template"
withChevron
icon={ layout }
>
{ __( 'Templates' ) }
</NavigatorButton>
<NavigatorButton
as={ SidebarNavigationItem }
path="/template-parts"
path="/wp_template_part"
withChevron
icon={ symbolFilled }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*/
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import { Button } from '@wordpress/components';
import {
Button,
__experimentalUseNavigator as useNavigator,
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

Expand All @@ -16,25 +19,28 @@ import { store as editSiteStore } from '../../store';

export default function SidebarNavigationScreenNavigationItem() {
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
const {
params: { postType, postId },
} = useNavigator();

const { post } = useSelect( ( select ) => {
const { getEditedPostContext } = select( editSiteStore );
const { getEntityRecord } = select( coreStore );
const { postType, postId } = getEditedPostContext() ?? {};
const { post } = useSelect(
( select ) => {
const { getEntityRecord } = select( coreStore );

// The currently selected entity to display.
// Typically template or template part in the site editor.
return {
post:
postId && postType
? getEntityRecord( 'postType', postType, postId )
: null,
};
}, [] );
// The currently selected entity to display.
// Typically template or template part in the site editor.
return {
post:
postId && postType
? getEntityRecord( 'postType', postType, postId )
: null,
};
},
[ postType, postId ]
);

return (
<SidebarNavigationScreen
path="/navigation/single"
title={ post ? decodeEntities( post?.title?.rendered ) : null }
actions={
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ export default function SidebarNavigationScreenNavigationMenus() {
history.push( {
postType: attributes.type,
postId: attributes.id,
path: '/navigation/single',
} );
}
},
[ history ]
);
return (
<SidebarNavigationScreen
path="/navigation"
title={ __( 'Navigation' ) }
content={
<div className="edit-site-sidebar-navigation-screen-navigation-menus">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@ import useEditedEntityRecord from '../use-edited-entity-record';
import { unlock } from '../../private-apis';
import { store as editSiteStore } from '../../store';

const config = {
wp_template: {
path: '/templates/single',
},
wp_template_part: {
path: '/template-parts/single',
},
};

export default function SidebarNavigationScreenTemplate( {
postType = 'wp_template',
} ) {
export default function SidebarNavigationScreenTemplate() {
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
const { getDescription, getTitle, record } = useEditedEntityRecord();
let description = getDescription();
Expand All @@ -36,7 +25,6 @@ export default function SidebarNavigationScreenTemplate( {

return (
<SidebarNavigationScreen
path={ config[ postType ].path }
title={ getTitle() }
actions={
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __experimentalUseNavigator as useNavigator } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -10,22 +11,16 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';

const config = {
wp_template: {
path: '/templates/all',
title: __( 'All templates' ),
},
wp_template_part: {
path: '/template-parts/all',
title: __( 'All template parts' ),
},
};

export default function SidebarNavigationScreenTemplatesBrowse( {
postType = 'wp_template',
} ) {
return (
<SidebarNavigationScreen
path={ config[ postType ].path }
title={ config[ postType ].title }
/>
);
export default function SidebarNavigationScreenTemplatesBrowse() {
const {
params: { postType },
} = useNavigator();
return <SidebarNavigationScreen title={ config[ postType ].title } />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
__experimentalUseNavigator as useNavigator,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useEntityRecords } from '@wordpress/core-data';
Expand All @@ -20,7 +21,6 @@ import AddNewTemplate from '../add-new-template';

const config = {
wp_template: {
path: '/templates',
labels: {
title: __( 'Templates' ),
loading: __( 'Loading templates' ),
Expand All @@ -29,7 +29,6 @@ const config = {
},
},
wp_template_part: {
path: '/template-parts',
labels: {
title: __( 'Template parts' ),
loading: __( 'Loading template parts' ),
Expand All @@ -43,14 +42,14 @@ const TemplateItem = ( { postType, postId, ...props } ) => {
const linkInfo = useLink( {
postType,
postId,
path: config[ postType ].path + '/single',
} );
return <SidebarNavigationItem { ...linkInfo } { ...props } />;
};

export default function SidebarNavigationScreenTemplates( {
postType = 'wp_template',
} ) {
export default function SidebarNavigationScreenTemplates() {
const {
params: { postType },
} = useNavigator();
const isMobileViewport = useViewportMatch( 'medium', '<' );

const { records: templates, isResolving: isLoading } = useEntityRecords(
Expand All @@ -62,14 +61,11 @@ export default function SidebarNavigationScreenTemplates( {
);

const browseAllLink = useLink( {
postType,
postId: undefined,
path: config[ postType ].path + '/all',
path: '/' + postType + '/all',
} );

return (
<SidebarNavigationScreen
path={ config[ postType ].path }
title={ config[ postType ].labels.title }
actions={
! isMobileViewport && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
__experimentalVStack as VStack,
__experimentalNavigatorToParentButton as NavigatorToParentButton,
Button,
__experimentalNavigatorScreen as NavigatorScreen,
} from '@wordpress/components';
import { isRTL, __ } from '@wordpress/i18n';
import { chevronRight, chevronLeft } from '@wordpress/icons';
Expand All @@ -19,7 +18,7 @@ import { store as editSiteStore } from '../../store';
import { unlock } from '../../private-apis';

export default function SidebarNavigationScreen( {
path,
isRoot,
title,
actions,
content,
Expand All @@ -32,41 +31,36 @@ export default function SidebarNavigationScreen( {
}, [] );

return (
<NavigatorScreen
className="edit-site-sidebar-navigation-screen"
path={ path }
>
<VStack spacing={ 2 }>
<HStack
spacing={ 4 }
justify="flex-start"
className="edit-site-sidebar-navigation-screen__title-icon"
>
{ path !== '/' ? (
<NavigatorToParentButton
className="edit-site-sidebar-navigation-screen__back"
icon={ isRTL() ? chevronRight : chevronLeft }
aria-label={ __( 'Back' ) }
/>
) : (
<Button
className="edit-site-sidebar-navigation-screen__back"
icon={ isRTL() ? chevronRight : chevronLeft }
aria-label={ __( 'Navigate to the Dashboard' ) }
href={ dashboardLink || 'index.php' }
label={ __( 'Dashboard' ) }
/>
) }
<h2 className="edit-site-sidebar-navigation-screen__title">
{ title }
</h2>
{ actions }
</HStack>
<VStack spacing={ 2 }>
<HStack
spacing={ 4 }
justify="flex-start"
className="edit-site-sidebar-navigation-screen__title-icon"
>
{ ! isRoot ? (
<NavigatorToParentButton
className="edit-site-sidebar-navigation-screen__back"
icon={ isRTL() ? chevronRight : chevronLeft }
aria-label={ __( 'Back' ) }
/>
) : (
<Button
className="edit-site-sidebar-navigation-screen__back"
icon={ isRTL() ? chevronRight : chevronLeft }
aria-label={ __( 'Navigate to the Dashboard' ) }
href={ dashboardLink || 'index.php' }
label={ __( 'Dashboard' ) }
/>
) }
<h2 className="edit-site-sidebar-navigation-screen__title">
{ title }
</h2>
{ actions }
</HStack>

<nav className="edit-site-sidebar-navigation-screen__content">
{ content }
</nav>
</VStack>
</NavigatorScreen>
<nav className="edit-site-sidebar-navigation-screen__content">
{ content }
</nav>
</VStack>
);
}
Loading

0 comments on commit 558a900

Please sign in to comment.