@wordpress/edit-site 6.33.5 → 6.33.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/build/components/add-new-template/add-custom-template-modal-content.js +3 -1
  2. package/build/components/add-new-template/add-custom-template-modal-content.js.map +2 -2
  3. package/build/components/add-new-template/index.js +6 -4
  4. package/build/components/add-new-template/index.js.map +2 -2
  5. package/build/components/add-new-template/utils.js +84 -9
  6. package/build/components/add-new-template/utils.js.map +2 -2
  7. package/build/components/dataviews-actions/index.js +2 -55
  8. package/build/components/dataviews-actions/index.js.map +3 -3
  9. package/build/components/editor/index.js +0 -1
  10. package/build/components/editor/index.js.map +2 -2
  11. package/build/components/editor/use-resolve-edited-entity.js +5 -11
  12. package/build/components/editor/use-resolve-edited-entity.js.map +2 -2
  13. package/build/components/page-templates/fields.js +5 -80
  14. package/build/components/page-templates/fields.js.map +3 -3
  15. package/build/components/page-templates/hooks.js +1 -1
  16. package/build/components/page-templates/hooks.js.map +2 -2
  17. package/build/components/page-templates/index.js +46 -217
  18. package/build/components/page-templates/index.js.map +3 -3
  19. package/build/components/page-templates/view-utils.js +1 -5
  20. package/build/components/page-templates/view-utils.js.map +2 -2
  21. package/build/components/sidebar-navigation-screen-templates-browse/content.js +6 -21
  22. package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
  23. package/build/components/site-editor-routes/template-item.js +14 -15
  24. package/build/components/site-editor-routes/template-item.js.map +2 -2
  25. package/build-module/components/add-new-template/add-custom-template-modal-content.js +3 -1
  26. package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +2 -2
  27. package/build-module/components/add-new-template/index.js +7 -4
  28. package/build-module/components/add-new-template/index.js.map +2 -2
  29. package/build-module/components/add-new-template/utils.js +84 -9
  30. package/build-module/components/add-new-template/utils.js.map +2 -2
  31. package/build-module/components/dataviews-actions/index.js +1 -53
  32. package/build-module/components/dataviews-actions/index.js.map +2 -2
  33. package/build-module/components/editor/index.js +0 -1
  34. package/build-module/components/editor/index.js.map +2 -2
  35. package/build-module/components/editor/use-resolve-edited-entity.js +5 -11
  36. package/build-module/components/editor/use-resolve-edited-entity.js.map +2 -2
  37. package/build-module/components/page-templates/fields.js +6 -85
  38. package/build-module/components/page-templates/fields.js.map +3 -3
  39. package/build-module/components/page-templates/hooks.js +1 -1
  40. package/build-module/components/page-templates/hooks.js.map +2 -2
  41. package/build-module/components/page-templates/index.js +51 -235
  42. package/build-module/components/page-templates/index.js.map +2 -2
  43. package/build-module/components/page-templates/view-utils.js +1 -5
  44. package/build-module/components/page-templates/view-utils.js.map +2 -2
  45. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +7 -22
  46. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
  47. package/build-module/components/site-editor-routes/template-item.js +14 -15
  48. package/build-module/components/site-editor-routes/template-item.js.map +2 -2
  49. package/package.json +17 -17
  50. package/src/components/add-new-template/add-custom-template-modal-content.js +3 -1
  51. package/src/components/add-new-template/index.js +9 -4
  52. package/src/components/add-new-template/utils.js +118 -9
  53. package/src/components/dataviews-actions/index.js +0 -61
  54. package/src/components/editor/index.js +0 -1
  55. package/src/components/editor/use-resolve-edited-entity.js +5 -20
  56. package/src/components/page-templates/fields.js +5 -95
  57. package/src/components/page-templates/hooks.js +1 -1
  58. package/src/components/page-templates/index.js +35 -244
  59. package/src/components/page-templates/view-utils.js +1 -8
  60. package/src/components/sidebar-navigation-screen-templates-browse/content.js +7 -22
  61. package/src/components/site-editor-routes/template-item.js +26 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/edit-site",
3
- "version": "6.33.5",
3
+ "version": "6.33.6",
4
4
  "description": "Edit Site Page module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -38,26 +38,26 @@
38
38
  "dependencies": {
39
39
  "@react-spring/web": "^9.4.5",
40
40
  "@wordpress/a11y": "^4.33.1",
41
- "@wordpress/admin-ui": "^1.1.1",
41
+ "@wordpress/admin-ui": "^1.1.2",
42
42
  "@wordpress/api-fetch": "^7.33.1",
43
43
  "@wordpress/base-styles": "^6.9.1",
44
44
  "@wordpress/blob": "^4.33.1",
45
- "@wordpress/block-editor": "^15.6.3",
46
- "@wordpress/block-library": "^9.33.4",
45
+ "@wordpress/block-editor": "^15.6.4",
46
+ "@wordpress/block-library": "^9.33.5",
47
47
  "@wordpress/blocks": "^15.6.1",
48
- "@wordpress/commands": "^1.33.1",
49
- "@wordpress/components": "^30.6.1",
48
+ "@wordpress/commands": "^1.33.2",
49
+ "@wordpress/components": "^30.6.2",
50
50
  "@wordpress/compose": "^7.33.1",
51
- "@wordpress/core-data": "^7.33.3",
51
+ "@wordpress/core-data": "^7.33.4",
52
52
  "@wordpress/data": "^10.33.1",
53
- "@wordpress/dataviews": "^10.1.2",
53
+ "@wordpress/dataviews": "^10.1.3",
54
54
  "@wordpress/date": "^5.33.1",
55
55
  "@wordpress/deprecated": "^4.33.1",
56
56
  "@wordpress/dom": "^4.33.1",
57
- "@wordpress/editor": "^14.33.5",
57
+ "@wordpress/editor": "^14.33.6",
58
58
  "@wordpress/element": "^6.33.1",
59
59
  "@wordpress/escape-html": "^3.33.1",
60
- "@wordpress/fields": "^0.25.5",
60
+ "@wordpress/fields": "^0.25.6",
61
61
  "@wordpress/hooks": "^4.33.1",
62
62
  "@wordpress/html-entities": "^4.33.1",
63
63
  "@wordpress/i18n": "^6.6.1",
@@ -66,18 +66,18 @@
66
66
  "@wordpress/keycodes": "^4.33.1",
67
67
  "@wordpress/media-utils": "^5.33.1",
68
68
  "@wordpress/notices": "^5.33.1",
69
- "@wordpress/patterns": "^2.33.3",
70
- "@wordpress/plugins": "^7.33.1",
71
- "@wordpress/preferences": "^4.33.1",
69
+ "@wordpress/patterns": "^2.33.4",
70
+ "@wordpress/plugins": "^7.33.2",
71
+ "@wordpress/preferences": "^4.33.2",
72
72
  "@wordpress/primitives": "^4.33.1",
73
73
  "@wordpress/private-apis": "^1.33.1",
74
- "@wordpress/reusable-blocks": "^5.33.3",
74
+ "@wordpress/reusable-blocks": "^5.33.4",
75
75
  "@wordpress/router": "^1.33.1",
76
76
  "@wordpress/style-engine": "^2.33.1",
77
77
  "@wordpress/url": "^4.33.1",
78
78
  "@wordpress/viewport": "^6.33.1",
79
- "@wordpress/views": "^1.0.3",
80
- "@wordpress/widgets": "^4.33.3",
79
+ "@wordpress/views": "^1.0.4",
80
+ "@wordpress/widgets": "^4.33.4",
81
81
  "@wordpress/wordcount": "^4.33.1",
82
82
  "change-case": "^4.1.2",
83
83
  "clsx": "^2.1.1",
@@ -93,5 +93,5 @@
93
93
  "publishConfig": {
94
94
  "access": "public"
95
95
  },
96
- "gitHead": "b54bd3285e50e409580bdfa2c47bc81f0000a0c9"
96
+ "gitHead": "2e2a11a11f0c5c9cb2bba2dd40b8046d2a10dc9d"
97
97
  }
@@ -173,7 +173,9 @@ function AddCustomTemplateModalContent( {
173
173
  onBack,
174
174
  containerRef,
175
175
  } ) {
176
- const [ showSearchEntities, setShowSearchEntities ] = useState();
176
+ const [ showSearchEntities, setShowSearchEntities ] = useState(
177
+ entityForSuggestions.hasGeneralTemplate
178
+ );
177
179
 
178
180
  // Focus on the first focusable element when the modal opens.
179
181
  // We handle focus management in the parent modal, just need to focus on the first focusable element.
@@ -53,6 +53,7 @@ import { TEMPLATE_POST_TYPE } from '../../utils/constants';
53
53
  */
54
54
  import AddCustomTemplateModalContent from './add-custom-template-modal-content';
55
55
  import {
56
+ useExistingTemplates,
56
57
  useDefaultTemplateTypes,
57
58
  useTaxonomiesMenuItems,
58
59
  usePostTypeMenuItems,
@@ -211,9 +212,7 @@ function NewTemplateModal( { onClose } ) {
211
212
  status: 'publish',
212
213
  title,
213
214
  // This adds a post meta field in template that is part of `is_custom` value calculation.
214
- meta: {
215
- is_wp_suggestion: isWPSuggestion,
216
- },
215
+ is_wp_suggestion: isWPSuggestion,
217
216
  },
218
217
  { throwOnError: true }
219
218
  );
@@ -389,9 +388,15 @@ function NewTemplate() {
389
388
  }
390
389
 
391
390
  function useMissingTemplates( setEntityForSuggestions, onClick ) {
391
+ const existingTemplates = useExistingTemplates();
392
392
  const defaultTemplateTypes = useDefaultTemplateTypes();
393
+ const existingTemplateSlugs = ( existingTemplates || [] ).map(
394
+ ( { slug } ) => slug
395
+ );
393
396
  const missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(
394
- ( template ) => DEFAULT_TEMPLATE_SLUGS.includes( template.slug )
397
+ ( template ) =>
398
+ DEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&
399
+ ! existingTemplateSlugs.includes( template.slug )
395
400
  );
396
401
  const onClickMenuItem = ( _entityForSuggestions ) => {
397
402
  onClick?.();
@@ -204,6 +204,7 @@ export function usePostTypeArchiveMenuItems() {
204
204
 
205
205
  export const usePostTypeMenuItems = ( onClickMenuItem ) => {
206
206
  const publicPostTypes = usePublicPostTypes();
207
+ const existingTemplates = useExistingTemplates();
207
208
  const defaultTemplateTypes = useDefaultTemplateTypes();
208
209
  // We need to keep track of naming conflicts. If a conflict
209
210
  // occurs, we need to add slug.
@@ -243,6 +244,9 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => {
243
244
  [ publicPostTypes ]
244
245
  );
245
246
  const postTypesInfo = useEntitiesInfo( 'postType', templatePrefixes );
247
+ const existingTemplateSlugs = ( existingTemplates || [] ).map(
248
+ ( { slug } ) => slug
249
+ );
246
250
  const menuItems = ( publicPostTypes || [] ).reduce(
247
251
  ( accumulator, postType ) => {
248
252
  const { slug, labels, icon } = postType;
@@ -253,6 +257,8 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => {
253
257
  const defaultTemplateType = defaultTemplateTypes?.find(
254
258
  ( { slug: _slug } ) => _slug === generalTemplateSlug
255
259
  );
260
+ const hasGeneralTemplate =
261
+ existingTemplateSlugs?.includes( generalTemplateSlug );
256
262
  const _needsUniqueIdentifier = needsUniqueIdentifier( postType );
257
263
  let menuItemTitle =
258
264
  labels.template_name ||
@@ -333,12 +339,14 @@ export const usePostTypeMenuItems = ( onClickMenuItem ) => {
333
339
  },
334
340
  },
335
341
  labels,
342
+ hasGeneralTemplate,
336
343
  template,
337
344
  } );
338
345
  };
339
346
  }
340
- // We don't need to add the menu item if there are no entities.
341
- if ( hasEntities ) {
347
+ // We don't need to add the menu item if there are no
348
+ // entities and the general template exists.
349
+ if ( ! hasGeneralTemplate || hasEntities ) {
342
350
  accumulator.push( menuItem );
343
351
  }
344
352
  return accumulator;
@@ -571,11 +579,7 @@ export function useAuthorMenuItem( onClickMenuItem ) {
571
579
  suggestion.slug
572
580
  );
573
581
  return {
574
- title: sprintf(
575
- // translators: %s: Name of the author e.g: "Admin".
576
- __( 'Author: %s' ),
577
- suggestion.name
578
- ),
582
+ title: templateSlug,
579
583
  slug: templateSlug,
580
584
  templatePrefix: 'author',
581
585
  };
@@ -597,6 +601,91 @@ export function useAuthorMenuItem( onClickMenuItem ) {
597
601
  }
598
602
  }
599
603
 
604
+ /**
605
+ * Helper hook that filters all the existing templates by the given
606
+ * object with the entity's slug as key and the template prefix as value.
607
+ *
608
+ * Example:
609
+ * `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]
610
+ * `templatePrefixes` is: { post_tag: 'tag' }
611
+ * It will return: { post_tag: ['apple'] }
612
+ *
613
+ * Note: We append the `-` to the given template prefix in this function for our checks.
614
+ *
615
+ * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
616
+ * @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.
617
+ */
618
+ const useExistingTemplateSlugs = ( templatePrefixes ) => {
619
+ const existingTemplates = useExistingTemplates();
620
+ const existingSlugs = useMemo( () => {
621
+ return Object.entries( templatePrefixes || {} ).reduce(
622
+ ( accumulator, [ slug, prefix ] ) => {
623
+ const slugsWithTemplates = ( existingTemplates || [] ).reduce(
624
+ ( _accumulator, existingTemplate ) => {
625
+ const _prefix = `${ prefix }-`;
626
+ if ( existingTemplate.slug.startsWith( _prefix ) ) {
627
+ _accumulator.push(
628
+ existingTemplate.slug.substring(
629
+ _prefix.length
630
+ )
631
+ );
632
+ }
633
+ return _accumulator;
634
+ },
635
+ []
636
+ );
637
+ if ( slugsWithTemplates.length ) {
638
+ accumulator[ slug ] = slugsWithTemplates;
639
+ }
640
+ return accumulator;
641
+ },
642
+ {}
643
+ );
644
+ }, [ templatePrefixes, existingTemplates ] );
645
+ return existingSlugs;
646
+ };
647
+
648
+ /**
649
+ * Helper hook that finds the existing records with an associated template,
650
+ * as they need to be excluded from the template suggestions.
651
+ *
652
+ * @param {string} entityName The entity's name.
653
+ * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
654
+ * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.
655
+ * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.
656
+ */
657
+ const useTemplatesToExclude = (
658
+ entityName,
659
+ templatePrefixes,
660
+ additionalQueryParameters = {}
661
+ ) => {
662
+ const slugsToExcludePerEntity =
663
+ useExistingTemplateSlugs( templatePrefixes );
664
+ const recordsToExcludePerEntity = useSelect(
665
+ ( select ) => {
666
+ return Object.entries( slugsToExcludePerEntity || {} ).reduce(
667
+ ( accumulator, [ slug, slugsWithTemplates ] ) => {
668
+ const entitiesWithTemplates = select(
669
+ coreStore
670
+ ).getEntityRecords( entityName, slug, {
671
+ _fields: 'id',
672
+ context: 'view',
673
+ slug: slugsWithTemplates,
674
+ ...additionalQueryParameters[ slug ],
675
+ } );
676
+ if ( entitiesWithTemplates?.length ) {
677
+ accumulator[ slug ] = entitiesWithTemplates;
678
+ }
679
+ return accumulator;
680
+ },
681
+ {}
682
+ );
683
+ },
684
+ [ slugsToExcludePerEntity ]
685
+ );
686
+ return recordsToExcludePerEntity;
687
+ };
688
+
600
689
  /**
601
690
  * Helper hook that returns information about an entity having
602
691
  * records that we can create a specific template for.
@@ -617,16 +706,26 @@ const useEntitiesInfo = (
617
706
  templatePrefixes,
618
707
  additionalQueryParameters = EMPTY_OBJECT
619
708
  ) => {
709
+ const recordsToExcludePerEntity = useTemplatesToExclude(
710
+ entityName,
711
+ templatePrefixes,
712
+ additionalQueryParameters
713
+ );
620
714
  const entitiesHasRecords = useSelect(
621
715
  ( select ) => {
622
716
  return Object.keys( templatePrefixes || {} ).reduce(
623
717
  ( accumulator, slug ) => {
718
+ const existingEntitiesIds =
719
+ recordsToExcludePerEntity?.[ slug ]?.map(
720
+ ( { id } ) => id
721
+ ) || [];
624
722
  accumulator[ slug ] = !! select(
625
723
  coreStore
626
724
  ).getEntityRecords( entityName, slug, {
627
725
  per_page: 1,
628
726
  _fields: 'id',
629
727
  context: 'view',
728
+ exclude: existingEntitiesIds,
630
729
  ...additionalQueryParameters[ slug ],
631
730
  } )?.length;
632
731
  return accumulator;
@@ -634,18 +733,28 @@ const useEntitiesInfo = (
634
733
  {}
635
734
  );
636
735
  },
637
- [ templatePrefixes, entityName, additionalQueryParameters ]
736
+ [
737
+ templatePrefixes,
738
+ recordsToExcludePerEntity,
739
+ entityName,
740
+ additionalQueryParameters,
741
+ ]
638
742
  );
639
743
  const entitiesInfo = useMemo( () => {
640
744
  return Object.keys( templatePrefixes || {} ).reduce(
641
745
  ( accumulator, slug ) => {
746
+ const existingEntitiesIds =
747
+ recordsToExcludePerEntity?.[ slug ]?.map(
748
+ ( { id } ) => id
749
+ ) || [];
642
750
  accumulator[ slug ] = {
643
751
  hasEntities: entitiesHasRecords[ slug ],
752
+ existingEntitiesIds,
644
753
  };
645
754
  return accumulator;
646
755
  },
647
756
  {}
648
757
  );
649
- }, [ templatePrefixes, entitiesHasRecords ] );
758
+ }, [ templatePrefixes, recordsToExcludePerEntity, entitiesHasRecords ] );
650
759
  return entitiesInfo;
651
760
  };
@@ -5,8 +5,6 @@ import { __ } from '@wordpress/i18n';
5
5
  import { pencil } from '@wordpress/icons';
6
6
  import { useMemo } from '@wordpress/element';
7
7
  import { privateApis as routerPrivateApis } from '@wordpress/router';
8
- import { useDispatch, useSelect } from '@wordpress/data';
9
- import { store as coreStore } from '@wordpress/core-data';
10
8
 
11
9
  /**
12
10
  * Internal dependencies
@@ -16,65 +14,6 @@ import { unlock } from '../../lock-unlock';
16
14
 
17
15
  const { useHistory } = unlock( routerPrivateApis );
18
16
 
19
- export const useSetActiveTemplateAction = () => {
20
- const activeTheme = useSelect( ( select ) =>
21
- select( coreStore ).getCurrentTheme()
22
- );
23
- const { getEntityRecord } = useSelect( coreStore );
24
- const { editEntityRecord, saveEditedEntityRecord } =
25
- useDispatch( coreStore );
26
- return useMemo(
27
- () => ( {
28
- id: 'set-active-template',
29
- label( items ) {
30
- return items.some( ( item ) => item._isActive )
31
- ? __( 'Deactivate' )
32
- : __( 'Activate' );
33
- },
34
- isPrimary: true,
35
- icon: pencil,
36
- isEligible( item ) {
37
- if ( item.theme !== activeTheme.stylesheet ) {
38
- return false;
39
- }
40
-
41
- // If it's not a created template but a registered template,
42
- // only allow activating (so when it's inactive).
43
- if ( typeof item.id !== 'number' ) {
44
- return item._isActive === false;
45
- }
46
-
47
- return true;
48
- },
49
- async callback( items ) {
50
- const deactivate = items.some( ( item ) => item._isActive );
51
- // current active templates
52
- const activeTemplates = {
53
- ...( ( await getEntityRecord( 'root', 'site' )
54
- .active_templates ) ?? {} ),
55
- };
56
- for ( const item of items ) {
57
- if ( deactivate ) {
58
- delete activeTemplates[ item.slug ];
59
- } else {
60
- activeTemplates[ item.slug ] = item.id;
61
- }
62
- }
63
- await editEntityRecord( 'root', 'site', undefined, {
64
- active_templates: activeTemplates,
65
- } );
66
- await saveEditedEntityRecord( 'root', 'site' );
67
- },
68
- } ),
69
- [
70
- editEntityRecord,
71
- saveEditedEntityRecord,
72
- getEntityRecord,
73
- activeTheme,
74
- ]
75
- );
76
- };
77
-
78
17
  export const useEditPostAction = () => {
79
18
  const history = useHistory();
80
19
  return useMemo(
@@ -110,7 +110,6 @@ function getNavigationPath( location, postType ) {
110
110
  'template-part-item',
111
111
  'page-item',
112
112
  'template-item',
113
- 'static-template-item',
114
113
  'post-item',
115
114
  ].includes( name )
116
115
  ) {
@@ -29,7 +29,9 @@ const postTypesWithoutParentTemplate = [
29
29
 
30
30
  const authorizedPostTypes = [ 'page', 'post' ];
31
31
 
32
- function getPostType( name ) {
32
+ export function useResolveEditedEntity() {
33
+ const { name, params = {}, query } = useLocation();
34
+ const { postId = query?.postId } = params; // Fallback to query param for postId for list view routes.
33
35
  let postType;
34
36
  if ( name === 'navigation-item' ) {
35
37
  postType = NAVIGATION_POST_TYPE;
@@ -37,9 +39,7 @@ function getPostType( name ) {
37
39
  postType = PATTERN_TYPES.user;
38
40
  } else if ( name === 'template-part-item' ) {
39
41
  postType = TEMPLATE_PART_POST_TYPE;
40
- } else if ( name === 'templates' ) {
41
- postType = TEMPLATE_POST_TYPE;
42
- } else if ( name === 'template-item' ) {
42
+ } else if ( name === 'template-item' || name === 'templates' ) {
43
43
  postType = TEMPLATE_POST_TYPE;
44
44
  } else if ( name === 'page-item' || name === 'pages' ) {
45
45
  postType = 'page';
@@ -47,14 +47,6 @@ function getPostType( name ) {
47
47
  postType = 'post';
48
48
  }
49
49
 
50
- return postType;
51
- }
52
-
53
- export function useResolveEditedEntity() {
54
- const { name, params = {}, query } = useLocation();
55
- const { postId = query?.postId } = params; // Fallback to query param for postId for list view routes.
56
- const postType = getPostType( name, postId ) ?? query?.postType;
57
-
58
50
  const homePage = useSelect( ( select ) => {
59
51
  const { getHomePage } = unlock( select( coreDataStore ) );
60
52
  return getHomePage();
@@ -149,14 +141,7 @@ export function useSyncDeprecatedEntityIntoState( {
149
141
 
150
142
  useEffect( () => {
151
143
  if ( isReady ) {
152
- // setEditedEntity expects a string (because the postId used to be
153
- // the template slug, even for edited templates). Now the postId can
154
- // be a number (either because it's an auto-draft or edited
155
- // template). Passing a number could break plugins doing things like
156
- // `id.includes`. It would be way more complex to keep passing the
157
- // template slug, while also being incorrect, so the easiest
158
- // solution is to cast the postId to a string.
159
- setEditedEntity( postType, String( postId ), context );
144
+ setEditedEntity( postType, postId, context );
160
145
  }
161
146
  }, [ isReady, postType, postId, context, setEditedEntity ] );
162
147
  }
@@ -6,12 +6,8 @@ import clsx from 'clsx';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import {
10
- Icon,
11
- __experimentalHStack as HStack,
12
- privateApis as componentsPrivateApis,
13
- } from '@wordpress/components';
14
- import { __, _x } from '@wordpress/i18n';
9
+ import { Icon, __experimentalHStack as HStack } from '@wordpress/components';
10
+ import { __ } from '@wordpress/i18n';
15
11
  import { useState, useMemo } from '@wordpress/element';
16
12
  import { decodeEntities } from '@wordpress/html-entities';
17
13
  import { parse } from '@wordpress/blocks';
@@ -20,43 +16,15 @@ import {
20
16
  privateApis as blockEditorPrivateApis,
21
17
  } from '@wordpress/block-editor';
22
18
  import { EditorProvider } from '@wordpress/editor';
23
- import {
24
- privateApis as corePrivateApis,
25
- store as coreStore,
26
- } from '@wordpress/core-data';
27
- import { useSelect } from '@wordpress/data';
28
19
 
29
20
  /**
30
21
  * Internal dependencies
31
22
  */
32
23
  import { useAddedBy } from './hooks';
33
- import { useDefaultTemplateTypes } from '../add-new-template/utils';
34
24
  import usePatternSettings from '../page-patterns/use-pattern-settings';
35
25
  import { unlock } from '../../lock-unlock';
36
26
 
37
27
  const { useGlobalStyle } = unlock( blockEditorPrivateApis );
38
- const { Badge } = unlock( componentsPrivateApis );
39
- const { useEntityRecordsWithPermissions } = unlock( corePrivateApis );
40
-
41
- function useAllDefaultTemplateTypes() {
42
- const defaultTemplateTypes = useDefaultTemplateTypes();
43
- const { records: staticRecords } = useEntityRecordsWithPermissions(
44
- 'root',
45
- 'registeredTemplate'
46
- );
47
- return [
48
- ...defaultTemplateTypes,
49
- ...staticRecords
50
- ?.filter( ( record ) => ! record.is_custom )
51
- .map( ( record ) => {
52
- return {
53
- slug: record.slug,
54
- title: record.title.rendered,
55
- description: record.description,
56
- };
57
- } ),
58
- ];
59
- }
60
28
 
61
29
  function PreviewField( { item } ) {
62
30
  const settings = usePatternSettings();
@@ -100,14 +68,8 @@ export const previewField = {
100
68
  export const descriptionField = {
101
69
  label: __( 'Description' ),
102
70
  id: 'description',
103
- render: function RenderDescription( { item } ) {
104
- const defaultTemplateTypes = useAllDefaultTemplateTypes();
105
- const defaultTemplateType = defaultTemplateTypes.find(
106
- ( type ) => type.slug === item.slug
107
- );
108
- return item.description
109
- ? decodeEntities( item.description )
110
- : defaultTemplateType?.description;
71
+ render: ( { item } ) => {
72
+ return item.description && decodeEntities( item.description );
111
73
  },
112
74
  enableSorting: false,
113
75
  enableGlobalSearch: true,
@@ -145,58 +107,6 @@ function AuthorField( { item } ) {
145
107
  export const authorField = {
146
108
  label: __( 'Author' ),
147
109
  id: 'author',
148
- getValue: ( { item } ) => item.author_text ?? item.author,
110
+ getValue: ( { item } ) => item.author_text,
149
111
  render: AuthorField,
150
112
  };
151
-
152
- export const activeField = {
153
- label: __( 'Status' ),
154
- id: 'active',
155
- type: 'boolean',
156
- getValue: ( { item } ) => item._isActive,
157
- render: function Render( { item } ) {
158
- const activeLabel = item._isCustom
159
- ? _x( 'Active when used', 'template' )
160
- : _x( 'Active', 'template' );
161
- const activeIntent = item._isCustom ? 'info' : 'success';
162
- const isActive = item._isActive;
163
- return (
164
- <Badge intent={ isActive ? activeIntent : 'default' }>
165
- { isActive ? activeLabel : _x( 'Inactive', 'template' ) }
166
- </Badge>
167
- );
168
- },
169
- };
170
-
171
- export const useThemeField = () => {
172
- const activeTheme = useSelect( ( select ) =>
173
- select( coreStore ).getCurrentTheme()
174
- );
175
- return useMemo(
176
- () => ( {
177
- label: __( 'Compatible Theme' ),
178
- id: 'theme',
179
- getValue: ( { item } ) => item.theme,
180
- render: function Render( { item } ) {
181
- if ( item.theme === activeTheme.stylesheet ) {
182
- return <Badge intent="success">{ item.theme }</Badge>;
183
- }
184
- return <Badge intent="error">{ item.theme }</Badge>;
185
- },
186
- } ),
187
- [ activeTheme ]
188
- );
189
- };
190
-
191
- export const slugField = {
192
- label: __( 'Template Type' ),
193
- id: 'slug',
194
- getValue: ( { item } ) => item.slug,
195
- render: function Render( { item } ) {
196
- const defaultTemplateTypes = useAllDefaultTemplateTypes();
197
- const defaultTemplateType = defaultTemplateTypes.find(
198
- ( type ) => type.slug === item.slug
199
- );
200
- return defaultTemplateType?.title || _x( 'Custom', 'template type' );
201
- },
202
- };
@@ -89,7 +89,7 @@ export function useAddedBy( postType, postId ) {
89
89
  type: 'user',
90
90
  icon: authorIcon,
91
91
  imageUrl: user?.avatar_urls?.[ 48 ],
92
- text: authorText ?? user?.name,
92
+ text: authorText,
93
93
  isCustomized: false,
94
94
  };
95
95
  }