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 33 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
36 changes: 18 additions & 18 deletions packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import { DropdownMenu } from '@wordpress/components';
import { useState, useRef } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { plus, symbol, symbolFilled, upload } from '@wordpress/icons';
import { useSelect, useDispatch } from '@wordpress/data';
import { useDispatch } from '@wordpress/data';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import {
privateApis as editPatternsPrivateApis,
store as patternsStore,
} from '@wordpress/patterns';
import { store as coreStore } from '@wordpress/core-data';
import { store as noticesStore } from '@wordpress/notices';

/**
Expand All @@ -31,15 +30,12 @@ const { CreatePatternModal, useAddPatternCategory } = unlock(
editPatternsPrivateApis
);

export default function AddNewPattern() {
export default function AddNewPattern( { canCreateParts, canCreatePatterns } ) {
const history = useHistory();
const { params } = useLocation();
const [ showPatternModal, setShowPatternModal ] = useState( false );
const [ showTemplatePartModal, setShowTemplatePartModal ] =
useState( false );
const isBlockBasedTheme = useSelect( ( select ) => {
return select( coreStore ).getCurrentTheme()?.is_block_theme;
}, [] );
const { createPatternFromFile } = unlock( useDispatch( patternsStore ) );
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );
Expand Down Expand Up @@ -73,29 +69,33 @@ export default function AddNewPattern() {
setShowTemplatePartModal( false );
}

const controls = [
{
const controls = [];

if ( canCreatePatterns ) {
controls.push( {
icon: symbol,
onClick: () => setShowPatternModal( true ),
title: __( 'Create pattern' ),
},
];
} );
}

if ( isBlockBasedTheme ) {
if ( canCreateParts ) {
controls.push( {
icon: symbolFilled,
onClick: () => setShowTemplatePartModal( true ),
title: __( 'Create template part' ),
} );
}

controls.push( {
icon: upload,
onClick: () => {
patternUploadInputRef.current.click();
},
title: __( 'Import pattern from JSON' ),
} );
if ( canCreatePatterns ) {
controls.push( {
icon: upload,
onClick: () => {
patternUploadInputRef.current.click();
},
title: __( 'Import pattern from JSON' ),
} );
}

const { categoryMap, findOrCreateTerm } = useAddPatternCategory();
return (
Expand Down
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
6 changes: 2 additions & 4 deletions packages/edit-site/src/components/page-patterns/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ export default function PatternsHeader( {
const templatePartArea = templatePartAreas.find(
( area ) => area.area === categoryId
);
title = templatePartArea?.label || __( 'All Template Parts' );
description =
templatePartArea?.description ||
__( 'Includes every template part defined for any area.' );
title = templatePartArea?.label || __( 'Template Parts' );
description = templatePartArea?.description;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why you removed "all" from the title and the description fallback? I'm curious about the difference when opening "All patterns" and "All template parts" in the sidebar.

"Al template part" is selected:

image

"All patterns" is selected:

image

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about making these text the same for hybrid themes in the template parts screen so before/after is the same. Though I now realize it's best to leave them as they are. Reverted the changes at 18c6a0b

} else if ( type === PATTERN_TYPES.theme ) {
patternCategory = patternCategories.find(
( category ) => category.name === categoryId
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.

Loading
Loading