From 371248420193dee8aab9bcd82d5db0baf8745070 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 25 Oct 2021 20:14:22 +0200 Subject: [PATCH 01/14] EntityTypeList: Add entity descriptions --- .../entities-saved-states/entity-type-list.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-type-list.js b/packages/editor/src/components/entities-saved-states/entity-type-list.js index fc8d9922beca11..b0e837a9789ff4 100644 --- a/packages/editor/src/components/entities-saved-states/entity-type-list.js +++ b/packages/editor/src/components/entities-saved-states/entity-type-list.js @@ -6,8 +6,9 @@ import { some } from 'lodash'; /** * WordPress dependencies */ +import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; -import { PanelBody } from '@wordpress/components'; +import { PanelBody, PanelRow } from '@wordpress/components'; import { page, layout } from '@wordpress/icons'; import { store as coreStore } from '@wordpress/core-data'; @@ -21,6 +22,13 @@ const ENTITY_NAME_ICONS = { page, }; +const ENTITY_NAME_DESCRIPTIONS = { + site: __( 'These changes will affect your whole site.' ), + wp_template: __( + 'These changes will affect pages and posts that use these templates.' + ), +}; + export default function EntityTypeList( { list, unselectedEntities, @@ -34,12 +42,14 @@ export default function EntityTypeList( { [ firstRecord.kind, firstRecord.name ] ); - // Set icon based on type of entity. + // Set icon and description based on type of entity. const { name } = firstRecord; const icon = ENTITY_NAME_ICONS[ name ]; + const description = ENTITY_NAME_DESCRIPTIONS[ name ]; return ( + { description ? { description } : null } { list.map( ( record ) => { return ( Date: Mon, 25 Oct 2021 21:02:22 +0200 Subject: [PATCH 02/14] Sort entity groups --- .../components/entities-saved-states/index.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/index.js b/packages/editor/src/components/entities-saved-states/index.js index 0015cdecd6435c..77ea0fc840439a 100644 --- a/packages/editor/src/components/entities-saved-states/index.js +++ b/packages/editor/src/components/entities-saved-states/index.js @@ -68,9 +68,21 @@ export default function EntitiesSavedStates( { close } ) { } = useDispatch( coreStore ); // To group entities by type. - const partitionedSavables = Object.values( - groupBy( dirtyEntityRecords, 'name' ) - ); + const partitionedSavables = groupBy( dirtyEntityRecords, 'name' ); + + // Sort entity groups. + const { + site: siteSavables, + wp_template: templateSavables, + wp_template_part: templatePartSavables, + ...contentSavables + } = partitionedSavables; + const sortedPartitionedSavables = [ + siteSavables, + templateSavables, + templatePartSavables, + ...Object.values( contentSavables ), + ]; // Unchecked entities to be ignored by save function. const [ unselectedEntities, _setUnselectedEntities ] = useState( [] ); @@ -168,7 +180,7 @@ export default function EntitiesSavedStates( { close } ) {

- { partitionedSavables.map( ( list ) => { + { sortedPartitionedSavables.map( ( list ) => { return ( Date: Mon, 25 Oct 2021 21:27:22 +0200 Subject: [PATCH 03/14] Change panel header copy --- packages/editor/src/components/entities-saved-states/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/index.js b/packages/editor/src/components/entities-saved-states/index.js index 77ea0fc840439a..431c393d84aa85 100644 --- a/packages/editor/src/components/entities-saved-states/index.js +++ b/packages/editor/src/components/entities-saved-states/index.js @@ -172,10 +172,10 @@ export default function EntitiesSavedStates( { close } ) {
- { __( 'Select the changes you want to save' ) } + { __( 'Are you ready to save?' ) }

{ __( - 'Some changes may affect other areas of your site.' + 'The following changes have been made to your site, templates, and content.' ) }

From 034eace7886f7201106b71209d17796e9a05ce87 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 27 Oct 2021 16:52:35 +0200 Subject: [PATCH 04/14] Remove undefined entries from partitioned savables --- packages/editor/src/components/entities-saved-states/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/components/entities-saved-states/index.js b/packages/editor/src/components/entities-saved-states/index.js index 431c393d84aa85..50f92da12d8420 100644 --- a/packages/editor/src/components/entities-saved-states/index.js +++ b/packages/editor/src/components/entities-saved-states/index.js @@ -82,7 +82,7 @@ export default function EntitiesSavedStates( { close } ) { templateSavables, templatePartSavables, ...Object.values( contentSavables ), - ]; + ].filter( Array.isArray ); // Unchecked entities to be ignored by save function. const [ unselectedEntities, _setUnselectedEntities ] = useState( [] ); From ef6f357c5b734d3e65a40e38f97c16e9c28d3a44 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 27 Oct 2021 17:56:26 +0200 Subject: [PATCH 05/14] Use singular and plural depending on number of savables per entity --- .../entities-saved-states/entity-type-list.js | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-type-list.js b/packages/editor/src/components/entities-saved-states/entity-type-list.js index b0e837a9789ff4..9650329b18b816 100644 --- a/packages/editor/src/components/entities-saved-states/entity-type-list.js +++ b/packages/editor/src/components/entities-saved-states/entity-type-list.js @@ -6,7 +6,7 @@ import { some } from 'lodash'; /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; +import { _n } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { PanelBody, PanelRow } from '@wordpress/components'; import { page, layout } from '@wordpress/icons'; @@ -23,10 +23,18 @@ const ENTITY_NAME_ICONS = { }; const ENTITY_NAME_DESCRIPTIONS = { - site: __( 'These changes will affect your whole site.' ), - wp_template: __( - 'These changes will affect pages and posts that use these templates.' - ), + site: ( length ) => + _n( + 'This change will affect your whole site.', + 'These changes will affect your whole site.', + length + ), + wp_template: ( length ) => + _n( + 'This change will affect pages and posts that use these templates.', + 'These changes will affect pages and posts that use these templates.', + length + ), }; export default function EntityTypeList( { @@ -45,7 +53,7 @@ export default function EntityTypeList( { // Set icon and description based on type of entity. const { name } = firstRecord; const icon = ENTITY_NAME_ICONS[ name ]; - const description = ENTITY_NAME_DESCRIPTIONS[ name ]; + const description = ENTITY_NAME_DESCRIPTIONS[ name ]?.( list.length ); return ( From d6b86795631a676c97e77fc44f3a5568e69deefe Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 27 Oct 2021 18:01:51 +0200 Subject: [PATCH 06/14] Tweak singular --- .../src/components/entities-saved-states/entity-type-list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-type-list.js b/packages/editor/src/components/entities-saved-states/entity-type-list.js index 9650329b18b816..476d08e6fdf775 100644 --- a/packages/editor/src/components/entities-saved-states/entity-type-list.js +++ b/packages/editor/src/components/entities-saved-states/entity-type-list.js @@ -31,7 +31,7 @@ const ENTITY_NAME_DESCRIPTIONS = { ), wp_template: ( length ) => _n( - 'This change will affect pages and posts that use these templates.', + 'This change will affect pages and posts that use this template.', 'These changes will affect pages and posts that use these templates.', length ), From 88adb536cf6fc57f03b809ff51b50a652c8623b0 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 27 Oct 2021 18:20:03 +0200 Subject: [PATCH 07/14] Remove icons from entities --- .../entities-saved-states/entity-type-list.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-type-list.js b/packages/editor/src/components/entities-saved-states/entity-type-list.js index 476d08e6fdf775..078aea48f592b5 100644 --- a/packages/editor/src/components/entities-saved-states/entity-type-list.js +++ b/packages/editor/src/components/entities-saved-states/entity-type-list.js @@ -9,7 +9,6 @@ import { some } from 'lodash'; import { _n } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { PanelBody, PanelRow } from '@wordpress/components'; -import { page, layout } from '@wordpress/icons'; import { store as coreStore } from '@wordpress/core-data'; /** @@ -17,11 +16,6 @@ import { store as coreStore } from '@wordpress/core-data'; */ import EntityRecordItem from './entity-record-item'; -const ENTITY_NAME_ICONS = { - site: layout, - page, -}; - const ENTITY_NAME_DESCRIPTIONS = { site: ( length ) => _n( @@ -50,13 +44,12 @@ export default function EntityTypeList( { [ firstRecord.kind, firstRecord.name ] ); - // Set icon and description based on type of entity. + // Set description based on type of entity. const { name } = firstRecord; - const icon = ENTITY_NAME_ICONS[ name ]; const description = ENTITY_NAME_DESCRIPTIONS[ name ]?.( list.length ); return ( - + { description ? { description } : null } { list.map( ( record ) => { return ( From 4ef8ac11d63df3716a349ecf85528c48ebde1cec Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 28 Oct 2021 16:04:09 +0200 Subject: [PATCH 08/14] Use template part area label rather than template part title --- .../entity-record-item.js | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-record-item.js b/packages/editor/src/components/entities-saved-states/entity-record-item.js index 8aaf5173b97e9b..74de20106ef77f 100644 --- a/packages/editor/src/components/entities-saved-states/entity-record-item.js +++ b/packages/editor/src/components/entities-saved-states/entity-record-item.js @@ -38,7 +38,10 @@ export default function EntityRecordItem( { // Handle templates that might use default descriptive titles const entityRecordTitle = useSelect( ( select ) => { - if ( 'postType' !== kind || 'wp_template' !== name ) { + if ( + 'postType' !== kind || + ! [ 'wp_template', 'wp_template_part' ].includes( name ) + ) { return title; } @@ -47,9 +50,25 @@ export default function EntityRecordItem( { name, key ); - return select( editorStore ).__experimentalGetTemplateInfo( - template - ).title; + + if ( name === 'wp_template' ) { + return select( editorStore ).__experimentalGetTemplateInfo( + template + ).title; + } + + if ( name === 'wp_template_part' ) { + const templatePartAreas = select( + editorStore + ).__experimentalGetDefaultTemplatePartAreas(); + + return ( + templatePartAreas.find( + ( templatePartArea ) => + templatePartArea.area === template.area + )?.label ?? title + ); + } }, [ name, kind, title, key ] ); From f7548489c4a50a059203591838ced4fe952ea6fe Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 29 Oct 2021 13:50:08 +0200 Subject: [PATCH 09/14] Revert "Use template part area label rather than template part title" This reverts commit 4ef8ac11d63df3716a349ecf85528c48ebde1cec. --- .../entity-record-item.js | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-record-item.js b/packages/editor/src/components/entities-saved-states/entity-record-item.js index 74de20106ef77f..8aaf5173b97e9b 100644 --- a/packages/editor/src/components/entities-saved-states/entity-record-item.js +++ b/packages/editor/src/components/entities-saved-states/entity-record-item.js @@ -38,10 +38,7 @@ export default function EntityRecordItem( { // Handle templates that might use default descriptive titles const entityRecordTitle = useSelect( ( select ) => { - if ( - 'postType' !== kind || - ! [ 'wp_template', 'wp_template_part' ].includes( name ) - ) { + if ( 'postType' !== kind || 'wp_template' !== name ) { return title; } @@ -50,25 +47,9 @@ export default function EntityRecordItem( { name, key ); - - if ( name === 'wp_template' ) { - return select( editorStore ).__experimentalGetTemplateInfo( - template - ).title; - } - - if ( name === 'wp_template_part' ) { - const templatePartAreas = select( - editorStore - ).__experimentalGetDefaultTemplatePartAreas(); - - return ( - templatePartAreas.find( - ( templatePartArea ) => - templatePartArea.area === template.area - )?.label ?? title - ); - } + return select( editorStore ).__experimentalGetTemplateInfo( + template + ).title; }, [ name, kind, title, key ] ); From 496d43f5d10876a503f9b18d839c164cd3b5e248 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 29 Oct 2021 14:23:20 +0200 Subject: [PATCH 10/14] Replace ternary by && Co-authored-by: Nik Tsekouras --- .../src/components/entities-saved-states/entity-type-list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-type-list.js b/packages/editor/src/components/entities-saved-states/entity-type-list.js index 078aea48f592b5..9af18738600c07 100644 --- a/packages/editor/src/components/entities-saved-states/entity-type-list.js +++ b/packages/editor/src/components/entities-saved-states/entity-type-list.js @@ -50,7 +50,7 @@ export default function EntityTypeList( { return ( - { description ? { description } : null } + { description && { description } } { list.map( ( record ) => { return ( Date: Fri, 29 Oct 2021 14:56:51 +0200 Subject: [PATCH 11/14] Add description for content entities --- .../entities-saved-states/entity-type-list.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-type-list.js b/packages/editor/src/components/entities-saved-states/entity-type-list.js index 9af18738600c07..b381ca704013bf 100644 --- a/packages/editor/src/components/entities-saved-states/entity-type-list.js +++ b/packages/editor/src/components/entities-saved-states/entity-type-list.js @@ -6,7 +6,7 @@ import { some } from 'lodash'; /** * WordPress dependencies */ -import { _n } from '@wordpress/i18n'; +import { __, _n } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { PanelBody, PanelRow } from '@wordpress/components'; import { store as coreStore } from '@wordpress/core-data'; @@ -16,20 +16,25 @@ import { store as coreStore } from '@wordpress/core-data'; */ import EntityRecordItem from './entity-record-item'; -const ENTITY_NAME_DESCRIPTIONS = { - site: ( length ) => - _n( +function getEntityDescription( entity, length ) { + const descriptions = { + site: _n( 'This change will affect your whole site.', 'These changes will affect your whole site.', length ), - wp_template: ( length ) => - _n( + wp_template: _n( 'This change will affect pages and posts that use this template.', 'These changes will affect pages and posts that use these templates.', length ), -}; + }; + + return ( + descriptions[ entity ] ?? + __( 'The following content has been modified.' ) + ); +} export default function EntityTypeList( { list, @@ -46,7 +51,7 @@ export default function EntityTypeList( { // Set description based on type of entity. const { name } = firstRecord; - const description = ENTITY_NAME_DESCRIPTIONS[ name ]?.( list.length ); + const description = getEntityDescription( name, list.length ); return ( From f033bfe62a41af70597502f5315f779498bec52b Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 29 Oct 2021 15:28:05 +0200 Subject: [PATCH 12/14] No description for Template Part --- .../src/components/entities-saved-states/entity-type-list.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/editor/src/components/entities-saved-states/entity-type-list.js b/packages/editor/src/components/entities-saved-states/entity-type-list.js index b381ca704013bf..717d7041ba8167 100644 --- a/packages/editor/src/components/entities-saved-states/entity-type-list.js +++ b/packages/editor/src/components/entities-saved-states/entity-type-list.js @@ -28,6 +28,7 @@ function getEntityDescription( entity, length ) { 'These changes will affect pages and posts that use these templates.', length ), + wp_template_part: '', // No separate description for template parts. }; return ( From 84759fe3a78a466004253ea0089b75746c6a91d4 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 29 Oct 2021 15:29:53 +0200 Subject: [PATCH 13/14] Singular/plural for Template Part(s) header --- .../components/entities-saved-states/entity-type-list.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-type-list.js b/packages/editor/src/components/entities-saved-states/entity-type-list.js index 717d7041ba8167..9846ad0f7c9917 100644 --- a/packages/editor/src/components/entities-saved-states/entity-type-list.js +++ b/packages/editor/src/components/entities-saved-states/entity-type-list.js @@ -49,13 +49,16 @@ export default function EntityTypeList( { select( coreStore ).getEntity( firstRecord.kind, firstRecord.name ), [ firstRecord.kind, firstRecord.name ] ); - - // Set description based on type of entity. const { name } = firstRecord; + const entityLabel = + name === 'wp_template_part' + ? _n( 'Template Part', 'Template Parts', list.length ) + : entity.label; + // Set description based on type of entity. const description = getEntityDescription( name, list.length ); return ( - + { description && { description } } { list.map( ( record ) => { return ( From 2d024a5832623a9eef3c5f80eaf18fb004b59402 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 29 Oct 2021 17:49:54 +0200 Subject: [PATCH 14/14] Tweak entity descriptions to exclude reusable blocks --- .../entities-saved-states/entity-type-list.js | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/editor/src/components/entities-saved-states/entity-type-list.js b/packages/editor/src/components/entities-saved-states/entity-type-list.js index 9846ad0f7c9917..ec32c79f77c7eb 100644 --- a/packages/editor/src/components/entities-saved-states/entity-type-list.js +++ b/packages/editor/src/components/entities-saved-states/entity-type-list.js @@ -17,24 +17,23 @@ import { store as coreStore } from '@wordpress/core-data'; import EntityRecordItem from './entity-record-item'; function getEntityDescription( entity, length ) { - const descriptions = { - site: _n( - 'This change will affect your whole site.', - 'These changes will affect your whole site.', - length - ), - wp_template: _n( - 'This change will affect pages and posts that use this template.', - 'These changes will affect pages and posts that use these templates.', - length - ), - wp_template_part: '', // No separate description for template parts. - }; - - return ( - descriptions[ entity ] ?? - __( 'The following content has been modified.' ) - ); + switch ( entity ) { + case 'site': + return _n( + 'This change will affect your whole site.', + 'These changes will affect your whole site.', + length + ); + case 'wp_template': + return _n( + 'This change will affect pages and posts that use this template.', + 'These changes will affect pages and posts that use these templates.', + length + ); + case 'page': + case 'post': + return __( 'The following content has been modified.' ); + } } export default function EntityTypeList( {