@wordpress/edit-site 3.0.15 → 3.0.16

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 (191) hide show
  1. package/build/components/add-new-template/new-template-part.js +29 -18
  2. package/build/components/add-new-template/new-template-part.js.map +1 -1
  3. package/build/components/add-new-template/new-template.js +30 -23
  4. package/build/components/add-new-template/new-template.js.map +1 -1
  5. package/build/components/app/index.js +51 -0
  6. package/build/components/app/index.js.map +1 -0
  7. package/build/components/block-editor/back-button.js +8 -20
  8. package/build/components/block-editor/back-button.js.map +1 -1
  9. package/build/components/block-editor/index.js +2 -1
  10. package/build/components/block-editor/index.js.map +1 -1
  11. package/build/components/create-template-part-modal/index.js +0 -2
  12. package/build/components/create-template-part-modal/index.js.map +1 -1
  13. package/build/components/edit-template-part-menu-button/index.js +20 -8
  14. package/build/components/edit-template-part-menu-button/index.js.map +1 -1
  15. package/build/components/editor/index.js +11 -30
  16. package/build/components/editor/index.js.map +1 -1
  17. package/build/components/global-styles/gradients-palette-panel.js +10 -10
  18. package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
  19. package/build/components/global-styles/use-global-styles-output.js +1 -2
  20. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  21. package/build/components/header/document-actions/index.js +3 -6
  22. package/build/components/header/document-actions/index.js.map +1 -1
  23. package/build/components/list/index.js +17 -15
  24. package/build/components/list/index.js.map +1 -1
  25. package/build/components/list/table.js +4 -4
  26. package/build/components/list/table.js.map +1 -1
  27. package/build/components/navigation-sidebar/index.js +12 -13
  28. package/build/components/navigation-sidebar/index.js.map +1 -1
  29. package/build/components/navigation-sidebar/navigation-panel/index.js +26 -24
  30. package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  31. package/build/components/routes/index.js +60 -0
  32. package/build/components/routes/index.js.map +1 -0
  33. package/build/components/routes/link.js +65 -0
  34. package/build/components/routes/link.js.map +1 -0
  35. package/build/components/routes/use-title.js +57 -0
  36. package/build/components/routes/use-title.js.map +1 -0
  37. package/build/components/sidebar/global-styles-sidebar.js +10 -0
  38. package/build/components/sidebar/global-styles-sidebar.js.map +1 -1
  39. package/build/components/sidebar/template-card/template-areas.js +7 -4
  40. package/build/components/sidebar/template-card/template-areas.js.map +1 -1
  41. package/build/components/template-details/index.js +12 -10
  42. package/build/components/template-details/index.js.map +1 -1
  43. package/build/components/template-details/template-areas.js +27 -10
  44. package/build/components/template-details/template-areas.js.map +1 -1
  45. package/build/components/template-part-converter/convert-to-template-part.js +7 -12
  46. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  47. package/build/components/url-query-controller/index.js +41 -50
  48. package/build/components/url-query-controller/index.js.map +1 -1
  49. package/build/components/welcome-guide/editor.js +6 -0
  50. package/build/components/welcome-guide/editor.js.map +1 -1
  51. package/build/components/welcome-guide/index.js +1 -28
  52. package/build/components/welcome-guide/index.js.map +1 -1
  53. package/build/components/welcome-guide/styles.js +18 -1
  54. package/build/components/welcome-guide/styles.js.map +1 -1
  55. package/build/index.js +29 -35
  56. package/build/index.js.map +1 -1
  57. package/build/plugins/index.js +3 -23
  58. package/build/plugins/index.js.map +1 -1
  59. package/build/plugins/site-export.js +61 -0
  60. package/build/plugins/site-export.js.map +1 -0
  61. package/build/plugins/welcome-guide-menu-item.js +1 -7
  62. package/build/plugins/welcome-guide-menu-item.js.map +1 -1
  63. package/build/store/actions.js +0 -27
  64. package/build/store/actions.js.map +1 -1
  65. package/build/store/constants.js +1 -14
  66. package/build/store/constants.js.map +1 -1
  67. package/build/store/reducer.js +7 -16
  68. package/build/store/reducer.js.map +1 -1
  69. package/build/store/selectors.js +1 -31
  70. package/build/store/selectors.js.map +1 -1
  71. package/build/utils/get-is-list-page.js +23 -0
  72. package/build/utils/get-is-list-page.js.map +1 -0
  73. package/build/utils/history.js +35 -0
  74. package/build/utils/history.js.map +1 -0
  75. package/build-module/components/add-new-template/new-template-part.js +27 -16
  76. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  77. package/build-module/components/add-new-template/new-template.js +28 -18
  78. package/build-module/components/add-new-template/new-template.js.map +1 -1
  79. package/build-module/components/app/index.js +35 -0
  80. package/build-module/components/app/index.js.map +1 -0
  81. package/build-module/components/block-editor/back-button.js +8 -19
  82. package/build-module/components/block-editor/back-button.js.map +1 -1
  83. package/build-module/components/block-editor/index.js +2 -1
  84. package/build-module/components/block-editor/index.js.map +1 -1
  85. package/build-module/components/create-template-part-modal/index.js +0 -2
  86. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  87. package/build-module/components/edit-template-part-menu-button/index.js +17 -9
  88. package/build-module/components/edit-template-part-menu-button/index.js.map +1 -1
  89. package/build-module/components/editor/index.js +13 -33
  90. package/build-module/components/editor/index.js.map +1 -1
  91. package/build-module/components/global-styles/gradients-palette-panel.js +10 -10
  92. package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
  93. package/build-module/components/global-styles/use-global-styles-output.js +1 -2
  94. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  95. package/build-module/components/header/document-actions/index.js +3 -6
  96. package/build-module/components/header/document-actions/index.js.map +1 -1
  97. package/build-module/components/list/index.js +15 -15
  98. package/build-module/components/list/index.js.map +1 -1
  99. package/build-module/components/list/table.js +4 -4
  100. package/build-module/components/list/table.js.map +1 -1
  101. package/build-module/components/navigation-sidebar/index.js +13 -13
  102. package/build-module/components/navigation-sidebar/index.js.map +1 -1
  103. package/build-module/components/navigation-sidebar/navigation-panel/index.js +24 -24
  104. package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  105. package/build-module/components/routes/index.js +47 -0
  106. package/build-module/components/routes/index.js.map +1 -0
  107. package/build-module/components/routes/link.js +51 -0
  108. package/build-module/components/routes/link.js.map +1 -0
  109. package/build-module/components/routes/use-title.js +44 -0
  110. package/build-module/components/routes/use-title.js.map +1 -0
  111. package/build-module/components/sidebar/global-styles-sidebar.js +8 -0
  112. package/build-module/components/sidebar/global-styles-sidebar.js.map +1 -1
  113. package/build-module/components/sidebar/template-card/template-areas.js +8 -4
  114. package/build-module/components/sidebar/template-card/template-areas.js.map +1 -1
  115. package/build-module/components/template-details/index.js +10 -9
  116. package/build-module/components/template-details/index.js.map +1 -1
  117. package/build-module/components/template-details/template-areas.js +24 -9
  118. package/build-module/components/template-details/template-areas.js.map +1 -1
  119. package/build-module/components/template-part-converter/convert-to-template-part.js +7 -12
  120. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  121. package/build-module/components/url-query-controller/index.js +40 -49
  122. package/build-module/components/url-query-controller/index.js.map +1 -1
  123. package/build-module/components/welcome-guide/editor.js +7 -1
  124. package/build-module/components/welcome-guide/editor.js.map +1 -1
  125. package/build-module/components/welcome-guide/index.js +2 -26
  126. package/build-module/components/welcome-guide/index.js.map +1 -1
  127. package/build-module/components/welcome-guide/styles.js +18 -2
  128. package/build-module/components/welcome-guide/styles.js.map +1 -1
  129. package/build-module/index.js +28 -33
  130. package/build-module/index.js.map +1 -1
  131. package/build-module/plugins/index.js +2 -18
  132. package/build-module/plugins/index.js.map +1 -1
  133. package/build-module/plugins/site-export.js +45 -0
  134. package/build-module/plugins/site-export.js.map +1 -0
  135. package/build-module/plugins/welcome-guide-menu-item.js +2 -7
  136. package/build-module/plugins/welcome-guide-menu-item.js.map +1 -1
  137. package/build-module/store/actions.js +0 -23
  138. package/build-module/store/actions.js.map +1 -1
  139. package/build-module/store/constants.js +0 -11
  140. package/build-module/store/constants.js.map +1 -1
  141. package/build-module/store/reducer.js +7 -16
  142. package/build-module/store/reducer.js.map +1 -1
  143. package/build-module/store/selectors.js +1 -27
  144. package/build-module/store/selectors.js.map +1 -1
  145. package/build-module/utils/get-is-list-page.js +16 -0
  146. package/build-module/utils/get-is-list-page.js.map +1 -0
  147. package/build-module/utils/history.js +25 -0
  148. package/build-module/utils/history.js.map +1 -0
  149. package/build-style/style-rtl.css +1 -6
  150. package/build-style/style.css +1 -6
  151. package/package.json +9 -8
  152. package/src/components/add-new-template/new-template-part.js +29 -11
  153. package/src/components/add-new-template/new-template.js +26 -12
  154. package/src/components/app/index.js +47 -0
  155. package/src/components/block-editor/back-button.js +6 -14
  156. package/src/components/block-editor/index.js +1 -0
  157. package/src/components/create-template-part-modal/index.js +0 -2
  158. package/src/components/edit-template-part-menu-button/index.js +16 -5
  159. package/src/components/editor/index.js +105 -131
  160. package/src/components/global-styles/gradients-palette-panel.js +12 -12
  161. package/src/components/global-styles/use-global-styles-output.js +0 -1
  162. package/src/components/header/document-actions/index.js +3 -9
  163. package/src/components/list/index.js +11 -12
  164. package/src/components/list/style.scss +6 -11
  165. package/src/components/list/table.js +5 -5
  166. package/src/components/navigation-sidebar/index.js +18 -17
  167. package/src/components/navigation-sidebar/navigation-panel/index.js +16 -22
  168. package/src/components/routes/index.js +53 -0
  169. package/src/components/routes/link.js +44 -0
  170. package/src/components/routes/use-title.js +56 -0
  171. package/src/components/sidebar/global-styles-sidebar.js +8 -0
  172. package/src/components/sidebar/template-card/template-areas.js +16 -4
  173. package/src/components/template-details/index.js +8 -6
  174. package/src/components/template-details/template-areas.js +31 -8
  175. package/src/components/template-part-converter/convert-to-template-part.js +4 -2
  176. package/src/components/url-query-controller/index.js +34 -45
  177. package/src/components/welcome-guide/editor.js +10 -1
  178. package/src/components/welcome-guide/index.js +6 -25
  179. package/src/components/welcome-guide/styles.js +20 -2
  180. package/src/index.js +33 -36
  181. package/src/plugins/index.js +2 -32
  182. package/src/plugins/site-export.js +48 -0
  183. package/src/plugins/welcome-guide-menu-item.js +2 -16
  184. package/src/store/actions.js +0 -23
  185. package/src/store/constants.js +0 -12
  186. package/src/store/reducer.js +12 -26
  187. package/src/store/selectors.js +1 -27
  188. package/src/store/test/reducer.js +22 -39
  189. package/src/store/test/selectors.js +3 -34
  190. package/src/utils/get-is-list-page.js +11 -0
  191. package/src/utils/history.js +35 -0
@@ -1,21 +1,13 @@
1
- /**
2
- * External dependencies
3
- */
4
- import downloadjs from 'downloadjs';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
9
- import { MenuItem } from '@wordpress/components';
10
- import { __ } from '@wordpress/i18n';
11
4
  import { registerPlugin } from '@wordpress/plugins';
12
- import apiFetch from '@wordpress/api-fetch';
13
- import { download } from '@wordpress/icons';
14
5
 
15
6
  /**
16
7
  * Internal dependencies
17
8
  */
18
9
  import ToolsMoreMenuGroup from '../components/header/tools-more-menu-group';
10
+ import SiteExport from './site-export';
19
11
  import WelcomeGuideMenuItem from './welcome-guide-menu-item';
20
12
 
21
13
  registerPlugin( 'edit-site', {
@@ -23,29 +15,7 @@ registerPlugin( 'edit-site', {
23
15
  return (
24
16
  <>
25
17
  <ToolsMoreMenuGroup>
26
- <MenuItem
27
- role="menuitem"
28
- icon={ download }
29
- onClick={ () =>
30
- apiFetch( {
31
- path: '/wp-block-editor/v1/export',
32
- parse: false,
33
- } )
34
- .then( ( res ) => res.blob() )
35
- .then( ( blob ) =>
36
- downloadjs(
37
- blob,
38
- 'edit-site-export.zip',
39
- 'application/zip'
40
- )
41
- )
42
- }
43
- info={ __(
44
- 'Download your templates and template parts.'
45
- ) }
46
- >
47
- { __( 'Export' ) }
48
- </MenuItem>
18
+ <SiteExport />
49
19
  <WelcomeGuideMenuItem />
50
20
  </ToolsMoreMenuGroup>
51
21
  </>
@@ -0,0 +1,48 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import downloadjs from 'downloadjs';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { __ } from '@wordpress/i18n';
10
+ import { MenuItem } from '@wordpress/components';
11
+ import apiFetch from '@wordpress/api-fetch';
12
+ import { download } from '@wordpress/icons';
13
+ import { useDispatch } from '@wordpress/data';
14
+ import { store as noticesStore } from '@wordpress/notices';
15
+
16
+ export default function SiteExport() {
17
+ const { createErrorNotice } = useDispatch( noticesStore );
18
+
19
+ async function handleExport() {
20
+ try {
21
+ const response = await apiFetch( {
22
+ path: '/wp-block-editor/v1/export',
23
+ parse: false,
24
+ } );
25
+ const blob = await response.blob();
26
+
27
+ downloadjs( blob, 'edit-site-export.zip', 'application/zip' );
28
+ } catch ( error ) {
29
+ const errorMessage =
30
+ error.message && error.code !== 'unknown_error'
31
+ ? error.message
32
+ : __( 'An error occurred while creating the site export.' );
33
+
34
+ createErrorNotice( errorMessage, { type: 'snackbar' } );
35
+ }
36
+ }
37
+
38
+ return (
39
+ <MenuItem
40
+ role="menuitem"
41
+ icon={ download }
42
+ onClick={ handleExport }
43
+ info={ __( 'Download your templates and template parts.' ) }
44
+ >
45
+ { __( 'Export' ) }
46
+ </MenuItem>
47
+ );
48
+ }
@@ -2,9 +2,8 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { useDispatch, useSelect } from '@wordpress/data';
5
+ import { useDispatch } from '@wordpress/data';
6
6
  import { MenuItem } from '@wordpress/components';
7
- import { store as interfaceStore } from '@wordpress/interface';
8
7
 
9
8
  /**
10
9
  * Internal dependencies
@@ -13,22 +12,9 @@ import { store as editSiteStore } from '../store';
13
12
 
14
13
  export default function WelcomeGuideMenuItem() {
15
14
  const { toggleFeature } = useDispatch( editSiteStore );
16
- const isStylesOpen = useSelect( ( select ) => {
17
- const sidebar = select( interfaceStore ).getActiveComplementaryArea(
18
- editSiteStore.name
19
- );
20
-
21
- return sidebar === 'edit-site/global-styles';
22
- }, [] );
23
15
 
24
16
  return (
25
- <MenuItem
26
- onClick={ () =>
27
- toggleFeature(
28
- isStylesOpen ? 'welcomeGuideStyles' : 'welcomeGuide'
29
- )
30
- }
31
- >
17
+ <MenuItem onClick={ () => toggleFeature( 'welcomeGuide' ) }>
32
18
  { __( 'Welcome Guide' ) }
33
19
  </MenuItem>
34
20
  );
@@ -172,20 +172,6 @@ export function setTemplatePart( templatePartId ) {
172
172
  };
173
173
  }
174
174
 
175
- /**
176
- * Returns an action object used to push a template part to navigation history.
177
- *
178
- * @param {string} templatePartId The template part ID.
179
- *
180
- * @return {Object} Action object.
181
- */
182
- export function pushTemplatePart( templatePartId ) {
183
- return {
184
- type: 'PUSH_TEMPLATE_PART',
185
- templatePartId,
186
- };
187
- }
188
-
189
175
  /**
190
176
  * Updates the homeTemplateId state with the templateId of the page resolved
191
177
  * from the given path.
@@ -244,15 +230,6 @@ export function* setPage( page ) {
244
230
  return templateId;
245
231
  }
246
232
 
247
- /**
248
- * Go back to the current editing page.
249
- */
250
- export function goBack() {
251
- return {
252
- type: 'GO_BACK',
253
- };
254
- }
255
-
256
233
  /**
257
234
  * Displays the site homepage for editing in the editor.
258
235
  */
@@ -1,8 +1,3 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __ } from '@wordpress/i18n';
5
-
6
1
  /**
7
2
  * The identifier for the data store.
8
3
  *
@@ -14,10 +9,3 @@ export const TEMPLATE_PART_AREA_HEADER = 'header';
14
9
  export const TEMPLATE_PART_AREA_FOOTER = 'footer';
15
10
  export const TEMPLATE_PART_AREA_SIDEBAR = 'sidebar';
16
11
  export const TEMPLATE_PART_AREA_GENERAL = 'uncategorized';
17
-
18
- export const TEMPLATE_PART_AREA_TO_NAME = {
19
- [ TEMPLATE_PART_AREA_HEADER ]: __( 'Header' ),
20
- [ TEMPLATE_PART_AREA_FOOTER ]: __( 'Footer' ),
21
- [ TEMPLATE_PART_AREA_SIDEBAR ]: __( 'Sidebar' ),
22
- [ TEMPLATE_PART_AREA_GENERAL ]: __( 'General' ),
23
- };
@@ -72,39 +72,25 @@ export function settings( state = {}, action ) {
72
72
  * Reducer keeping track of the currently edited Post Type,
73
73
  * Post Id and the context provided to fill the content of the block editor.
74
74
  *
75
- * @param {Array} state Current state history.
75
+ * @param {Object} state Current edited post.
76
76
  * @param {Object} action Dispatched action.
77
77
  *
78
- * @return {Array} Updated state.
78
+ * @return {Object} Updated state.
79
79
  */
80
- export function editedPost( state = [], action ) {
80
+ export function editedPost( state = {}, action ) {
81
81
  switch ( action.type ) {
82
82
  case 'SET_TEMPLATE':
83
83
  case 'SET_PAGE':
84
- return [
85
- {
86
- type: 'wp_template',
87
- id: action.templateId,
88
- page: action.page,
89
- },
90
- ];
84
+ return {
85
+ type: 'wp_template',
86
+ id: action.templateId,
87
+ page: action.page,
88
+ };
91
89
  case 'SET_TEMPLATE_PART':
92
- return [
93
- {
94
- type: 'wp_template_part',
95
- id: action.templatePartId,
96
- },
97
- ];
98
- case 'PUSH_TEMPLATE_PART':
99
- return [
100
- ...state,
101
- {
102
- type: 'wp_template_part',
103
- id: action.templatePartId,
104
- },
105
- ];
106
- case 'GO_BACK':
107
- return state.slice( 0, -1 );
90
+ return {
91
+ type: 'wp_template_part',
92
+ id: action.templatePartId,
93
+ };
108
94
  }
109
95
 
110
96
  return state;
@@ -135,11 +135,7 @@ export function getHomeTemplateId( state ) {
135
135
  }
136
136
 
137
137
  function getCurrentEditedPost( state ) {
138
- return state.editedPost[ state.editedPost.length - 1 ] || {};
139
- }
140
-
141
- function getPreviousEditedPost( state ) {
142
- return state.editedPost[ state.editedPost.length - 2 ] || {};
138
+ return state.editedPost;
143
139
  }
144
140
 
145
141
  /**
@@ -164,28 +160,6 @@ export function getEditedPostId( state ) {
164
160
  return getCurrentEditedPost( state ).id;
165
161
  }
166
162
 
167
- /**
168
- * Returns the previous edited post type (wp_template or wp_template_part).
169
- *
170
- * @param {Object} state Global application state.
171
- *
172
- * @return {TemplateType?} Template type.
173
- */
174
- export function getPreviousEditedPostType( state ) {
175
- return getPreviousEditedPost( state ).type;
176
- }
177
-
178
- /**
179
- * Returns the ID of the previous edited template or template part.
180
- *
181
- * @param {Object} state Global application state.
182
- *
183
- * @return {string?} Post ID.
184
- */
185
- export function getPreviousEditedPostId( state ) {
186
- return getPreviousEditedPost( state ).id;
187
- }
188
-
189
163
  /**
190
164
  * Returns the current page object.
191
165
  *
@@ -88,7 +88,7 @@ describe( 'state', () => {
88
88
 
89
89
  describe( 'editedPost()', () => {
90
90
  it( 'should apply default state', () => {
91
- expect( editedPost( undefined, {} ) ).toEqual( [] );
91
+ expect( editedPost( undefined, {} ) ).toEqual( {} );
92
92
  } );
93
93
 
94
94
  it( 'should default to returning the same state', () => {
@@ -98,56 +98,39 @@ describe( 'state', () => {
98
98
 
99
99
  it( 'should update when a template is set', () => {
100
100
  expect(
101
- editedPost( [ { id: 1, type: 'wp_template' } ], {
102
- type: 'SET_TEMPLATE',
103
- templateId: 2,
104
- } )
105
- ).toEqual( [ { id: 2, type: 'wp_template' } ] );
101
+ editedPost(
102
+ { id: 1, type: 'wp_template' },
103
+ {
104
+ type: 'SET_TEMPLATE',
105
+ templateId: 2,
106
+ }
107
+ )
108
+ ).toEqual( { id: 2, type: 'wp_template' } );
106
109
  } );
107
110
 
108
111
  it( 'should update when a page is set', () => {
109
112
  expect(
110
- editedPost( [ { id: 1, type: 'wp_template' } ], {
111
- type: 'SET_PAGE',
112
- templateId: 2,
113
- page: {},
114
- } )
115
- ).toEqual( [ { id: 2, type: 'wp_template', page: {} } ] );
113
+ editedPost(
114
+ { id: 1, type: 'wp_template' },
115
+ {
116
+ type: 'SET_PAGE',
117
+ templateId: 2,
118
+ page: {},
119
+ }
120
+ )
121
+ ).toEqual( { id: 2, type: 'wp_template', page: {} } );
116
122
  } );
117
123
 
118
124
  it( 'should update when a template part is set', () => {
119
- expect(
120
- editedPost( [ { id: 1, type: 'wp_template' } ], {
121
- type: 'SET_TEMPLATE_PART',
122
- templatePartId: 2,
123
- } )
124
- ).toEqual( [ { id: 2, type: 'wp_template_part' } ] );
125
- } );
126
-
127
- it( 'should update when a template part is pushed', () => {
128
- expect(
129
- editedPost( [ { id: 1, type: 'wp_template' } ], {
130
- type: 'PUSH_TEMPLATE_PART',
131
- templatePartId: 2,
132
- } )
133
- ).toEqual( [
134
- { id: 1, type: 'wp_template' },
135
- { id: 2, type: 'wp_template_part' },
136
- ] );
137
- } );
138
-
139
- it( 'should go back to the previous page', () => {
140
125
  expect(
141
126
  editedPost(
142
- [
143
- { id: 1, type: 'wp_template' },
144
- { id: 2, type: 'wp_template_part' },
145
- ],
127
+ { id: 1, type: 'wp_template' },
146
128
  {
147
- type: 'GO_BACK',
129
+ type: 'SET_TEMPLATE_PART',
130
+ templatePartId: 2,
148
131
  }
149
132
  )
150
- ).toEqual( [ { id: 1, type: 'wp_template' } ] );
133
+ ).toEqual( { id: 2, type: 'wp_template_part' } );
151
134
  } );
152
135
  } );
153
136
 
@@ -13,8 +13,6 @@ import {
13
13
  getHomeTemplateId,
14
14
  getEditedPostType,
15
15
  getEditedPostId,
16
- getPreviousEditedPostType,
17
- getPreviousEditedPostId,
18
16
  getPage,
19
17
  getNavigationPanelActiveMenu,
20
18
  getReusableBlocks,
@@ -152,51 +150,22 @@ describe( 'selectors', () => {
152
150
 
153
151
  describe( 'getEditedPostId', () => {
154
152
  it( 'returns the template ID', () => {
155
- const state = { editedPost: [ { id: 10 } ] };
153
+ const state = { editedPost: { id: 10 } };
156
154
  expect( getEditedPostId( state ) ).toBe( 10 );
157
155
  } );
158
156
  } );
159
157
 
160
158
  describe( 'getEditedPostType', () => {
161
159
  it( 'returns the template type', () => {
162
- const state = { editedPost: [ { type: 'wp_template' } ] };
160
+ const state = { editedPost: { type: 'wp_template' } };
163
161
  expect( getEditedPostType( state ) ).toBe( 'wp_template' );
164
162
  } );
165
163
  } );
166
164
 
167
- describe( 'getPreviousEditedPostId', () => {
168
- it( 'returns the previous template ID', () => {
169
- const state = { editedPost: [ { id: 10 }, { id: 20 } ] };
170
- expect( getPreviousEditedPostId( state ) ).toBe( 10 );
171
- } );
172
-
173
- it( 'returns undefined when there are no previous pages', () => {
174
- const state = { editedPost: [ { id: 10 } ] };
175
- expect( getPreviousEditedPostId( state ) ).toBeUndefined();
176
- } );
177
- } );
178
-
179
- describe( 'getPreviousEditedPostType', () => {
180
- it( 'returns the previous template type', () => {
181
- const state = {
182
- editedPost: [
183
- { type: 'wp_template' },
184
- { type: 'wp_template_part' },
185
- ],
186
- };
187
- expect( getPreviousEditedPostType( state ) ).toBe( 'wp_template' );
188
- } );
189
-
190
- it( 'returns undefined when there are no previous pages', () => {
191
- const state = { editedPost: [ { type: 'wp_template' } ] };
192
- expect( getPreviousEditedPostType( state ) ).toBeUndefined();
193
- } );
194
- } );
195
-
196
165
  describe( 'getPage', () => {
197
166
  it( 'returns the page object', () => {
198
167
  const page = {};
199
- const state = { editedPost: [ { page } ] };
168
+ const state = { editedPost: { page } };
200
169
  expect( getPage( state ) ).toBe( page );
201
170
  } );
202
171
  } );
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns if the params match the list page route.
3
+ *
4
+ * @param {Object} params The search params.
5
+ * @param {string} params.postId The post ID.
6
+ * @param {string} params.postType The post type.
7
+ * @return {boolean} Is list page or not.
8
+ */
9
+ export default function getIsListPage( { postId, postType } ) {
10
+ return !! ( ! postId && postType );
11
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { createBrowserHistory } from 'history';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { addQueryArgs } from '@wordpress/url';
10
+
11
+ const history = createBrowserHistory();
12
+
13
+ const originalHistoryPush = history.push;
14
+ const originalHistoryReplace = history.replace;
15
+
16
+ function push( params, state ) {
17
+ return originalHistoryPush.call(
18
+ history,
19
+ addQueryArgs( window.location.href, params ),
20
+ state
21
+ );
22
+ }
23
+
24
+ function replace( params, state ) {
25
+ return originalHistoryReplace.call(
26
+ history,
27
+ addQueryArgs( window.location.href, params ),
28
+ state
29
+ );
30
+ }
31
+
32
+ history.push = push;
33
+ history.replace = replace;
34
+
35
+ export default history;