@wordpress/edit-site 5.21.0 → 5.22.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 (123) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/actions/index.js +121 -0
  3. package/build/components/actions/index.js.map +1 -0
  4. package/build/components/block-editor/use-site-editor-settings.js +12 -4
  5. package/build/components/block-editor/use-site-editor-settings.js.map +1 -1
  6. package/build/components/dataviews/dataviews.js +10 -2
  7. package/build/components/dataviews/dataviews.js.map +1 -1
  8. package/build/components/dataviews/filters.js +30 -17
  9. package/build/components/dataviews/filters.js.map +1 -1
  10. package/build/components/dataviews/in-filter.js +5 -7
  11. package/build/components/dataviews/in-filter.js.map +1 -1
  12. package/build/components/dataviews/item-actions.js +62 -0
  13. package/build/components/dataviews/item-actions.js.map +1 -0
  14. package/build/components/dataviews/pagination.js +31 -50
  15. package/build/components/dataviews/pagination.js.map +1 -1
  16. package/build/components/dataviews/{text-filter.js → search.js} +10 -10
  17. package/build/components/dataviews/search.js.map +1 -0
  18. package/build/components/dataviews/view-grid.js +3 -3
  19. package/build/components/dataviews/view-grid.js.map +1 -1
  20. package/build/components/dataviews/view-list.js +2 -2
  21. package/build/components/dataviews/view-list.js.map +1 -1
  22. package/build/components/global-styles/font-library-modal/font-collection.js +1 -1
  23. package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  24. package/build/components/global-styles/screen-block.js +1 -8
  25. package/build/components/global-styles/screen-block.js.map +1 -1
  26. package/build/components/page-pages/default-views.js +62 -0
  27. package/build/components/page-pages/default-views.js.map +1 -0
  28. package/build/components/page-pages/index.js +73 -52
  29. package/build/components/page-pages/index.js.map +1 -1
  30. package/build/components/page-patterns/rename-category-menu-item.js +27 -9
  31. package/build/components/page-patterns/rename-category-menu-item.js.map +1 -1
  32. package/build/components/save-button/index.js +4 -2
  33. package/build/components/save-button/index.js.map +1 -1
  34. package/build/components/sidebar/index.js +3 -1
  35. package/build/components/sidebar/index.js.map +1 -1
  36. package/build/components/sidebar-dataviews/index.js +74 -0
  37. package/build/components/sidebar-dataviews/index.js.map +1 -0
  38. package/build/components/sidebar-navigation-screen-page/page-details.js +1 -1
  39. package/build/components/sidebar-navigation-screen-page/page-details.js.map +1 -1
  40. package/build/hooks/commands/use-edit-mode-commands.js +3 -2
  41. package/build/hooks/commands/use-edit-mode-commands.js.map +1 -1
  42. package/build/utils/use-activate-theme.js +8 -0
  43. package/build/utils/use-activate-theme.js.map +1 -1
  44. package/build-module/components/actions/index.js +108 -0
  45. package/build-module/components/actions/index.js.map +1 -0
  46. package/build-module/components/block-editor/use-site-editor-settings.js +12 -4
  47. package/build-module/components/block-editor/use-site-editor-settings.js.map +1 -1
  48. package/build-module/components/dataviews/dataviews.js +10 -2
  49. package/build-module/components/dataviews/dataviews.js.map +1 -1
  50. package/build-module/components/dataviews/filters.js +30 -17
  51. package/build-module/components/dataviews/filters.js.map +1 -1
  52. package/build-module/components/dataviews/in-filter.js +5 -7
  53. package/build-module/components/dataviews/in-filter.js.map +1 -1
  54. package/build-module/components/dataviews/item-actions.js +55 -0
  55. package/build-module/components/dataviews/item-actions.js.map +1 -0
  56. package/build-module/components/dataviews/pagination.js +32 -51
  57. package/build-module/components/dataviews/pagination.js.map +1 -1
  58. package/build-module/components/dataviews/{text-filter.js → search.js} +9 -9
  59. package/build-module/components/dataviews/search.js.map +1 -0
  60. package/build-module/components/dataviews/view-grid.js +3 -3
  61. package/build-module/components/dataviews/view-grid.js.map +1 -1
  62. package/build-module/components/dataviews/view-list.js +2 -2
  63. package/build-module/components/dataviews/view-list.js.map +1 -1
  64. package/build-module/components/global-styles/font-library-modal/font-collection.js +1 -1
  65. package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  66. package/build-module/components/global-styles/screen-block.js +1 -8
  67. package/build-module/components/global-styles/screen-block.js.map +1 -1
  68. package/build-module/components/page-pages/default-views.js +55 -0
  69. package/build-module/components/page-pages/default-views.js.map +1 -0
  70. package/build-module/components/page-pages/index.js +71 -52
  71. package/build-module/components/page-pages/index.js.map +1 -1
  72. package/build-module/components/page-patterns/rename-category-menu-item.js +25 -9
  73. package/build-module/components/page-patterns/rename-category-menu-item.js.map +1 -1
  74. package/build-module/components/save-button/index.js +4 -2
  75. package/build-module/components/save-button/index.js.map +1 -1
  76. package/build-module/components/sidebar/index.js +3 -1
  77. package/build-module/components/sidebar/index.js.map +1 -1
  78. package/build-module/components/sidebar-dataviews/index.js +66 -0
  79. package/build-module/components/sidebar-dataviews/index.js.map +1 -0
  80. package/build-module/components/sidebar-navigation-screen-page/page-details.js +1 -1
  81. package/build-module/components/sidebar-navigation-screen-page/page-details.js.map +1 -1
  82. package/build-module/hooks/commands/use-edit-mode-commands.js +4 -3
  83. package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -1
  84. package/build-module/utils/use-activate-theme.js +8 -0
  85. package/build-module/utils/use-activate-theme.js.map +1 -1
  86. package/build-style/style-rtl.css +9 -5
  87. package/build-style/style.css +9 -5
  88. package/package.json +40 -40
  89. package/src/components/actions/index.js +123 -0
  90. package/src/components/block-editor/use-site-editor-settings.js +21 -13
  91. package/src/components/dataviews/README.md +134 -47
  92. package/src/components/dataviews/dataviews.js +11 -1
  93. package/src/components/dataviews/filters.js +35 -17
  94. package/src/components/dataviews/in-filter.js +5 -7
  95. package/src/components/dataviews/item-actions.js +69 -0
  96. package/src/components/dataviews/pagination.js +53 -74
  97. package/src/components/dataviews/{text-filter.js → search.js} +7 -7
  98. package/src/components/dataviews/style.scss +10 -5
  99. package/src/components/dataviews/view-grid.js +7 -2
  100. package/src/components/dataviews/view-list.js +2 -2
  101. package/src/components/global-styles/font-library-modal/font-collection.js +1 -1
  102. package/src/components/global-styles/screen-block.js +1 -7
  103. package/src/components/page-pages/default-views.js +60 -0
  104. package/src/components/page-pages/index.js +85 -60
  105. package/src/components/page-patterns/rename-category-menu-item.js +29 -12
  106. package/src/components/save-button/index.js +10 -5
  107. package/src/components/sidebar/index.js +2 -0
  108. package/src/components/sidebar-dataviews/index.js +66 -0
  109. package/src/components/sidebar-navigation-screen-page/page-details.js +3 -1
  110. package/src/hooks/commands/use-edit-mode-commands.js +3 -1
  111. package/src/utils/use-activate-theme.js +5 -0
  112. package/build/components/actions/trash-post.js +0 -48
  113. package/build/components/actions/trash-post.js.map +0 -1
  114. package/build/components/dataviews/field-actions.js +0 -30
  115. package/build/components/dataviews/field-actions.js.map +0 -1
  116. package/build/components/dataviews/text-filter.js.map +0 -1
  117. package/build-module/components/actions/trash-post.js +0 -41
  118. package/build-module/components/actions/trash-post.js.map +0 -1
  119. package/build-module/components/dataviews/field-actions.js +0 -22
  120. package/build-module/components/dataviews/field-actions.js.map +0 -1
  121. package/build-module/components/dataviews/text-filter.js.map +0 -1
  122. package/src/components/actions/trash-post.js +0 -55
  123. package/src/components/dataviews/field-actions.js +0 -28
@@ -1130,8 +1130,17 @@ textarea.edit-site-code-editor-text-area.edit-site-code-editor-text-area:-ms-inp
1130
1130
 
1131
1131
  .dataviews-wrapper {
1132
1132
  width: 100%;
1133
+ height: 100%;
1134
+ overflow: auto;
1133
1135
  padding: 32px;
1134
1136
  }
1137
+ .dataviews-wrapper > div {
1138
+ min-height: 100%;
1139
+ }
1140
+
1141
+ .dataviews-pagination {
1142
+ margin-top: auto;
1143
+ }
1135
1144
 
1136
1145
  .dataviews-list-view {
1137
1146
  width: 100%;
@@ -1161,11 +1170,6 @@ textarea.edit-site-code-editor-text-area.edit-site-code-editor-text-area:-ms-inp
1161
1170
  border-bottom: 1px solid #f0f0f0;
1162
1171
  }
1163
1172
 
1164
- .dataviews__select-control-prefix {
1165
- color: #757575;
1166
- text-wrap: nowrap;
1167
- }
1168
-
1169
1173
  .dataviews-view-grid__media {
1170
1174
  width: 100%;
1171
1175
  min-height: 200px;
@@ -1130,8 +1130,17 @@ textarea.edit-site-code-editor-text-area.edit-site-code-editor-text-area:-ms-inp
1130
1130
 
1131
1131
  .dataviews-wrapper {
1132
1132
  width: 100%;
1133
+ height: 100%;
1134
+ overflow: auto;
1133
1135
  padding: 32px;
1134
1136
  }
1137
+ .dataviews-wrapper > div {
1138
+ min-height: 100%;
1139
+ }
1140
+
1141
+ .dataviews-pagination {
1142
+ margin-top: auto;
1143
+ }
1135
1144
 
1136
1145
  .dataviews-list-view {
1137
1146
  width: 100%;
@@ -1161,11 +1170,6 @@ textarea.edit-site-code-editor-text-area.edit-site-code-editor-text-area:-ms-inp
1161
1170
  border-bottom: 1px solid #f0f0f0;
1162
1171
  }
1163
1172
 
1164
- .dataviews__select-control-prefix {
1165
- color: #757575;
1166
- text-wrap: nowrap;
1167
- }
1168
-
1169
1173
  .dataviews-view-grid__media {
1170
1174
  width: 100%;
1171
1175
  min-height: 200px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/edit-site",
3
- "version": "5.21.0",
3
+ "version": "5.22.0",
4
4
  "description": "Edit Site Page module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -28,44 +28,44 @@
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.16.0",
30
30
  "@tanstack/react-table": "^8.10.3",
31
- "@wordpress/a11y": "^3.44.0",
32
- "@wordpress/api-fetch": "^6.41.0",
33
- "@wordpress/block-editor": "^12.12.0",
34
- "@wordpress/block-library": "^8.21.0",
35
- "@wordpress/blocks": "^12.21.0",
36
- "@wordpress/commands": "^0.15.0",
37
- "@wordpress/components": "^25.10.0",
38
- "@wordpress/compose": "^6.21.0",
39
- "@wordpress/core-commands": "^0.13.0",
40
- "@wordpress/core-data": "^6.21.0",
41
- "@wordpress/data": "^9.14.0",
42
- "@wordpress/date": "^4.44.0",
43
- "@wordpress/deprecated": "^3.44.0",
44
- "@wordpress/dom": "^3.44.0",
45
- "@wordpress/editor": "^13.21.0",
46
- "@wordpress/element": "^5.21.0",
47
- "@wordpress/escape-html": "^2.44.0",
48
- "@wordpress/hooks": "^3.44.0",
49
- "@wordpress/html-entities": "^3.44.0",
50
- "@wordpress/i18n": "^4.44.0",
51
- "@wordpress/icons": "^9.35.0",
52
- "@wordpress/interface": "^5.21.0",
53
- "@wordpress/keyboard-shortcuts": "^4.21.0",
54
- "@wordpress/keycodes": "^3.44.0",
55
- "@wordpress/media-utils": "^4.35.0",
56
- "@wordpress/notices": "^4.12.0",
57
- "@wordpress/patterns": "^1.5.0",
58
- "@wordpress/plugins": "^6.12.0",
59
- "@wordpress/preferences": "^3.21.0",
60
- "@wordpress/primitives": "^3.42.0",
61
- "@wordpress/private-apis": "^0.26.0",
62
- "@wordpress/reusable-blocks": "^4.21.0",
63
- "@wordpress/router": "^0.13.0",
64
- "@wordpress/style-engine": "^1.27.0",
65
- "@wordpress/url": "^3.45.0",
66
- "@wordpress/viewport": "^5.21.0",
67
- "@wordpress/widgets": "^3.21.0",
68
- "@wordpress/wordcount": "^3.44.0",
31
+ "@wordpress/a11y": "^3.45.0",
32
+ "@wordpress/api-fetch": "^6.42.0",
33
+ "@wordpress/block-editor": "^12.13.0",
34
+ "@wordpress/block-library": "^8.22.0",
35
+ "@wordpress/blocks": "^12.22.0",
36
+ "@wordpress/commands": "^0.16.0",
37
+ "@wordpress/components": "^25.11.0",
38
+ "@wordpress/compose": "^6.22.0",
39
+ "@wordpress/core-commands": "^0.14.0",
40
+ "@wordpress/core-data": "^6.22.0",
41
+ "@wordpress/data": "^9.15.0",
42
+ "@wordpress/date": "^4.45.0",
43
+ "@wordpress/deprecated": "^3.45.0",
44
+ "@wordpress/dom": "^3.45.0",
45
+ "@wordpress/editor": "^13.22.0",
46
+ "@wordpress/element": "^5.22.0",
47
+ "@wordpress/escape-html": "^2.45.0",
48
+ "@wordpress/hooks": "^3.45.0",
49
+ "@wordpress/html-entities": "^3.45.0",
50
+ "@wordpress/i18n": "^4.45.0",
51
+ "@wordpress/icons": "^9.36.0",
52
+ "@wordpress/interface": "^5.22.0",
53
+ "@wordpress/keyboard-shortcuts": "^4.22.0",
54
+ "@wordpress/keycodes": "^3.45.0",
55
+ "@wordpress/media-utils": "^4.36.0",
56
+ "@wordpress/notices": "^4.13.0",
57
+ "@wordpress/patterns": "^1.6.0",
58
+ "@wordpress/plugins": "^6.13.0",
59
+ "@wordpress/preferences": "^3.22.0",
60
+ "@wordpress/primitives": "^3.43.0",
61
+ "@wordpress/private-apis": "^0.27.0",
62
+ "@wordpress/reusable-blocks": "^4.22.0",
63
+ "@wordpress/router": "^0.14.0",
64
+ "@wordpress/style-engine": "^1.28.0",
65
+ "@wordpress/url": "^3.46.0",
66
+ "@wordpress/viewport": "^5.22.0",
67
+ "@wordpress/widgets": "^3.22.0",
68
+ "@wordpress/wordcount": "^3.45.0",
69
69
  "change-case": "^4.1.2",
70
70
  "classnames": "^2.3.1",
71
71
  "colord": "^2.9.2",
@@ -85,5 +85,5 @@
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
- "gitHead": "f83bb1a71e8fa416131b81a9f282a72a1dc6c694"
88
+ "gitHead": "2a00e87b57b9c27ed2b9b0fd8d423ef3cada72c1"
89
89
  }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { external, trash } from '@wordpress/icons';
5
+ import { addQueryArgs } from '@wordpress/url';
6
+ import { useDispatch } from '@wordpress/data';
7
+ import { decodeEntities } from '@wordpress/html-entities';
8
+ import { store as coreStore } from '@wordpress/core-data';
9
+ import { __, sprintf } from '@wordpress/i18n';
10
+ import { store as noticesStore } from '@wordpress/notices';
11
+ import { useMemo } from '@wordpress/element';
12
+ import { privateApis as routerPrivateApis } from '@wordpress/router';
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import { unlock } from '../../lock-unlock';
17
+
18
+ const { useHistory } = unlock( routerPrivateApis );
19
+
20
+ export function useTrashPostAction() {
21
+ const { createSuccessNotice, createErrorNotice } =
22
+ useDispatch( noticesStore );
23
+ const { deleteEntityRecord } = useDispatch( coreStore );
24
+
25
+ return useMemo(
26
+ () => ( {
27
+ id: 'move-to-trash',
28
+ label: __( 'Move to Trash' ),
29
+ isPrimary: true,
30
+ icon: trash,
31
+ isEligible( { status } ) {
32
+ return status !== 'trash';
33
+ },
34
+ async perform( post ) {
35
+ try {
36
+ await deleteEntityRecord(
37
+ 'postType',
38
+ post.type,
39
+ post.id,
40
+ {},
41
+ { throwOnError: true }
42
+ );
43
+ createSuccessNotice(
44
+ sprintf(
45
+ /* translators: The page's title. */
46
+ __( '"%s" moved to the Trash.' ),
47
+ decodeEntities( post.title.rendered )
48
+ ),
49
+ {
50
+ type: 'snackbar',
51
+ id: 'edit-site-page-trashed',
52
+ }
53
+ );
54
+ } catch ( error ) {
55
+ const errorMessage =
56
+ error.message && error.code !== 'unknown_error'
57
+ ? error.message
58
+ : __(
59
+ 'An error occurred while moving the page to the trash.'
60
+ );
61
+
62
+ createErrorNotice( errorMessage, { type: 'snackbar' } );
63
+ }
64
+ },
65
+ } ),
66
+ [ createSuccessNotice, createErrorNotice, deleteEntityRecord ]
67
+ );
68
+ }
69
+
70
+ export const viewPostAction = {
71
+ id: 'view-post',
72
+ label: __( 'View' ),
73
+ isPrimary: true,
74
+ icon: external,
75
+ isEligible( post ) {
76
+ return post.status !== 'trash';
77
+ },
78
+ perform( post ) {
79
+ document.location.href = post.link;
80
+ },
81
+ };
82
+
83
+ export function useEditPostAction() {
84
+ const history = useHistory();
85
+ return useMemo(
86
+ () => ( {
87
+ id: 'edit-post',
88
+ label: __( 'Edit' ),
89
+ isEligible( { status } ) {
90
+ return status !== 'trash';
91
+ },
92
+ perform( post ) {
93
+ history.push( {
94
+ postId: post.id,
95
+ postType: post.type,
96
+ canvas: 'edit',
97
+ } );
98
+ },
99
+ } ),
100
+ [ history ]
101
+ );
102
+ }
103
+ export const postRevisionsAction = {
104
+ id: 'view-post-revisions',
105
+ label: __( 'View revisions' ),
106
+ isPrimary: false,
107
+ isEligible: ( post ) => {
108
+ if ( post.status === 'trash' ) {
109
+ return false;
110
+ }
111
+ const lastRevisionId =
112
+ post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null;
113
+ const revisionsCount =
114
+ post?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;
115
+ return lastRevisionId && revisionsCount > 1;
116
+ },
117
+ perform( post ) {
118
+ const href = addQueryArgs( 'revision.php', {
119
+ revision: post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id,
120
+ } );
121
+ document.location.href = href;
122
+ },
123
+ };
@@ -85,19 +85,23 @@ function useArchiveLabel( templateSlug ) {
85
85
 
86
86
  export default function useSiteEditorSettings() {
87
87
  const { setIsInserterOpened } = useDispatch( editSiteStore );
88
- const { storedSettings, canvasMode, templateType } = useSelect(
89
- ( select ) => {
90
- const { getSettings, getCanvasMode, getEditedPostType } = unlock(
91
- select( editSiteStore )
92
- );
93
- return {
94
- storedSettings: getSettings( setIsInserterOpened ),
95
- canvasMode: getCanvasMode(),
96
- templateType: getEditedPostType(),
97
- };
98
- },
99
- [ setIsInserterOpened ]
100
- );
88
+ const { storedSettings, canvasMode, templateType, siteSettings } =
89
+ useSelect(
90
+ ( select ) => {
91
+ const { canUser, getEntityRecord } = select( coreStore );
92
+ const { getSettings, getCanvasMode, getEditedPostType } =
93
+ unlock( select( editSiteStore ) );
94
+ return {
95
+ storedSettings: getSettings( setIsInserterOpened ),
96
+ canvasMode: getCanvasMode(),
97
+ templateType: getEditedPostType(),
98
+ siteSettings: canUser( 'read', 'settings' )
99
+ ? getEntityRecord( 'root', 'site' )
100
+ : undefined,
101
+ };
102
+ },
103
+ [ setIsInserterOpened ]
104
+ );
101
105
 
102
106
  const settingsBlockPatterns =
103
107
  storedSettings.__experimentalAdditionalBlockPatterns ?? // WP 6.0
@@ -180,6 +184,8 @@ export default function useSiteEditorSettings() {
180
184
  focusMode: canvasMode === 'view' && focusMode ? false : focusMode,
181
185
  __experimentalArchiveTitleTypeLabel: archiveLabels.archiveTypeLabel,
182
186
  __experimentalArchiveTitleNameLabel: archiveLabels.archiveNameLabel,
187
+ pageOnFront: siteSettings?.page_on_front,
188
+ pageForPosts: siteSettings?.page_for_posts,
183
189
  };
184
190
  }, [
185
191
  storedSettings,
@@ -189,5 +195,7 @@ export default function useSiteEditorSettings() {
189
195
  canvasMode,
190
196
  archiveLabels.archiveTypeLabel,
191
197
  archiveLabels.archiveNameLabel,
198
+ siteSettings?.page_on_front,
199
+ siteSettings?.page_for_posts,
192
200
  ] );
193
201
  }
@@ -1,107 +1,194 @@
1
1
  # DataView
2
2
 
3
- This file aims to document the main APIs related to the DataView component.
3
+ This file documents the DataViews UI component, which provides an API to render datasets using different view types (table, grid, etc.).
4
+
5
+ ```js
6
+ <DataViews
7
+ data={ pages }
8
+ isLoading= { isLoadingPages }
9
+ view={ view }
10
+ onChangeView={ onChangeView }
11
+ fields={ fields }
12
+ actions={ [ trashPostAction ] }
13
+ paginationInfo={ { totalItems, totalPages } }
14
+ />
15
+ ```
16
+
17
+ ## Data
18
+
19
+ The dataset to work with, represented as a one-dimensional array.
20
+
21
+ Example:
22
+
23
+ ```js
24
+ [
25
+ { id: 1, title: "Title", ... },
26
+ { ... }
27
+ ]
28
+ ```
4
29
 
5
30
  ## View
6
31
 
7
- The view is responsible for configuring how the dataset is visible to the user. For example:
32
+ The view object configures how the dataset is visible to the user.
33
+
34
+ Example:
8
35
 
9
36
  ```js
10
37
  {
11
38
  type: 'list',
12
- page: 1,
13
39
  perPage: 5,
40
+ page: 1,
14
41
  sort: {
15
42
  field: 'date',
16
43
  direction: 'desc',
17
44
  },
45
+ search: '',
18
46
  filters: {
19
- search: '',
20
47
  author: 2,
21
48
  status: 'publish, draft'
22
49
  },
23
- visibleFilters: [ 'search', 'author', 'status' ],
50
+ visibleFilters: [ 'author', 'status' ],
24
51
  hiddenFields: [ 'date', 'featured-image' ],
25
52
  layout: {},
26
53
  }
27
54
  ```
28
55
 
29
- - `type`: one of `list` or `grid`.
30
- - `page`: the current page.
31
- - `perPage`: number of records per page.
32
- - `sort.field`: field used for sorting.
33
- - `sort.direction`: one of `asc` or `desc`.
34
- - `filters`: the filters applied to the dataset.
56
+ - `type`: view type, one of `list` or `grid`.
57
+ - `perPage`: number of records to show per page.
58
+ - `page`: the page that is visible.
59
+ - `sort.field`: field used for sorting the dataset.
60
+ - `sort.direction`: the direction to use for sorting, one of `asc` or `desc`.
61
+ - `search`: the text search applied to the dataset.
62
+ - `filters`: the filters applied to the dataset. See filters section.
35
63
  - `visibleFilters`: the `id` of the filters that are visible in the UI.
36
64
  - `hiddenFields`: the `id` of the fields that are hidden in the UI.
37
65
  - `layout`: ...
38
66
 
39
- The view configuration is used to retrieve the corresponding entity that holds the dataset:
67
+ Note that it's the consumer's responsibility to provide the data and make sure the dataset corresponds to the view's config (sort, pagination, filters, etc.).
68
+
69
+ Example:
40
70
 
41
71
  ```js
42
- const {
43
- records: pages,
44
- isLoading: isLoadingPages,
45
- totalItems,
46
- totalPages
47
- } = useEntityRecords( 'postType', 'page', {
48
- per_page: view.perPage,
49
- page: view.page,
50
- order: view.sort?.direction,
51
- orderby: view.sort?.field
52
- ...view.filters
53
- } );
72
+ function MyCustomPageList() {
73
+ const [ view, setView ] = useState( {
74
+ type: 'list',
75
+ page: 1,
76
+ "...": "..."
77
+ } );
78
+
79
+ const queryArgs = useMemo(
80
+ () => ( {
81
+ per_page: view.perPage,
82
+ page: view.page,
83
+ order: view.sort?.direction,
84
+ orderby: view.sort?.field
85
+ search: view.search,
86
+ ...view.filters
87
+ } ),
88
+ [ view ]
89
+ );
90
+
91
+ const {
92
+ records
93
+ } = useEntityRecords( 'postType', 'page', queryArgs );
94
+
95
+ return (
96
+ <DataViews
97
+ data={ records }
98
+ view={ view }
99
+ onChangeView={ setView }
100
+ "..."
101
+ />
102
+ );
103
+ }
54
104
  ```
55
105
 
56
106
  ## Fields
57
107
 
58
- The fields describe the dataset. For example:
108
+ The fields describe the visible items for each record in the dataset.
109
+
110
+ Example:
59
111
 
60
112
  ```js
61
113
  [
114
+ {
115
+ id: 'date',
116
+ header: __( 'Date' ),
117
+ getValue: ( { item } ) => item.date,
118
+ render: ( { item } ) => {
119
+ return (
120
+ <time>{ getFormattedDate( item.date ) }</time>
121
+ );
122
+ }
123
+ },
62
124
  {
63
125
  id: 'author',
64
126
  header: __( 'Author' ),
65
127
  getValue: ( { item } ) => item.author,
66
- render: ( {item} ) => {
128
+ render: ( { item } ) => {
67
129
  return (
68
130
  <a href="...">{ item.author }</a>
69
131
  );
70
132
  },
71
133
  elements: [
72
- { value: 1, label: 'admin' }
73
- { value: 2, label: 'user' }
134
+ { value: 1, label: 'Admin' }
135
+ { value: 2, label: 'User' }
74
136
  ]
75
- filters: [
76
- { id: 'author', type: 'enumeration' },
77
- { id: 'author_search', type: 'search' }
78
- ],
79
- },
137
+ filters: [ 'enumeration' ],
138
+ }
80
139
  ]
81
140
  ```
82
141
 
83
142
  - `id`: identifier for the field. Unique.
84
- - `header`: the field name for the UI.
143
+ - `header`: the field's name to be shown in the UI.
85
144
  - `getValue`: function that returns the value of the field.
86
145
  - `render`: function that renders the field.
87
- - `elements`: a set of valid values for the field.
88
- - `filters`: what filters are available. A filter is an object with `id` and `type` as properties:
89
- - `id`: unique identifier for the filter. Matches the entity query param.
90
- - `type`: the type of filter. One of `search` or `enumeration`.
91
-
146
+ - `elements`: the set of valid values for the field's value.
147
+ - `filters`: what filters are available for the user to use. See filters section.
92
148
 
93
- ## DataViews
149
+ ## Filters
94
150
 
95
- The UI component responsible for rendering the dataset.
151
+ Filters describe the conditions a record should match to be listed as part of the dataset. Filters are provided per field.
96
152
 
97
153
  ```js
154
+ const field = [
155
+ {
156
+ id: 'author',
157
+ filters: [ 'enumeration' ],
158
+ }
159
+ ];
160
+
98
161
  <DataViews
99
- data={ pages }
100
- isLoading= { isLoadingPages }
101
162
  fields={ fields }
102
- view={ view }
103
- onChangeView={ onChangeView }
104
- actions={ [ trashPostAction ] }
105
- paginationInfo={ { totalItems, totalPages } }
106
163
  />
107
164
  ```
165
+
166
+ A filter is an object that may contain the following properties:
167
+
168
+ - `id`: unique identifier for the filter. Matches the entity query param. Field filters may omit it, in which case the field's `id` will be used.
169
+ - `name`: nice looking name for the filter. Field filters may omit it, in which case the field's `header` will be used.
170
+ - `type`: the type of filter. Only `enumeration` is supported at the moment.
171
+ - `elements`: for filters of type `enumeration`, the list of options to show. A one-dimensional array of object with value/label keys, as in `[ { value: 1, label: "Value name" } ]`.
172
+ - `value`: what's serialized into the view's filters.
173
+ - `label`: nice-looking name for users.
174
+ - `resetValue`: for filters of type `enumeration`, this is the value for the reset option. If none is provided, `''` will be used.
175
+ - `resetLabel`: for filters of type `enumeration`, this is the label for the reset option. If none is provided, `All` will be used.
176
+
177
+ As a convenience, field's filter can provide abbreviated versions for the filter. All of following examples result in the same filter:
178
+
179
+ ```js
180
+ const field = [
181
+ {
182
+ id: 'author',
183
+ header: __( 'Author' ),
184
+ elements: authors,
185
+ filters: [
186
+ 'enumeration',
187
+ { type: 'enumeration' },
188
+ { id: 'author', type: 'enumeration' },
189
+ { id: 'author', type: 'enumeration', name: __( 'Author' ) },
190
+ { id: 'author', type: 'enumeration', name: __( 'Author' ), elements: authors },
191
+ ],
192
+ }
193
+ ];
194
+ ```
@@ -14,12 +14,15 @@ import ViewList from './view-list';
14
14
  import Pagination from './pagination';
15
15
  import ViewActions from './view-actions';
16
16
  import Filters from './filters';
17
+ import Search from './search';
17
18
  import { ViewGrid } from './view-grid';
18
19
 
19
20
  export default function DataViews( {
20
21
  view,
21
22
  onChangeView,
22
23
  fields,
24
+ search = true,
25
+ searchLabel = undefined,
23
26
  actions,
24
27
  data,
25
28
  isLoading = false,
@@ -34,9 +37,16 @@ export default function DataViews( {
34
37
  }, [ fields ] );
35
38
  return (
36
39
  <div className="dataviews-wrapper">
37
- <VStack spacing={ 4 }>
40
+ <VStack spacing={ 4 } justify="flex-start">
38
41
  <HStack>
39
42
  <HStack justify="start">
43
+ { search && (
44
+ <Search
45
+ label={ searchLabel }
46
+ view={ view }
47
+ onChangeView={ onChangeView }
48
+ />
49
+ ) }
40
50
  <Filters
41
51
  fields={ fields }
42
52
  view={ view }