@wordpress/edit-site 6.33.5 → 6.33.7

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 (70) 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-patterns/index.js +1 -1
  14. package/build/components/page-patterns/index.js.map +2 -2
  15. package/build/components/page-templates/fields.js +5 -80
  16. package/build/components/page-templates/fields.js.map +3 -3
  17. package/build/components/page-templates/hooks.js +1 -1
  18. package/build/components/page-templates/hooks.js.map +2 -2
  19. package/build/components/page-templates/index.js +46 -217
  20. package/build/components/page-templates/index.js.map +3 -3
  21. package/build/components/page-templates/view-utils.js +1 -5
  22. package/build/components/page-templates/view-utils.js.map +2 -2
  23. package/build/components/sidebar-navigation-screen-templates-browse/content.js +6 -21
  24. package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
  25. package/build/components/site-editor-routes/template-item.js +14 -15
  26. package/build/components/site-editor-routes/template-item.js.map +2 -2
  27. package/build-module/components/add-new-template/add-custom-template-modal-content.js +3 -1
  28. package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +2 -2
  29. package/build-module/components/add-new-template/index.js +7 -4
  30. package/build-module/components/add-new-template/index.js.map +2 -2
  31. package/build-module/components/add-new-template/utils.js +84 -9
  32. package/build-module/components/add-new-template/utils.js.map +2 -2
  33. package/build-module/components/dataviews-actions/index.js +1 -53
  34. package/build-module/components/dataviews-actions/index.js.map +2 -2
  35. package/build-module/components/editor/index.js +0 -1
  36. package/build-module/components/editor/index.js.map +2 -2
  37. package/build-module/components/editor/use-resolve-edited-entity.js +5 -11
  38. package/build-module/components/editor/use-resolve-edited-entity.js.map +2 -2
  39. package/build-module/components/page-patterns/index.js +1 -1
  40. package/build-module/components/page-patterns/index.js.map +2 -2
  41. package/build-module/components/page-templates/fields.js +6 -85
  42. package/build-module/components/page-templates/fields.js.map +3 -3
  43. package/build-module/components/page-templates/hooks.js +1 -1
  44. package/build-module/components/page-templates/hooks.js.map +2 -2
  45. package/build-module/components/page-templates/index.js +51 -235
  46. package/build-module/components/page-templates/index.js.map +2 -2
  47. package/build-module/components/page-templates/view-utils.js +1 -5
  48. package/build-module/components/page-templates/view-utils.js.map +2 -2
  49. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +7 -22
  50. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +2 -2
  51. package/build-module/components/site-editor-routes/template-item.js +14 -15
  52. package/build-module/components/site-editor-routes/template-item.js.map +2 -2
  53. package/build-style/posts-rtl.css +6 -1
  54. package/build-style/posts.css +6 -1
  55. package/build-style/style-rtl.css +6 -1
  56. package/build-style/style.css +6 -1
  57. package/package.json +17 -17
  58. package/src/components/add-new-template/add-custom-template-modal-content.js +3 -1
  59. package/src/components/add-new-template/index.js +9 -4
  60. package/src/components/add-new-template/utils.js +118 -9
  61. package/src/components/dataviews-actions/index.js +0 -61
  62. package/src/components/editor/index.js +0 -1
  63. package/src/components/editor/use-resolve-edited-entity.js +5 -20
  64. package/src/components/page-patterns/index.js +1 -1
  65. package/src/components/page-templates/fields.js +5 -95
  66. package/src/components/page-templates/hooks.js +1 -1
  67. package/src/components/page-templates/index.js +35 -244
  68. package/src/components/page-templates/view-utils.js +1 -8
  69. package/src/components/sidebar-navigation-screen-templates-browse/content.js +7 -22
  70. package/src/components/site-editor-routes/template-item.js +26 -28
@@ -1758,7 +1758,6 @@ div.dataviews-view-list {
1758
1758
  .dataviews-view-table td.dataviews-view-table__checkbox-column,
1759
1759
  .dataviews-view-table th.dataviews-view-table__checkbox-column {
1760
1760
  padding-right: 0;
1761
- width: 1%;
1762
1761
  }
1763
1762
 
1764
1763
  .dataviews-view-table td.dataviews-view-table__checkbox-column .dataviews-view-table__cell-content-wrapper,
@@ -1880,6 +1879,7 @@ div.dataviews-view-list {
1880
1879
  min-height: 32px;
1881
1880
  display: flex;
1882
1881
  align-items: center;
1882
+ white-space: nowrap;
1883
1883
  }
1884
1884
 
1885
1885
  .dataviews-view-table tbody .dataviews-view-table__cell-content-wrapper.dataviews-view-table__cell-align-end {
@@ -2003,6 +2003,11 @@ div.dataviews-view-list {
2003
2003
  color: #1e1e1e;
2004
2004
  }
2005
2005
 
2006
+ /* Column width intents via colgroup: make non-primary columns shrink-to-fit */
2007
+ .dataviews-view-table col[class^=dataviews-view-table__col-]:not(.dataviews-view-table__col-primary) {
2008
+ width: 1%;
2009
+ }
2010
+
2006
2011
  .dataviews-view-picker-grid .dataviews-view-picker-grid__card {
2007
2012
  height: 100%;
2008
2013
  justify-content: flex-start;
@@ -1758,7 +1758,6 @@ div.dataviews-view-list {
1758
1758
  .dataviews-view-table td.dataviews-view-table__checkbox-column,
1759
1759
  .dataviews-view-table th.dataviews-view-table__checkbox-column {
1760
1760
  padding-left: 0;
1761
- width: 1%;
1762
1761
  }
1763
1762
 
1764
1763
  .dataviews-view-table td.dataviews-view-table__checkbox-column .dataviews-view-table__cell-content-wrapper,
@@ -1880,6 +1879,7 @@ div.dataviews-view-list {
1880
1879
  min-height: 32px;
1881
1880
  display: flex;
1882
1881
  align-items: center;
1882
+ white-space: nowrap;
1883
1883
  }
1884
1884
 
1885
1885
  .dataviews-view-table tbody .dataviews-view-table__cell-content-wrapper.dataviews-view-table__cell-align-end {
@@ -2003,6 +2003,11 @@ div.dataviews-view-list {
2003
2003
  color: #1e1e1e;
2004
2004
  }
2005
2005
 
2006
+ /* Column width intents via colgroup: make non-primary columns shrink-to-fit */
2007
+ .dataviews-view-table col[class^=dataviews-view-table__col-]:not(.dataviews-view-table__col-primary) {
2008
+ width: 1%;
2009
+ }
2010
+
2006
2011
  .dataviews-view-picker-grid .dataviews-view-picker-grid__card {
2007
2012
  height: 100%;
2008
2013
  justify-content: flex-start;
@@ -1758,7 +1758,6 @@ div.dataviews-view-list {
1758
1758
  .dataviews-view-table td.dataviews-view-table__checkbox-column,
1759
1759
  .dataviews-view-table th.dataviews-view-table__checkbox-column {
1760
1760
  padding-right: 0;
1761
- width: 1%;
1762
1761
  }
1763
1762
 
1764
1763
  .dataviews-view-table td.dataviews-view-table__checkbox-column .dataviews-view-table__cell-content-wrapper,
@@ -1880,6 +1879,7 @@ div.dataviews-view-list {
1880
1879
  min-height: 32px;
1881
1880
  display: flex;
1882
1881
  align-items: center;
1882
+ white-space: nowrap;
1883
1883
  }
1884
1884
 
1885
1885
  .dataviews-view-table tbody .dataviews-view-table__cell-content-wrapper.dataviews-view-table__cell-align-end {
@@ -2003,6 +2003,11 @@ div.dataviews-view-list {
2003
2003
  color: #1e1e1e;
2004
2004
  }
2005
2005
 
2006
+ /* Column width intents via colgroup: make non-primary columns shrink-to-fit */
2007
+ .dataviews-view-table col[class^=dataviews-view-table__col-]:not(.dataviews-view-table__col-primary) {
2008
+ width: 1%;
2009
+ }
2010
+
2006
2011
  .dataviews-view-picker-grid .dataviews-view-picker-grid__card {
2007
2012
  height: 100%;
2008
2013
  justify-content: flex-start;
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.7",
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.3",
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.5",
46
+ "@wordpress/block-library": "^9.33.6",
47
47
  "@wordpress/blocks": "^15.6.1",
48
- "@wordpress/commands": "^1.33.1",
49
- "@wordpress/components": "^30.6.1",
48
+ "@wordpress/commands": "^1.33.3",
49
+ "@wordpress/components": "^30.6.3",
50
50
  "@wordpress/compose": "^7.33.1",
51
- "@wordpress/core-data": "^7.33.3",
51
+ "@wordpress/core-data": "^7.33.5",
52
52
  "@wordpress/data": "^10.33.1",
53
- "@wordpress/dataviews": "^10.1.2",
53
+ "@wordpress/dataviews": "^10.1.4",
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.7",
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.7",
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.5",
70
+ "@wordpress/plugins": "^7.33.3",
71
+ "@wordpress/preferences": "^4.33.3",
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.5",
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.5",
80
+ "@wordpress/widgets": "^4.33.5",
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": "36643498e343222da980e5ae235d2f8630ad6b4f"
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
  }
@@ -106,7 +106,7 @@ export default function DataviewsPatterns() {
106
106
  slug: categoryId,
107
107
  defaultView: DEFAULT_VIEW,
108
108
  queryParams: {
109
- page: Number( query.pageNumber ?? 1 ),
109
+ page: query.pageNumber,
110
110
  search: query.search,
111
111
  },
112
112
  onChangeQueryParams: ( params ) => {