Skip to content

Commit

Permalink
DataViews: Update template parts view (#57952)
Browse files Browse the repository at this point in the history
* DataViews: Update template parts view

* fix initialization of edited entity for template parts

* make the view stable

* add clarification message
  • Loading branch information
ntsekouras authored Jan 23, 2024
1 parent 4c96f5e commit 16c4d12
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 193 deletions.
31 changes: 26 additions & 5 deletions packages/edit-site/src/components/layout/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ import Editor from '../editor';
import DataviewsPatterns from '../page-patterns/dataviews-patterns';
import PagePages from '../page-pages';
import PagePatterns from '../page-patterns';
import PageTemplateParts from '../page-template-parts';
import PageTemplates from '../page-templates';
import PageTemplatesTemplateParts from '../page-templates-template-parts';

import {
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
} from '../../utils/constants';

const { useLocation } = unlock( routerPrivateApis );

export default function useLayoutAreas() {
const isSiteEditorLoading = useIsSiteEditorLoading();
const { params } = useLocation();
const { postType, postId, path, layout, isCustom } = params ?? {};

// Regular page
if ( path === '/page' ) {
const isListLayout =
Expand Down Expand Up @@ -62,7 +65,11 @@ export default function useLayoutAreas() {
window?.__experimentalAdminViews;
return {
areas: {
content: <PageTemplates />,
content: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_POST_TYPE }
/>
),
preview: isListLayout && (
<Editor isLoading={ isSiteEditorLoading } />
),
Expand All @@ -75,9 +82,23 @@ export default function useLayoutAreas() {

// Template parts
if ( path === '/wp_template_part/all' ) {
const isListLayout =
isCustom !== 'true' &&
layout === 'list' &&
window?.__experimentalAdminViews;
return {
areas: {
content: <PageTemplateParts />,
content: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_PART_POST_TYPE }
/>
),
preview: isListLayout && (
<Editor isLoading={ isSiteEditorLoading } />
),
},
widths: {
content: isListLayout ? 380 : undefined,
},
};
}
Expand Down
99 changes: 0 additions & 99 deletions packages/edit-site/src/components/page-template-parts/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,17 @@ export const deleteTemplateAction = {
export const renameTemplateAction = {
id: 'rename-template',
label: __( 'Rename' ),
isEligible: ( template ) =>
isTemplateRemovable( template ) && template.is_custom,
isEligible: ( template ) => {
// We can only remove templates or template parts that can be removed.
// Additionally in the case of templates, we can only remove custom templates.
if (
! isTemplateRemovable( template ) ||
( template.type === TEMPLATE_POST_TYPE && ! template.is_custom )
) {
return false;
}
return true;
},
RenderModal: ( { items: templates, closeModal } ) => {
const template = templates[ 0 ];
const title = decodeEntities( template.title.rendered );
Expand Down
Loading

1 comment on commit 16c4d12

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 16c4d12.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7626371951
📝 Reported issues:

Please sign in to comment.