Skip to content

Commit

Permalink
Patterns: remove "Manage all parts" page & link (#60689)
Browse files Browse the repository at this point in the history
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: SaxonF <saxonafletcher@git.wordpress.org>
  • Loading branch information
7 people authored Apr 22, 2024
1 parent aa5cdae commit e6321ba
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 269 deletions.
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
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

0 comments on commit e6321ba

Please sign in to comment.