@wordpress/edit-site 6.4.0 → 6.5.0

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 (198) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-pattern/index.js +6 -1
  3. package/build/components/add-new-pattern/index.js.map +1 -1
  4. package/build/components/add-new-post/index.js +2 -1
  5. package/build/components/add-new-post/index.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +2 -2
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/editor/index.js +71 -20
  9. package/build/components/editor/index.js.map +1 -1
  10. package/build/components/global-styles/font-families.js +3 -4
  11. package/build/components/global-styles/font-families.js.map +1 -1
  12. package/build/components/global-styles/font-library-modal/context.js +0 -5
  13. package/build/components/global-styles/font-library-modal/context.js.map +1 -1
  14. package/build/components/global-styles/font-library-modal/font-collection.js +25 -5
  15. package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  16. package/build/components/global-styles/font-library-modal/index.js +1 -8
  17. package/build/components/global-styles/font-library-modal/index.js.map +1 -1
  18. package/build/components/global-styles/font-library-modal/installed-fonts.js +21 -6
  19. package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  20. package/build/components/global-styles/font-library-modal/upload-fonts.js +2 -3
  21. package/build/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
  22. package/build/components/global-styles/screen-typeset.js +40 -0
  23. package/build/components/global-styles/screen-typeset.js.map +1 -0
  24. package/build/components/global-styles/screen-typography-element.js +14 -0
  25. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  26. package/build/components/global-styles/screen-typography.js +4 -6
  27. package/build/components/global-styles/screen-typography.js.map +1 -1
  28. package/build/components/global-styles/shadows-edit-panel.js +50 -59
  29. package/build/components/global-styles/shadows-edit-panel.js.map +1 -1
  30. package/build/components/global-styles/typeset-button.js +97 -0
  31. package/build/components/global-styles/typeset-button.js.map +1 -0
  32. package/build/components/global-styles/typeset.js +80 -0
  33. package/build/components/global-styles/typeset.js.map +1 -0
  34. package/build/components/global-styles/ui.js +4 -0
  35. package/build/components/global-styles/ui.js.map +1 -1
  36. package/build/components/global-styles/utils.js +10 -1
  37. package/build/components/global-styles/utils.js.map +1 -1
  38. package/build/components/page-patterns/fields.js +230 -0
  39. package/build/components/page-patterns/fields.js.map +1 -0
  40. package/build/components/page-patterns/index.js +8 -226
  41. package/build/components/page-patterns/index.js.map +1 -1
  42. package/build/components/page-patterns/use-patterns.js +26 -1
  43. package/build/components/page-patterns/use-patterns.js.map +1 -1
  44. package/build/components/page-templates/fields.js +169 -0
  45. package/build/components/page-templates/fields.js.map +1 -0
  46. package/build/components/page-templates/index.js +10 -177
  47. package/build/components/page-templates/index.js.map +1 -1
  48. package/build/components/post-edit/index.js +18 -6
  49. package/build/components/post-edit/index.js.map +1 -1
  50. package/build/components/post-fields/index.js +19 -15
  51. package/build/components/post-fields/index.js.map +1 -1
  52. package/build/components/post-list/index.js +125 -67
  53. package/build/components/post-list/index.js.map +1 -1
  54. package/build/components/sidebar-dataviews/add-new-view.js +2 -2
  55. package/build/components/sidebar-dataviews/add-new-view.js.map +1 -1
  56. package/build/components/sidebar-dataviews/dataview-item.js +2 -3
  57. package/build/components/sidebar-dataviews/dataview-item.js.map +1 -1
  58. package/build/components/sidebar-dataviews/default-views.js +81 -81
  59. package/build/components/sidebar-dataviews/default-views.js.map +1 -1
  60. package/build/components/sidebar-dataviews/index.js +3 -42
  61. package/build/components/sidebar-dataviews/index.js.map +1 -1
  62. package/build/components/site-hub/index.js +6 -3
  63. package/build/components/site-hub/index.js.map +1 -1
  64. package/build/components/style-book/index.js +22 -25
  65. package/build/components/style-book/index.js.map +1 -1
  66. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js +5 -0
  67. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
  68. package/build/hooks/push-changes-to-global-styles/index.js +2 -3
  69. package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
  70. package/build/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +2 -4
  71. package/build/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js.map +1 -1
  72. package/build/index.js +0 -2
  73. package/build/index.js.map +1 -1
  74. package/build-module/components/add-new-pattern/index.js +6 -1
  75. package/build-module/components/add-new-pattern/index.js.map +1 -1
  76. package/build-module/components/add-new-post/index.js +2 -1
  77. package/build-module/components/add-new-post/index.js.map +1 -1
  78. package/build-module/components/add-new-template/utils.js +2 -2
  79. package/build-module/components/add-new-template/utils.js.map +1 -1
  80. package/build-module/components/editor/index.js +73 -22
  81. package/build-module/components/editor/index.js.map +1 -1
  82. package/build-module/components/global-styles/font-families.js +3 -4
  83. package/build-module/components/global-styles/font-families.js.map +1 -1
  84. package/build-module/components/global-styles/font-library-modal/context.js +0 -5
  85. package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
  86. package/build-module/components/global-styles/font-library-modal/font-collection.js +26 -6
  87. package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  88. package/build-module/components/global-styles/font-library-modal/index.js +1 -8
  89. package/build-module/components/global-styles/font-library-modal/index.js.map +1 -1
  90. package/build-module/components/global-styles/font-library-modal/installed-fonts.js +21 -6
  91. package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  92. package/build-module/components/global-styles/font-library-modal/upload-fonts.js +2 -3
  93. package/build-module/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
  94. package/build-module/components/global-styles/screen-typeset.js +34 -0
  95. package/build-module/components/global-styles/screen-typeset.js.map +1 -0
  96. package/build-module/components/global-styles/screen-typography-element.js +14 -0
  97. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  98. package/build-module/components/global-styles/screen-typography.js +4 -6
  99. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  100. package/build-module/components/global-styles/shadows-edit-panel.js +51 -60
  101. package/build-module/components/global-styles/shadows-edit-panel.js.map +1 -1
  102. package/build-module/components/global-styles/typeset-button.js +89 -0
  103. package/build-module/components/global-styles/typeset-button.js.map +1 -0
  104. package/build-module/components/global-styles/typeset.js +71 -0
  105. package/build-module/components/global-styles/typeset.js.map +1 -0
  106. package/build-module/components/global-styles/ui.js +4 -0
  107. package/build-module/components/global-styles/ui.js.map +1 -1
  108. package/build-module/components/global-styles/utils.js +10 -1
  109. package/build-module/components/global-styles/utils.js.map +1 -1
  110. package/build-module/components/page-patterns/fields.js +223 -0
  111. package/build-module/components/page-patterns/fields.js.map +1 -0
  112. package/build-module/components/page-patterns/index.js +11 -229
  113. package/build-module/components/page-patterns/index.js.map +1 -1
  114. package/build-module/components/page-patterns/use-patterns.js +26 -1
  115. package/build-module/components/page-patterns/use-patterns.js.map +1 -1
  116. package/build-module/components/page-templates/fields.js +160 -0
  117. package/build-module/components/page-templates/fields.js.map +1 -0
  118. package/build-module/components/page-templates/index.js +12 -178
  119. package/build-module/components/page-templates/index.js.map +1 -1
  120. package/build-module/components/post-edit/index.js +20 -8
  121. package/build-module/components/post-edit/index.js.map +1 -1
  122. package/build-module/components/post-fields/index.js +19 -15
  123. package/build-module/components/post-fields/index.js.map +1 -1
  124. package/build-module/components/post-list/index.js +127 -69
  125. package/build-module/components/post-list/index.js.map +1 -1
  126. package/build-module/components/sidebar-dataviews/add-new-view.js +2 -2
  127. package/build-module/components/sidebar-dataviews/add-new-view.js.map +1 -1
  128. package/build-module/components/sidebar-dataviews/dataview-item.js +2 -3
  129. package/build-module/components/sidebar-dataviews/dataview-item.js.map +1 -1
  130. package/build-module/components/sidebar-dataviews/default-views.js +81 -81
  131. package/build-module/components/sidebar-dataviews/default-views.js.map +1 -1
  132. package/build-module/components/sidebar-dataviews/index.js +3 -42
  133. package/build-module/components/sidebar-dataviews/index.js.map +1 -1
  134. package/build-module/components/site-hub/index.js +7 -4
  135. package/build-module/components/site-hub/index.js.map +1 -1
  136. package/build-module/components/style-book/index.js +23 -26
  137. package/build-module/components/style-book/index.js.map +1 -1
  138. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js +5 -0
  139. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
  140. package/build-module/hooks/push-changes-to-global-styles/index.js +2 -3
  141. package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
  142. package/build-module/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +2 -3
  143. package/build-module/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js.map +1 -1
  144. package/build-module/index.js +0 -2
  145. package/build-module/index.js.map +1 -1
  146. package/build-style/posts-rtl.css +190 -11
  147. package/build-style/posts.css +190 -11
  148. package/build-style/style-rtl.css +296 -55
  149. package/build-style/style.css +296 -55
  150. package/package.json +41 -41
  151. package/src/components/add-new-pattern/index.js +8 -3
  152. package/src/components/add-new-post/index.js +2 -1
  153. package/src/components/add-new-template/utils.js +10 -6
  154. package/src/components/editor/index.js +80 -22
  155. package/src/components/editor/style.scss +59 -1
  156. package/src/components/global-styles/font-families.js +3 -5
  157. package/src/components/global-styles/font-library-modal/context.js +0 -5
  158. package/src/components/global-styles/font-library-modal/font-collection.js +34 -10
  159. package/src/components/global-styles/font-library-modal/index.js +2 -7
  160. package/src/components/global-styles/font-library-modal/installed-fonts.js +23 -5
  161. package/src/components/global-styles/font-library-modal/style.scss +1 -1
  162. package/src/components/global-styles/font-library-modal/upload-fonts.js +2 -2
  163. package/src/components/global-styles/screen-typeset.js +42 -0
  164. package/src/components/global-styles/screen-typography-element.js +14 -0
  165. package/src/components/global-styles/screen-typography.js +4 -4
  166. package/src/components/global-styles/shadows-edit-panel.js +66 -73
  167. package/src/components/global-styles/style.scss +4 -7
  168. package/src/components/global-styles/typeset-button.js +93 -0
  169. package/src/components/global-styles/typeset.js +73 -0
  170. package/src/components/global-styles/ui.js +5 -0
  171. package/src/components/global-styles/utils.js +13 -1
  172. package/src/components/layout/style.scss +8 -0
  173. package/src/components/page-patterns/fields.js +251 -0
  174. package/src/components/page-patterns/index.js +15 -244
  175. package/src/components/page-patterns/style.scss +82 -85
  176. package/src/components/page-patterns/use-patterns.js +31 -1
  177. package/src/components/page-templates/fields.js +157 -0
  178. package/src/components/page-templates/index.js +19 -170
  179. package/src/components/page-templates/style.scss +14 -5
  180. package/src/components/post-edit/index.js +27 -8
  181. package/src/components/post-fields/index.js +29 -17
  182. package/src/components/post-list/index.js +134 -74
  183. package/src/components/sidebar-dataviews/add-new-view.js +2 -4
  184. package/src/components/sidebar-dataviews/dataview-item.js +2 -2
  185. package/src/components/sidebar-dataviews/default-views.js +95 -95
  186. package/src/components/sidebar-dataviews/index.js +3 -37
  187. package/src/components/site-hub/index.js +11 -2
  188. package/src/components/site-icon/style.scss +4 -1
  189. package/src/components/style-book/index.js +27 -32
  190. package/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +5 -0
  191. package/src/hooks/push-changes-to-global-styles/index.js +2 -3
  192. package/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +2 -3
  193. package/src/index.js +0 -2
  194. package/build/utils/clone-deep.js +0 -15
  195. package/build/utils/clone-deep.js.map +0 -1
  196. package/build-module/utils/clone-deep.js +0 -9
  197. package/build-module/utils/clone-deep.js.map +0 -1
  198. package/src/utils/clone-deep.js +0 -8
@@ -2,11 +2,14 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { Button } from '@wordpress/components';
5
- import { useEntityRecords, store as coreStore } from '@wordpress/core-data';
5
+ import {
6
+ store as coreStore,
7
+ privateApis as coreDataPrivateApis,
8
+ } from '@wordpress/core-data';
6
9
  import { useState, useMemo, useCallback, useEffect } from '@wordpress/element';
7
10
  import { privateApis as routerPrivateApis } from '@wordpress/router';
8
11
  import { useSelect, useDispatch } from '@wordpress/data';
9
- import { DataViews } from '@wordpress/dataviews';
12
+ import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';
10
13
  import { privateApis as editorPrivateApis } from '@wordpress/editor';
11
14
  import { __ } from '@wordpress/i18n';
12
15
  import { drawerRight } from '@wordpress/icons';
@@ -33,102 +36,139 @@ import usePostFields from '../post-fields';
33
36
 
34
37
  const { usePostActions } = unlock( editorPrivateApis );
35
38
  const { useLocation, useHistory } = unlock( routerPrivateApis );
39
+ const { useEntityRecordsWithPermissions } = unlock( coreDataPrivateApis );
36
40
  const EMPTY_ARRAY = [];
37
41
 
42
+ const getDefaultView = ( defaultViews, activeView ) => {
43
+ return defaultViews.find( ( { slug } ) => slug === activeView )?.view;
44
+ };
45
+
46
+ const getCustomView = ( editedEntityRecord ) => {
47
+ if ( ! editedEntityRecord?.content ) {
48
+ return undefined;
49
+ }
50
+
51
+ const content = JSON.parse( editedEntityRecord.content );
52
+ if ( ! content ) {
53
+ return undefined;
54
+ }
55
+
56
+ return {
57
+ ...content,
58
+ layout: defaultLayouts[ content.type ]?.layout,
59
+ };
60
+ };
61
+
62
+ /**
63
+ * This function abstracts working with default & custom views by
64
+ * providing a [ state, setState ] tuple based on the URL parameters.
65
+ *
66
+ * Consumers use the provided tuple to work with state
67
+ * and don't have to deal with the specifics of default & custom views.
68
+ *
69
+ * @param {string} postType Post type to retrieve default views for.
70
+ * @return {Array} The [ state, setState ] tuple.
71
+ */
38
72
  function useView( postType ) {
39
73
  const {
40
74
  params: { activeView = 'all', isCustom = 'false', layout },
41
75
  } = useLocation();
42
76
  const history = useHistory();
43
- const DEFAULT_VIEWS = useDefaultViews( { postType } );
44
- const selectedDefaultView = useMemo( () => {
45
- const defaultView =
46
- isCustom === 'false' &&
47
- DEFAULT_VIEWS[ postType ].find(
48
- ( { slug } ) => slug === activeView
49
- )?.view;
50
- if ( isCustom === 'false' && layout ) {
51
- return {
52
- ...defaultView,
53
- type: layout,
54
- layout: defaultLayouts[ layout ]?.layout,
55
- };
56
- }
57
- return defaultView;
58
- }, [ isCustom, activeView, layout, postType, DEFAULT_VIEWS ] );
59
- const [ view, setView ] = useState( selectedDefaultView );
60
77
 
61
- useEffect( () => {
62
- if ( selectedDefaultView ) {
63
- setView( selectedDefaultView );
64
- }
65
- }, [ selectedDefaultView ] );
66
- const editedViewRecord = useSelect(
78
+ const defaultViews = useDefaultViews( { postType } );
79
+ const { editEntityRecord } = useDispatch( coreStore );
80
+ const editedEntityRecord = useSelect(
67
81
  ( select ) => {
68
82
  if ( isCustom !== 'true' ) {
69
- return;
83
+ return undefined;
70
84
  }
85
+
71
86
  const { getEditedEntityRecord } = select( coreStore );
72
- const dataviewRecord = getEditedEntityRecord(
87
+ return getEditedEntityRecord(
73
88
  'postType',
74
89
  'wp_dataviews',
75
90
  Number( activeView )
76
91
  );
77
- return dataviewRecord;
78
92
  },
79
93
  [ activeView, isCustom ]
80
94
  );
81
- const { editEntityRecord } = useDispatch( coreStore );
82
-
83
- const customView = useMemo( () => {
84
- const storedView =
85
- editedViewRecord?.content &&
86
- JSON.parse( editedViewRecord?.content );
87
- if ( ! storedView ) {
88
- return storedView;
95
+ const [ view, setView ] = useState( () => {
96
+ let initialView;
97
+ if ( isCustom === 'true' ) {
98
+ initialView = getCustomView( editedEntityRecord ) ?? {
99
+ type: layout ?? LAYOUT_LIST,
100
+ };
101
+ } else {
102
+ initialView = getDefaultView( defaultViews, activeView ) ?? {
103
+ type: layout ?? LAYOUT_LIST,
104
+ };
89
105
  }
90
106
 
107
+ const type = layout ?? initialView.type;
91
108
  return {
92
- ...storedView,
93
- layout: defaultLayouts[ storedView?.type ]?.layout,
109
+ ...initialView,
110
+ type,
94
111
  };
95
- }, [ editedViewRecord?.content ] );
112
+ } );
96
113
 
97
- const setCustomView = useCallback(
98
- ( viewToSet ) => {
99
- editEntityRecord(
100
- 'postType',
101
- 'wp_dataviews',
102
- editedViewRecord?.id,
103
- {
104
- content: JSON.stringify( viewToSet ),
105
- }
106
- );
107
- },
108
- [ editEntityRecord, editedViewRecord?.id ]
109
- );
114
+ const setViewWithUrlUpdate = useCallback(
115
+ ( newView ) => {
116
+ const { params } = history.getLocationWithParams();
110
117
 
111
- const setDefaultViewAndUpdateUrl = useCallback(
112
- ( viewToSet ) => {
113
- if ( viewToSet.type !== view?.type ) {
114
- const { params } = history.getLocationWithParams();
118
+ if ( newView.type === LAYOUT_LIST && ! params?.layout ) {
119
+ // Skip updating the layout URL param if
120
+ // it is not present and the newView.type is LAYOUT_LIST.
121
+ } else if ( newView.type !== params?.layout ) {
115
122
  history.push( {
116
123
  ...params,
117
- layout: viewToSet.type,
124
+ layout: newView.type,
118
125
  } );
119
126
  }
120
- setView( viewToSet );
127
+
128
+ setView( newView );
129
+
130
+ if ( isCustom === 'true' && editedEntityRecord?.id ) {
131
+ editEntityRecord(
132
+ 'postType',
133
+ 'wp_dataviews',
134
+ editedEntityRecord?.id,
135
+ {
136
+ content: JSON.stringify( newView ),
137
+ }
138
+ );
139
+ }
121
140
  },
122
- [ history, view?.type ]
141
+ [ history, isCustom, editEntityRecord, editedEntityRecord?.id ]
123
142
  );
124
143
 
125
- if ( isCustom === 'false' ) {
126
- return [ view, setDefaultViewAndUpdateUrl ];
127
- } else if ( isCustom === 'true' && customView ) {
128
- return [ customView, setCustomView ];
129
- }
130
- // Loading state where no the view was not found on custom views or default views.
131
- return [ DEFAULT_VIEWS[ postType ][ 0 ].view, setDefaultViewAndUpdateUrl ];
144
+ // When layout URL param changes, update the view type
145
+ // without affecting any other config.
146
+ useEffect( () => {
147
+ setView( ( prevView ) => ( {
148
+ ...prevView,
149
+ type: layout ?? LAYOUT_LIST,
150
+ } ) );
151
+ }, [ layout ] );
152
+
153
+ // When activeView or isCustom URL parameters change, reset the view.
154
+ useEffect( () => {
155
+ let newView;
156
+ if ( isCustom === 'true' ) {
157
+ newView = getCustomView( editedEntityRecord );
158
+ } else {
159
+ newView = getDefaultView( defaultViews, activeView );
160
+ }
161
+
162
+ if ( newView ) {
163
+ const type = layout ?? newView.type;
164
+ setView( {
165
+ ...newView,
166
+ type,
167
+ } );
168
+ }
169
+ }, [ activeView, isCustom, layout, defaultViews, editedEntityRecord ] );
170
+
171
+ return [ view, setViewWithUrlUpdate, setViewWithUrlUpdate ];
132
172
  }
133
173
 
134
174
  const DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All but 'trash'.
@@ -141,7 +181,12 @@ export default function PostList( { postType } ) {
141
181
  const [ view, setView ] = useView( postType );
142
182
  const history = useHistory();
143
183
  const location = useLocation();
144
- const { postId, quickEdit = false } = location.params;
184
+ const {
185
+ postId,
186
+ quickEdit = false,
187
+ isCustom,
188
+ activeView = 'all',
189
+ } = location.params;
145
190
  const [ selection, setSelection ] = useState( postId?.split( ',' ) ?? [] );
146
191
  const onChangeSelection = useCallback(
147
192
  ( items ) => {
@@ -157,9 +202,11 @@ export default function PostList( { postType } ) {
157
202
  [ history ]
158
203
  );
159
204
 
205
+ const { isLoading: isLoadingFields, fields } = usePostFields( view.type );
206
+
160
207
  const queryArgs = useMemo( () => {
161
208
  const filters = {};
162
- view.filters.forEach( ( filter ) => {
209
+ view.filters?.forEach( ( filter ) => {
163
210
  if (
164
211
  filter.field === 'status' &&
165
212
  filter.operator === OPERATOR_IS_ANY
@@ -196,12 +243,25 @@ export default function PostList( { postType } ) {
196
243
  }, [ view ] );
197
244
  const {
198
245
  records,
199
- isResolving: isLoadingMainEntities,
246
+ isResolving: isLoadingData,
200
247
  totalItems,
201
248
  totalPages,
202
- } = useEntityRecords( 'postType', postType, queryArgs );
249
+ } = useEntityRecordsWithPermissions( 'postType', postType, queryArgs );
250
+
251
+ // The REST API sort the authors by ID, but we want to sort them by name.
252
+ const data = useMemo( () => {
253
+ if ( ! isLoadingFields && view?.sort?.field === 'author' ) {
254
+ return filterSortAndPaginate(
255
+ records,
256
+ { sort: { ...view.sort } },
257
+ fields
258
+ ).data;
259
+ }
260
+
261
+ return records;
262
+ }, [ records, fields, isLoadingFields, view?.sort ] );
203
263
 
204
- const ids = records?.map( ( record ) => getItemId( record ) ) ?? [];
264
+ const ids = data?.map( ( record ) => getItemId( record ) ) ?? [];
205
265
  const prevIds = usePrevious( ids ) ?? [];
206
266
  const deletedIds = prevIds.filter( ( id ) => ! ids.includes( id ) );
207
267
  const postIdWasDeleted = deletedIds.includes( postId );
@@ -259,7 +319,6 @@ export default function PostList( { postType } ) {
259
319
  } );
260
320
  closeModal();
261
321
  };
262
- const { isLoading: isLoadingFields, fields } = usePostFields( view.type );
263
322
 
264
323
  return (
265
324
  <Page
@@ -287,11 +346,12 @@ export default function PostList( { postType } ) {
287
346
  }
288
347
  >
289
348
  <DataViews
349
+ key={ activeView + isCustom }
290
350
  paginationInfo={ paginationInfo }
291
351
  fields={ fields }
292
352
  actions={ actions }
293
- data={ records || EMPTY_ARRAY }
294
- isLoading={ isLoadingMainEntities || isLoadingFields }
353
+ data={ data || EMPTY_ARRAY }
354
+ isLoading={ isLoadingData || isLoadingFields }
295
355
  view={ view }
296
356
  onChangeView={ setView }
297
357
  selection={ selection }
@@ -29,7 +29,7 @@ function AddNewItemModalContent( { type, setIsAdding } ) {
29
29
  const { saveEntityRecord } = useDispatch( coreStore );
30
30
  const [ title, setTitle ] = useState( '' );
31
31
  const [ isSaving, setIsSaving ] = useState( false );
32
- const DEFAULT_VIEWS = useDefaultViews( { postType: type } );
32
+ const defaultViews = useDefaultViews( { postType: type } );
33
33
  return (
34
34
  <form
35
35
  onSubmit={ async ( event ) => {
@@ -61,9 +61,7 @@ function AddNewItemModalContent( { type, setIsAdding } ) {
61
61
  title,
62
62
  status: 'publish',
63
63
  wp_dataviews_type: dataViewTaxonomyId,
64
- content: JSON.stringify(
65
- DEFAULT_VIEWS[ type ][ 0 ].view
66
- ),
64
+ content: JSON.stringify( defaultViews[ 0 ].view ),
67
65
  }
68
66
  );
69
67
  const {
@@ -29,7 +29,7 @@ export default function DataViewItem( {
29
29
  suffix,
30
30
  } ) {
31
31
  const {
32
- params: { postType, layout },
32
+ params: { postType },
33
33
  } = useLocation();
34
34
 
35
35
  const iconToUse =
@@ -41,7 +41,7 @@ export default function DataViewItem( {
41
41
  }
42
42
  const linkInfo = useLink( {
43
43
  postType,
44
- layout,
44
+ layout: type,
45
45
  activeView,
46
46
  isCustom: isCustom ? 'true' : undefined,
47
47
  } );
@@ -77,105 +77,105 @@ export function useDefaultViews( { postType } ) {
77
77
  [ postType ]
78
78
  );
79
79
  return useMemo( () => {
80
- return {
81
- [ postType ]: [
82
- {
83
- title: labels?.all_items || __( 'All items' ),
84
- slug: 'all',
85
- icon: pages,
86
- view: DEFAULT_POST_BASE,
87
- },
88
- {
89
- title: __( 'Published' ),
90
- slug: 'published',
91
- icon: published,
92
- view: {
93
- ...DEFAULT_POST_BASE,
94
- filters: [
95
- {
96
- field: 'status',
97
- operator: OPERATOR_IS_ANY,
98
- value: 'publish',
99
- },
100
- ],
101
- },
80
+ return [
81
+ {
82
+ title: labels?.all_items || __( 'All items' ),
83
+ slug: 'all',
84
+ icon: pages,
85
+ view: DEFAULT_POST_BASE,
86
+ },
87
+ {
88
+ title: __( 'Published' ),
89
+ slug: 'published',
90
+ icon: published,
91
+ view: {
92
+ ...DEFAULT_POST_BASE,
93
+ filters: [
94
+ {
95
+ field: 'status',
96
+ operator: OPERATOR_IS_ANY,
97
+ value: 'publish',
98
+ },
99
+ ],
102
100
  },
103
- {
104
- title: __( 'Scheduled' ),
105
- slug: 'future',
106
- icon: scheduled,
107
- view: {
108
- ...DEFAULT_POST_BASE,
109
- filters: [
110
- {
111
- field: 'status',
112
- operator: OPERATOR_IS_ANY,
113
- value: 'future',
114
- },
115
- ],
116
- },
101
+ },
102
+ {
103
+ title: __( 'Scheduled' ),
104
+ slug: 'future',
105
+ icon: scheduled,
106
+ view: {
107
+ ...DEFAULT_POST_BASE,
108
+ filters: [
109
+ {
110
+ field: 'status',
111
+ operator: OPERATOR_IS_ANY,
112
+ value: 'future',
113
+ },
114
+ ],
117
115
  },
118
- {
119
- title: __( 'Drafts' ),
120
- slug: 'drafts',
121
- icon: drafts,
122
- view: {
123
- ...DEFAULT_POST_BASE,
124
- filters: [
125
- {
126
- field: 'status',
127
- operator: OPERATOR_IS_ANY,
128
- value: 'draft',
129
- },
130
- ],
131
- },
116
+ },
117
+ {
118
+ title: __( 'Drafts' ),
119
+ slug: 'drafts',
120
+ icon: drafts,
121
+ view: {
122
+ ...DEFAULT_POST_BASE,
123
+ filters: [
124
+ {
125
+ field: 'status',
126
+ operator: OPERATOR_IS_ANY,
127
+ value: 'draft',
128
+ },
129
+ ],
132
130
  },
133
- {
134
- title: __( 'Pending' ),
135
- slug: 'pending',
136
- icon: pending,
137
- view: {
138
- ...DEFAULT_POST_BASE,
139
- filters: [
140
- {
141
- field: 'status',
142
- operator: OPERATOR_IS_ANY,
143
- value: 'pending',
144
- },
145
- ],
146
- },
131
+ },
132
+ {
133
+ title: __( 'Pending' ),
134
+ slug: 'pending',
135
+ icon: pending,
136
+ view: {
137
+ ...DEFAULT_POST_BASE,
138
+ filters: [
139
+ {
140
+ field: 'status',
141
+ operator: OPERATOR_IS_ANY,
142
+ value: 'pending',
143
+ },
144
+ ],
147
145
  },
148
- {
149
- title: __( 'Private' ),
150
- slug: 'private',
151
- icon: notAllowed,
152
- view: {
153
- ...DEFAULT_POST_BASE,
154
- filters: [
155
- {
156
- field: 'status',
157
- operator: OPERATOR_IS_ANY,
158
- value: 'private',
159
- },
160
- ],
161
- },
146
+ },
147
+ {
148
+ title: __( 'Private' ),
149
+ slug: 'private',
150
+ icon: notAllowed,
151
+ view: {
152
+ ...DEFAULT_POST_BASE,
153
+ filters: [
154
+ {
155
+ field: 'status',
156
+ operator: OPERATOR_IS_ANY,
157
+ value: 'private',
158
+ },
159
+ ],
162
160
  },
163
- {
164
- title: __( 'Trash' ),
165
- slug: 'trash',
166
- icon: trash,
167
- view: {
168
- ...DEFAULT_POST_BASE,
169
- filters: [
170
- {
171
- field: 'status',
172
- operator: OPERATOR_IS_ANY,
173
- value: 'trash',
174
- },
175
- ],
176
- },
161
+ },
162
+ {
163
+ title: __( 'Trash' ),
164
+ slug: 'trash',
165
+ icon: trash,
166
+ view: {
167
+ ...DEFAULT_POST_BASE,
168
+ type: LAYOUT_TABLE,
169
+ layout: defaultLayouts[ LAYOUT_TABLE ].layout,
170
+ filters: [
171
+ {
172
+ field: 'status',
173
+ operator: OPERATOR_IS_ANY,
174
+ value: 'trash',
175
+ },
176
+ ],
177
177
  },
178
- ],
179
- };
180
- }, [ labels, postType ] );
178
+ },
179
+ ];
180
+ }, [ labels ] );
181
181
  }
@@ -3,8 +3,6 @@
3
3
  */
4
4
  import { __experimentalItemGroup as ItemGroup } from '@wordpress/components';
5
5
  import { privateApis as routerPrivateApis } from '@wordpress/router';
6
- import { useRef, useEffect } from '@wordpress/element';
7
- import { usePrevious } from '@wordpress/compose';
8
6
 
9
7
  /**
10
8
  * Internal dependencies
@@ -14,45 +12,13 @@ import { unlock } from '../../lock-unlock';
14
12
  import DataViewItem from './dataview-item';
15
13
  import CustomDataViewsList from './custom-dataviews-list';
16
14
 
17
- const { useLocation, useHistory } = unlock( routerPrivateApis );
18
-
19
- /**
20
- * Hook to switch to table layout when switching to the trash view.
21
- * When going out of the trash view, it switches back to the previous layout if
22
- * there was an automatic switch to table layout.
23
- */
24
- function useSwitchToTableOnTrash() {
25
- const {
26
- params: { activeView, layout, ...restParams },
27
- } = useLocation();
28
- const history = useHistory();
29
- const viewToSwitchOutOfTrash = useRef( undefined );
30
- const previousActiveView = usePrevious( activeView );
31
- useEffect( () => {
32
- if ( activeView === 'trash' && previousActiveView !== 'trash' ) {
33
- viewToSwitchOutOfTrash.current = layout || 'list';
34
- history.push( { ...restParams, layout: 'table', activeView } );
35
- } else if (
36
- previousActiveView === 'trash' &&
37
- activeView !== 'trash' &&
38
- viewToSwitchOutOfTrash.current
39
- ) {
40
- history.push( {
41
- ...restParams,
42
- layout: viewToSwitchOutOfTrash.current,
43
- activeView,
44
- } );
45
- viewToSwitchOutOfTrash.current = undefined;
46
- }
47
- }, [ previousActiveView, activeView, layout, history, restParams ] );
48
- }
15
+ const { useLocation } = unlock( routerPrivateApis );
49
16
 
50
17
  export default function DataViewsSidebarContent() {
51
18
  const {
52
19
  params: { postType, activeView = 'all', isCustom = 'false' },
53
20
  } = useLocation();
54
- useSwitchToTableOnTrash();
55
- const DEFAULT_VIEWS = useDefaultViews( { postType } );
21
+ const defaultViews = useDefaultViews( { postType } );
56
22
  if ( ! postType ) {
57
23
  return null;
58
24
  }
@@ -61,7 +27,7 @@ export default function DataViewsSidebarContent() {
61
27
  return (
62
28
  <>
63
29
  <ItemGroup>
64
- { DEFAULT_VIEWS[ postType ].map( ( dataview ) => {
30
+ { defaultViews.map( ( dataview ) => {
65
31
  return (
66
32
  <DataViewItem
67
33
  key={ dataview.slug }
@@ -7,7 +7,11 @@ import clsx from 'clsx';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { useSelect, useDispatch } from '@wordpress/data';
10
- import { Button, __experimentalHStack as HStack } from '@wordpress/components';
10
+ import {
11
+ Button,
12
+ __experimentalHStack as HStack,
13
+ VisuallyHidden,
14
+ } from '@wordpress/components';
11
15
  import { __ } from '@wordpress/i18n';
12
16
  import { store as coreStore } from '@wordpress/core-data';
13
17
  import { decodeEntities } from '@wordpress/html-entities';
@@ -80,9 +84,14 @@ const SiteHub = memo(
80
84
  variant="link"
81
85
  href={ homeUrl }
82
86
  target="_blank"
83
- label={ __( 'View site (opens in a new tab)' ) }
84
87
  >
85
88
  { decodeEntities( siteTitle ) }
89
+ <VisuallyHidden as="span">
90
+ {
91
+ /* translators: accessibility text */
92
+ __( '(opens in a new tab)' )
93
+ }
94
+ </VisuallyHidden>
86
95
  </Button>
87
96
  </div>
88
97
  <HStack
@@ -1,9 +1,11 @@
1
1
  .edit-site-site-icon__icon {
2
2
  fill: currentColor;
3
+ width: 100%;
4
+ height: 100%;
3
5
 
4
6
  .edit-site-layout.is-full-canvas & {
5
7
  // Make the WordPress icon not so big in full canvas.
6
- padding: $grid-unit-15 * 0.5; // 6px.
8
+ padding: $grid-unit-15;
7
9
  }
8
10
  }
9
11
 
@@ -12,6 +14,7 @@
12
14
  height: 100%;
13
15
  object-fit: cover;
14
16
  background: #333;
17
+ aspect-ratio: 1 / 1;
15
18
 
16
19
  .edit-site-layout.is-full-canvas & {
17
20
  border-radius: 0;