Skip to content

Commit a608ced

Browse files
mcsfjuanfraellatrixpriethor
committed
Template activation: improve UX for custom templates (#72499)
Co-authored-by: mcsf <[email protected]> Co-authored-by: juanfra <[email protected]> Co-authored-by: ellatrix <[email protected]> Co-authored-by: priethor < [email protected]>
1 parent 2d4bf41 commit a608ced

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

packages/edit-site/src/components/dataviews-actions/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const useSetActiveTemplateAction = () => {
3535
icon: pencil,
3636
isEligible( item ) {
3737
return (
38+
! item._isCustom &&
3839
! ( item.slug === 'index' && item.source === 'theme' ) &&
3940
item.theme === activeTheme.stylesheet
4041
);

packages/edit-site/src/components/page-templates/fields.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
__experimentalHStack as HStack,
1212
privateApis as componentsPrivateApis,
1313
} from '@wordpress/components';
14-
import { __ } from '@wordpress/i18n';
14+
import { __, _x } from '@wordpress/i18n';
1515
import { useState, useMemo } from '@wordpress/element';
1616
import { decodeEntities } from '@wordpress/html-entities';
1717
import { parse } from '@wordpress/blocks';
@@ -155,6 +155,19 @@ export const activeField = {
155155
id: 'active',
156156
getValue: ( { item } ) => item._isActive,
157157
render: function Render( { item } ) {
158+
if ( item._isCustom ) {
159+
return (
160+
<Badge
161+
intent="info"
162+
title={ __(
163+
'Custom templates cannot be active nor inactive.'
164+
) }
165+
>
166+
{ __( 'N/A' ) }
167+
</Badge>
168+
);
169+
}
170+
158171
const isActive = item._isActive;
159172
return (
160173
<Badge intent={ isActive ? 'success' : 'default' }>
@@ -190,10 +203,6 @@ export const slugField = {
190203
const defaultTemplateType = defaultTemplateTypes.find(
191204
( type ) => type.slug === item.slug
192205
);
193-
return (
194-
defaultTemplateType?.title ||
195-
// translators: %s is the slug of a custom template.
196-
__( 'Custom' )
197-
);
206+
return defaultTemplateType?.title || _x( 'Custom', 'template type' );
198207
},
199208
};

packages/edit-site/src/components/page-templates/index.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ export default function PageTemplates() {
7272
},
7373
} );
7474

75-
const { activeTemplatesOption, activeTheme } = useSelect( ( select ) => {
76-
const { getEntityRecord, getCurrentTheme } = select( coreStore );
77-
return {
78-
activeTemplatesOption: getEntityRecord( 'root', 'site' )
79-
?.active_templates,
80-
activeTheme: getCurrentTheme(),
81-
};
82-
} );
75+
const { activeTemplatesOption, activeTheme, defaultTemplateTypes } =
76+
useSelect( ( select ) => {
77+
const { getEntityRecord, getCurrentTheme } = select( coreStore );
78+
return {
79+
activeTemplatesOption: getEntityRecord( 'root', 'site' )
80+
?.active_templates,
81+
activeTheme: getCurrentTheme(),
82+
defaultTemplateTypes:
83+
select( coreStore ).getCurrentTheme()
84+
?.default_template_types,
85+
};
86+
} );
8387
// Todo: this will have to be better so that we're not fetching all the
8488
// records all the time. Active templates query will need to move server
8589
// side.
@@ -150,8 +154,14 @@ export default function PageTemplates() {
150154
_isActive: activeTemplates.find(
151155
( template ) => template.id === record.id
152156
),
157+
_isCustom:
158+
record.is_custom ||
159+
( ! record.meta?.is_wp_suggestion &&
160+
! defaultTemplateTypes.find(
161+
( type ) => type.slug === record.slug
162+
) ),
153163
} ) );
154-
}, [ _records, activeTemplates ] );
164+
}, [ _records, activeTemplates, defaultTemplateTypes ] );
155165

156166
const users = useSelect(
157167
( select ) => {

0 commit comments

Comments
 (0)