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

Patterns: remove "Manage all parts" page & link #60689

Merged
merged 37 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9e59f77
Details page for parts: always go back to patterns
oandregal Apr 11, 2024
2c120e5
Remove wp_template_part/all sidebar
oandregal Apr 11, 2024
de0226a
Remove wp_template_part/all content & preview frames
oandregal Apr 11, 2024
943ac6c
Remove code to sync entity from URL params
oandregal Apr 11, 2024
c08064e
wp_template_part/all is no longer a page that exists
oandregal Apr 11, 2024
d3e095e
Remove link to Manage all Parts
oandregal Apr 11, 2024
9c62807
Remove code for Parts in the Templates component
oandregal Apr 11, 2024
1feaf09
Rename page class: from edit-site-page-template-template-parts-datavi…
oandregal Apr 11, 2024
4d29772
Move page-templates-template-parts to page-templates
oandregal Apr 11, 2024
3e015b0
/wp_template_part/all: load patterns sidebar
oandregal Apr 12, 2024
6cb562b
Remove template part loading logic
oandregal Apr 12, 2024
2be2331
Update e2e tests
oandregal Apr 12, 2024
52cbb75
Fix import after rebase
oandregal Apr 18, 2024
19ffef2
Fixup sidebar screen pattern
oandregal Apr 18, 2024
6965ef9
Load the patterns screen for /wp_template_part/all
oandregal Apr 18, 2024
b5cee39
Use a generic copy that works for patterns & parts
oandregal Apr 18, 2024
fcd10be
Do not load pattern categories for block themes
oandregal Apr 18, 2024
e487f2d
Set category id & type properly when the path is /wp_template_part/all
oandregal Apr 18, 2024
21af7ea
Content frame: set category id & type properly when the path is /wp_t…
oandregal Apr 18, 2024
8bb9743
Go back to /wp_template_part/all for non-block based themes
oandregal Apr 18, 2024
8212ac2
Use the existing page path (either /patterns or /wp_template_part/all
oandregal Apr 18, 2024
1545f51
Revert changes to get-is-list-page
oandregal Apr 18, 2024
4afe159
Revert changes to sync entity
oandregal Apr 18, 2024
195b50d
Template sidebar: remove postType configuration
oandregal Apr 18, 2024
2ea07e2
Hide actions for themes that are not block based
oandregal Apr 19, 2024
cc9d537
List patterns as well
oandregal Apr 22, 2024
4143618
Fix backpath for non block based themes
oandregal Apr 22, 2024
0a806db
Update Patterns sidebar
oandregal Apr 22, 2024
d7d8d4c
Fix backpath for Pattern sidebar
oandregal Apr 22, 2024
c635c42
Show actions when the path is not /wp_template_part/all
oandregal Apr 22, 2024
45ee635
Non block based themes cannot create template parts
oandregal Apr 22, 2024
627ded8
Update copy for /wp_template_part/all screen
oandregal Apr 22, 2024
3c6aab9
Improve logic to show actions
oandregal Apr 22, 2024
5192d86
Inline strings
oandregal Apr 22, 2024
2dbe1c5
Document backpath
oandregal Apr 22, 2024
08e8ebe
Do not render button if no actions
oandregal Apr 22, 2024
18c6a0b
Revert back changes to content title copy
oandregal Apr 22, 2024
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
51 changes: 13 additions & 38 deletions packages/edit-site/src/components/layout/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useIsSiteEditorLoading } from './hooks';
import Editor from '../editor';
import PagePages from '../page-pages';
import PagePatterns from '../page-patterns';
import PageTemplatesTemplateParts from '../page-templates-template-parts';
import PageTemplates from '../page-templates';
import SidebarNavigationScreen from '../sidebar-navigation-screen';
import SidebarNavigationScreenGlobalStyles from '../sidebar-navigation-screen-global-styles';
import SidebarNavigationScreenMain from '../sidebar-navigation-screen-main';
Expand All @@ -24,10 +24,6 @@ import SidebarNavigationScreenPattern from '../sidebar-navigation-screen-pattern
import SidebarNavigationScreenPatterns from '../sidebar-navigation-screen-patterns';
import SidebarNavigationScreenNavigationMenu from '../sidebar-navigation-screen-navigation-menu';
import DataViewsSidebarContent from '../sidebar-dataviews';
import {
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
} from '../../utils/constants';

const { useLocation, useHistory } = unlock( routerPrivateApis );

Expand Down Expand Up @@ -108,22 +104,12 @@ export default function useLayoutAreas() {
return {
key: 'templates-list',
areas: {
sidebar: (
<SidebarNavigationScreenTemplatesBrowse postType="wp_template" />
),
content: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_POST_TYPE }
/>
),
sidebar: <SidebarNavigationScreenTemplatesBrowse />,
content: <PageTemplates />,
preview: isListLayout && (
<Editor isLoading={ isSiteEditorLoading } />
),
mobile: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_POST_TYPE }
/>
),
mobile: <PageTemplates />,
},
widths: {
content: isListLayout ? 380 : undefined,
Expand All @@ -132,30 +118,19 @@ export default function useLayoutAreas() {
}

// Template parts
/*
* This is for legacy reasons, as the template parts are now part of the patterns screen.
* However, hybrid themes (classic themes that support template parts) still access this URL.
* While there are plans to make them use the patterns screen instead, we cannot do it for now.
* See discussion at https://github.com/WordPress/gutenberg/pull/60689
*/
if ( path === '/wp_template_part/all' ) {
const isListLayout = isCustom !== 'true' && layout === 'list';
return {
key: 'template-parts',
areas: {
sidebar: (
<SidebarNavigationScreenTemplatesBrowse postType="wp_template_part" />
),
content: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_PART_POST_TYPE }
/>
),
preview: isListLayout && (
<Editor isLoading={ isSiteEditorLoading } />
),
mobile: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_PART_POST_TYPE }
/>
),
},
widths: {
content: isListLayout ? 380 : undefined,
sidebar: <SidebarNavigationScreenPatterns />,
content: <PagePatterns />,
mobile: <PagePatterns />,
},
};
}
Expand Down
21 changes: 17 additions & 4 deletions packages/edit-site/src/components/page-patterns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
LAYOUT_LIST,
PATTERN_TYPES,
TEMPLATE_PART_POST_TYPE,
TEMPLATE_PART_ALL_AREAS_CATEGORY,
PATTERN_SYNC_TYPES,
PATTERN_DEFAULT_CATEGORY,
ENUMERATION_TYPE,
Expand All @@ -68,7 +69,7 @@ import { unlock } from '../../lock-unlock';
import usePatterns from './use-patterns';
import PatternsHeader from './header';
import { useLink } from '../routes/link';
import { useAddedBy } from '../page-templates-template-parts/hooks';
import { useAddedBy } from '../page-templates/hooks';

const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock(
blockEditorPrivateApis
Expand Down Expand Up @@ -310,9 +311,21 @@ function Title( { item, categoryId } ) {
}

export default function DataviewsPatterns() {
const { categoryType, categoryId = PATTERN_DEFAULT_CATEGORY } =
getQueryArgs( window.location.href );
const type = categoryType || PATTERN_TYPES.theme;
const {
categoryType,
categoryId: categoryIdFromURL,
path,
} = getQueryArgs( window.location.href );
const type =
categoryType ||
( path === '/wp_template_part/all'
? TEMPLATE_PART_POST_TYPE
: PATTERN_TYPES.theme );
const categoryId =
categoryIdFromURL ||
( path === '/wp_template_part/all'
? TEMPLATE_PART_ALL_AREAS_CATEGORY
: PATTERN_DEFAULT_CATEGORY );
const [ view, setView ] = useState( DEFAULT_VIEW );
const isUncategorizedThemePatterns =
type === PATTERN_TYPES.theme && categoryId === 'uncategorized';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {

import usePatternSettings from '../page-patterns/use-pattern-settings';
import { unlock } from '../../lock-unlock';
import AddNewTemplatePart from './add-new-template-part';

const { usePostActions } = unlock( editorPrivateApis );

Expand Down Expand Up @@ -175,10 +174,7 @@ function Preview( { item, viewType } ) {
onClick={ onClick }
aria-label={ item.title?.rendered || item.title }
>
{ isEmpty &&
( item.type === TEMPLATE_POST_TYPE
? __( 'Empty template' )
: __( 'Empty template part' ) ) }
{ isEmpty && __( 'Empty template' ) }
{ ! isEmpty && (
<Async>
<BlockPreview blocks={ blocks } />
Expand All @@ -199,7 +195,7 @@ const TEMPLATE_ACTIONS = [
'delete-template',
];

export default function PageTemplatesTemplateParts( { postType } ) {
export default function PageTemplates() {
const { params } = useLocation();
const { activeView = 'all', layout } = params;
const defaultView = useMemo( () => {
Expand Down Expand Up @@ -239,7 +235,7 @@ export default function PageTemplatesTemplateParts( { postType } ) {

const { records, isResolving: isLoadingData } = useEntityRecords(
'postType',
postType,
TEMPLATE_POST_TYPE,
{
per_page: -1,
}
Expand Down Expand Up @@ -271,8 +267,8 @@ export default function PageTemplatesTemplateParts( { postType } ) {
} ) );
}, [ records ] );

const fields = useMemo( () => {
const _fields = [
const fields = useMemo(
() => [
{
header: __( 'Preview' ),
id: 'preview',
Expand All @@ -284,10 +280,7 @@ export default function PageTemplatesTemplateParts( { postType } ) {
enableSorting: false,
},
{
header:
postType === TEMPLATE_POST_TYPE
? __( 'Template' )
: __( 'Template Part' ),
header: __( 'Template' ),
id: 'title',
getValue: ( { item } ) => item.title?.rendered,
render: ( { item } ) => (
Expand All @@ -297,9 +290,7 @@ export default function PageTemplatesTemplateParts( { postType } ) {
enableHiding: false,
enableGlobalSearch: true,
},
];
if ( postType === TEMPLATE_POST_TYPE ) {
_fields.push( {
{
header: __( 'Description' ),
id: 'description',
render: ( { item } ) => {
Expand All @@ -324,23 +315,21 @@ export default function PageTemplatesTemplateParts( { postType } ) {
minWidth: 320,
enableSorting: false,
enableGlobalSearch: true,
} );
}
// TODO: The plan is to support fields reordering, which would require an API like `order` or something
// similar. With the aforementioned API we wouldn't need to construct the fields array like this.
_fields.push( {
header: __( 'Author' ),
id: 'author',
getValue: ( { item } ) => item.author_text,
render: ( { item } ) => {
return <AuthorField viewType={ view.type } item={ item } />;
},
type: ENUMERATION_TYPE,
elements: authors,
width: '1%',
} );
return _fields;
}, [ postType, authors, view.type ] );
{
header: __( 'Author' ),
id: 'author',
getValue: ( { item } ) => item.author_text,
render: ( { item } ) => {
return <AuthorField viewType={ view.type } item={ item } />;
},
type: ENUMERATION_TYPE,
elements: authors,
width: '1%',
},
],
[ authors, view.type ]
);

const { data, paginationInfo } = useMemo( () => {
return filterSortAndPaginate( records, view, fields );
Expand Down Expand Up @@ -385,19 +374,9 @@ export default function PageTemplatesTemplateParts( { postType } ) {

return (
<Page
className="edit-site-page-template-template-parts-dataviews"
title={
postType === TEMPLATE_POST_TYPE
? __( 'Templates' )
: __( 'Template Parts' )
}
actions={
postType === TEMPLATE_POST_TYPE ? (
<AddNewTemplate />
) : (
<AddNewTemplatePart />
)
}
className="edit-site-page-templates"
title={ __( 'Templates' ) }
actions={ <AddNewTemplate /> }
>
<DataViews
paginationInfo={ paginationInfo }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
white-space: normal;
}

.edit-site-page-template-template-parts-dataviews {
.edit-site-page-templates {
.dataviews-pagination {
z-index: z-index(".edit-site-templates__dataviews-list-pagination");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* WordPress dependencies
*/
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { pencil } from '@wordpress/icons';
import { getQueryArgs } from '@wordpress/url';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -17,7 +17,6 @@ import usePatternDetails from './use-pattern-details';
import { store as editSiteStore } from '../../store';
import { unlock } from '../../lock-unlock';
import TemplateActions from '../template-actions';
import { TEMPLATE_PART_POST_TYPE } from '../../utils/constants';

const { useLocation, useHistory } = unlock( routerPrivateApis );

Expand All @@ -27,20 +26,18 @@ export default function SidebarNavigationScreenPattern() {
const {
params: { postType, postId },
} = location;
const { categoryType } = getQueryArgs( window.location.href );
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );

useInitEditedEntityFromURL();

const patternDetails = usePatternDetails( postType, postId );

// The absence of a category type in the query params for template parts
// indicates the user has arrived at the template part via the "manage all"
// page and the back button should return them to that list page.
const backPath =
! categoryType && postType === TEMPLATE_PART_POST_TYPE
? { path: '/wp_template_part/all' }
: { path: '/patterns' };
const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);
const backPath = isBlockBasedTheme
? { path: '/patterns' }
: { path: '/wp_template_part/all' };

return (
<SidebarNavigationScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { useAddedBy } from '../page-templates-template-parts/hooks';
import { useAddedBy } from '../page-templates/hooks';
import useEditedEntityRecord from '../use-edited-entity-record';
import useNavigationMenuContent from './use-navigation-menu-content';
import SidebarNavigationScreenDetailsFooter from '../sidebar-navigation-screen-details-footer';
Expand Down
Loading
Loading