@wordpress/edit-site 5.20.1 → 5.21.1-next.f8d8eceb.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 (260) 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/add-new-template/add-custom-template-modal-content.js +17 -13
  5. package/build/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
  6. package/build/components/block-editor/resize-handle.js +2 -1
  7. package/build/components/block-editor/resize-handle.js.map +1 -1
  8. package/build/components/block-editor/use-site-editor-settings.js +12 -4
  9. package/build/components/block-editor/use-site-editor-settings.js.map +1 -1
  10. package/build/components/create-template-part-modal/index.js +10 -6
  11. package/build/components/create-template-part-modal/index.js.map +1 -1
  12. package/build/components/dataviews/context.js +15 -0
  13. package/build/components/dataviews/context.js.map +1 -0
  14. package/build/components/dataviews/dataviews.js +50 -33
  15. package/build/components/dataviews/dataviews.js.map +1 -1
  16. package/build/components/dataviews/filters.js +74 -0
  17. package/build/components/dataviews/filters.js.map +1 -0
  18. package/build/components/dataviews/in-filter.js +49 -0
  19. package/build/components/dataviews/in-filter.js.map +1 -0
  20. package/build/components/dataviews/index.js +0 -7
  21. package/build/components/dataviews/index.js.map +1 -1
  22. package/build/components/dataviews/item-actions.js +62 -0
  23. package/build/components/dataviews/item-actions.js.map +1 -0
  24. package/build/components/dataviews/pagination.js +74 -45
  25. package/build/components/dataviews/pagination.js.map +1 -1
  26. package/build/components/dataviews/{text-filter.js → search.js} +21 -15
  27. package/build/components/dataviews/search.js.map +1 -0
  28. package/build/components/dataviews/view-actions.js +94 -56
  29. package/build/components/dataviews/view-actions.js.map +1 -1
  30. package/build/components/dataviews/view-grid.js +59 -0
  31. package/build/components/dataviews/view-grid.js.map +1 -0
  32. package/build/components/dataviews/view-list.js +283 -0
  33. package/build/components/dataviews/view-list.js.map +1 -0
  34. package/build/components/editor/index.js +2 -1
  35. package/build/components/editor/index.js.map +1 -1
  36. package/build/components/global-styles/font-library-modal/context.js +16 -10
  37. package/build/components/global-styles/font-library-modal/context.js.map +1 -1
  38. package/build/components/global-styles/font-library-modal/font-collection.js +20 -6
  39. package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  40. package/build/components/global-styles/screen-block.js +2 -10
  41. package/build/components/global-styles/screen-block.js.map +1 -1
  42. package/build/components/global-styles/screen-root.js +1 -2
  43. package/build/components/global-styles/screen-root.js.map +1 -1
  44. package/build/components/global-styles/ui.js +3 -4
  45. package/build/components/global-styles/ui.js.map +1 -1
  46. package/build/components/layout/index.js +10 -2
  47. package/build/components/layout/index.js.map +1 -1
  48. package/build/components/media/index.js +34 -0
  49. package/build/components/media/index.js.map +1 -0
  50. package/build/components/page-actions/index.js +0 -2
  51. package/build/components/page-actions/index.js.map +1 -1
  52. package/build/components/page-pages/default-views.js +60 -0
  53. package/build/components/page-pages/default-views.js.map +1 -0
  54. package/build/components/page-pages/index.js +174 -107
  55. package/build/components/page-pages/index.js.map +1 -1
  56. package/build/components/page-patterns/delete-category-menu-item.js +89 -0
  57. package/build/components/page-patterns/delete-category-menu-item.js.map +1 -0
  58. package/build/components/page-patterns/duplicate-menu-item.js +52 -131
  59. package/build/components/page-patterns/duplicate-menu-item.js.map +1 -1
  60. package/build/components/page-patterns/grid-item.js +1 -0
  61. package/build/components/page-patterns/grid-item.js.map +1 -1
  62. package/build/components/page-patterns/header.js +25 -3
  63. package/build/components/page-patterns/header.js.map +1 -1
  64. package/build/components/page-patterns/rename-category-menu-item.js +49 -0
  65. package/build/components/page-patterns/rename-category-menu-item.js.map +1 -0
  66. package/build/components/page-patterns/rename-menu-item.js +1 -1
  67. package/build/components/page-patterns/rename-menu-item.js.map +1 -1
  68. package/build/components/page-patterns/use-patterns.js +1 -0
  69. package/build/components/page-patterns/use-patterns.js.map +1 -1
  70. package/build/components/pattern-modal/duplicate.js +65 -0
  71. package/build/components/pattern-modal/duplicate.js.map +1 -0
  72. package/build/components/pattern-modal/index.js +24 -0
  73. package/build/components/pattern-modal/index.js.map +1 -0
  74. package/build/components/pattern-modal/rename.js +42 -0
  75. package/build/components/pattern-modal/rename.js.map +1 -0
  76. package/build/components/sidebar/index.js +3 -1
  77. package/build/components/sidebar/index.js.map +1 -1
  78. package/build/components/sidebar-dataviews/index.js +72 -0
  79. package/build/components/sidebar-dataviews/index.js.map +1 -0
  80. package/build/components/sidebar-edit-mode/template-panel/last-revision.js +3 -0
  81. package/build/components/sidebar-edit-mode/template-panel/last-revision.js.map +1 -1
  82. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js +2 -2
  83. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js.map +1 -1
  84. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +2 -3
  85. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
  86. package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js +29 -0
  87. package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js.map +1 -0
  88. package/build/components/sidebar-navigation-screen-template/home-template-details.js +12 -1
  89. package/build/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
  90. package/build/hooks/commands/use-common-commands.js +1 -2
  91. package/build/hooks/commands/use-common-commands.js.map +1 -1
  92. package/build/hooks/commands/use-edit-mode-commands.js +50 -0
  93. package/build/hooks/commands/use-edit-mode-commands.js.map +1 -1
  94. package/build/lock-unlock.js +1 -1
  95. package/build/lock-unlock.js.map +1 -1
  96. package/build/store/selectors.js +4 -5
  97. package/build/store/selectors.js.map +1 -1
  98. package/build-module/components/actions/index.js +108 -0
  99. package/build-module/components/actions/index.js.map +1 -0
  100. package/build-module/components/add-new-template/add-custom-template-modal-content.js +16 -12
  101. package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
  102. package/build-module/components/block-editor/resize-handle.js +2 -1
  103. package/build-module/components/block-editor/resize-handle.js.map +1 -1
  104. package/build-module/components/block-editor/use-site-editor-settings.js +12 -4
  105. package/build-module/components/block-editor/use-site-editor-settings.js.map +1 -1
  106. package/build-module/components/create-template-part-modal/index.js +10 -6
  107. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  108. package/build-module/components/dataviews/context.js +7 -0
  109. package/build-module/components/dataviews/context.js.map +1 -0
  110. package/build-module/components/dataviews/dataviews.js +49 -32
  111. package/build-module/components/dataviews/dataviews.js.map +1 -1
  112. package/build-module/components/dataviews/filters.js +66 -0
  113. package/build-module/components/dataviews/filters.js.map +1 -0
  114. package/build-module/components/dataviews/in-filter.js +41 -0
  115. package/build-module/components/dataviews/in-filter.js.map +1 -0
  116. package/build-module/components/dataviews/index.js +0 -1
  117. package/build-module/components/dataviews/index.js.map +1 -1
  118. package/build-module/components/dataviews/item-actions.js +55 -0
  119. package/build-module/components/dataviews/item-actions.js.map +1 -0
  120. package/build-module/components/dataviews/pagination.js +73 -46
  121. package/build-module/components/dataviews/pagination.js.map +1 -1
  122. package/build-module/components/dataviews/search.js +42 -0
  123. package/build-module/components/dataviews/search.js.map +1 -0
  124. package/build-module/components/dataviews/view-actions.js +95 -54
  125. package/build-module/components/dataviews/view-actions.js.map +1 -1
  126. package/build-module/components/dataviews/view-grid.js +51 -0
  127. package/build-module/components/dataviews/view-grid.js.map +1 -0
  128. package/build-module/components/dataviews/view-list.js +274 -0
  129. package/build-module/components/dataviews/view-list.js.map +1 -0
  130. package/build-module/components/editor/index.js +2 -1
  131. package/build-module/components/editor/index.js.map +1 -1
  132. package/build-module/components/global-styles/font-library-modal/context.js +16 -10
  133. package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
  134. package/build-module/components/global-styles/font-library-modal/font-collection.js +20 -6
  135. package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  136. package/build-module/components/global-styles/screen-block.js +2 -10
  137. package/build-module/components/global-styles/screen-block.js.map +1 -1
  138. package/build-module/components/global-styles/screen-root.js +1 -2
  139. package/build-module/components/global-styles/screen-root.js.map +1 -1
  140. package/build-module/components/global-styles/ui.js +3 -4
  141. package/build-module/components/global-styles/ui.js.map +1 -1
  142. package/build-module/components/layout/index.js +11 -3
  143. package/build-module/components/layout/index.js.map +1 -1
  144. package/build-module/components/media/index.js +26 -0
  145. package/build-module/components/media/index.js.map +1 -0
  146. package/build-module/components/page-actions/index.js +0 -2
  147. package/build-module/components/page-actions/index.js.map +1 -1
  148. package/build-module/components/page-pages/default-views.js +53 -0
  149. package/build-module/components/page-pages/default-views.js.map +1 -0
  150. package/build-module/components/page-pages/index.js +175 -110
  151. package/build-module/components/page-pages/index.js.map +1 -1
  152. package/build-module/components/page-patterns/delete-category-menu-item.js +82 -0
  153. package/build-module/components/page-patterns/delete-category-menu-item.js.map +1 -0
  154. package/build-module/components/page-patterns/duplicate-menu-item.js +54 -133
  155. package/build-module/components/page-patterns/duplicate-menu-item.js.map +1 -1
  156. package/build-module/components/page-patterns/grid-item.js +1 -0
  157. package/build-module/components/page-patterns/grid-item.js.map +1 -1
  158. package/build-module/components/page-patterns/header.js +26 -4
  159. package/build-module/components/page-patterns/header.js.map +1 -1
  160. package/build-module/components/page-patterns/rename-category-menu-item.js +42 -0
  161. package/build-module/components/page-patterns/rename-category-menu-item.js.map +1 -0
  162. package/build-module/components/page-patterns/rename-menu-item.js +1 -1
  163. package/build-module/components/page-patterns/rename-menu-item.js.map +1 -1
  164. package/build-module/components/page-patterns/use-patterns.js +1 -0
  165. package/build-module/components/page-patterns/use-patterns.js.map +1 -1
  166. package/build-module/components/pattern-modal/duplicate.js +57 -0
  167. package/build-module/components/pattern-modal/duplicate.js.map +1 -0
  168. package/build-module/components/pattern-modal/index.js +14 -0
  169. package/build-module/components/pattern-modal/index.js.map +1 -0
  170. package/build-module/components/pattern-modal/rename.js +34 -0
  171. package/build-module/components/pattern-modal/rename.js.map +1 -0
  172. package/build-module/components/sidebar/index.js +3 -1
  173. package/build-module/components/sidebar/index.js.map +1 -1
  174. package/build-module/components/sidebar-dataviews/index.js +64 -0
  175. package/build-module/components/sidebar-dataviews/index.js.map +1 -0
  176. package/build-module/components/sidebar-edit-mode/template-panel/last-revision.js +3 -0
  177. package/build-module/components/sidebar-edit-mode/template-panel/last-revision.js.map +1 -1
  178. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js +2 -2
  179. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js.map +1 -1
  180. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +2 -3
  181. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
  182. package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js +22 -0
  183. package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js.map +1 -0
  184. package/build-module/components/sidebar-navigation-screen-template/home-template-details.js +12 -1
  185. package/build-module/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
  186. package/build-module/hooks/commands/use-common-commands.js +1 -2
  187. package/build-module/hooks/commands/use-common-commands.js.map +1 -1
  188. package/build-module/hooks/commands/use-edit-mode-commands.js +51 -1
  189. package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -1
  190. package/build-module/lock-unlock.js +1 -1
  191. package/build-module/lock-unlock.js.map +1 -1
  192. package/build-module/store/selectors.js +4 -5
  193. package/build-module/store/selectors.js.map +1 -1
  194. package/build-style/style-rtl.css +48 -11
  195. package/build-style/style.css +48 -11
  196. package/package.json +40 -40
  197. package/src/components/actions/index.js +123 -0
  198. package/src/components/add-new-template/add-custom-template-modal-content.js +22 -17
  199. package/src/components/block-editor/resize-handle.js +1 -0
  200. package/src/components/block-editor/use-site-editor-settings.js +21 -13
  201. package/src/components/create-template-part-modal/index.js +9 -5
  202. package/src/components/dataviews/README.md +194 -0
  203. package/src/components/dataviews/context.js +7 -0
  204. package/src/components/dataviews/dataviews.js +55 -34
  205. package/src/components/dataviews/filters.js +75 -0
  206. package/src/components/dataviews/in-filter.js +45 -0
  207. package/src/components/dataviews/index.js +0 -1
  208. package/src/components/dataviews/item-actions.js +69 -0
  209. package/src/components/dataviews/pagination.js +80 -59
  210. package/src/components/dataviews/search.js +41 -0
  211. package/src/components/dataviews/style.scss +18 -3
  212. package/src/components/dataviews/view-actions.js +108 -63
  213. package/src/components/dataviews/view-grid.js +65 -0
  214. package/src/components/dataviews/view-list.js +348 -0
  215. package/src/components/editor/index.js +2 -0
  216. package/src/components/global-styles/font-library-modal/context.js +17 -11
  217. package/src/components/global-styles/font-library-modal/font-collection.js +19 -11
  218. package/src/components/global-styles/screen-block.js +2 -9
  219. package/src/components/global-styles/screen-root.js +1 -2
  220. package/src/components/global-styles/style.scss +16 -4
  221. package/src/components/global-styles/ui.js +1 -2
  222. package/src/components/layout/index.js +12 -4
  223. package/src/components/media/index.js +25 -0
  224. package/src/components/page-actions/index.js +1 -7
  225. package/src/components/page-pages/default-views.js +58 -0
  226. package/src/components/page-pages/index.js +181 -108
  227. package/src/components/page-pages/style.scss +3 -0
  228. package/src/components/page-patterns/delete-category-menu-item.js +104 -0
  229. package/src/components/page-patterns/duplicate-menu-item.js +68 -181
  230. package/src/components/page-patterns/grid-item.js +1 -0
  231. package/src/components/page-patterns/header.js +42 -6
  232. package/src/components/page-patterns/rename-category-menu-item.js +45 -0
  233. package/src/components/page-patterns/rename-menu-item.js +2 -2
  234. package/src/components/page-patterns/style.scss +8 -0
  235. package/src/components/page-patterns/use-patterns.js +5 -0
  236. package/src/components/pattern-modal/duplicate.js +53 -0
  237. package/src/components/pattern-modal/index.js +19 -0
  238. package/src/components/pattern-modal/rename.js +29 -0
  239. package/src/components/sidebar/index.js +2 -0
  240. package/src/components/sidebar-dataviews/index.js +65 -0
  241. package/src/components/sidebar-edit-mode/template-panel/last-revision.js +4 -0
  242. package/src/components/sidebar-navigation-screen/style.scss +17 -5
  243. package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js +2 -7
  244. package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +2 -8
  245. package/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js +32 -0
  246. package/src/components/sidebar-navigation-screen-template/home-template-details.js +21 -7
  247. package/src/hooks/commands/use-common-commands.js +1 -2
  248. package/src/hooks/commands/use-edit-mode-commands.js +43 -0
  249. package/src/lock-unlock.js +1 -1
  250. package/src/store/selectors.js +9 -10
  251. package/src/style.scss +1 -0
  252. package/build/components/dataviews/list-view.js +0 -89
  253. package/build/components/dataviews/list-view.js.map +0 -1
  254. package/build/components/dataviews/text-filter.js.map +0 -1
  255. package/build-module/components/dataviews/list-view.js +0 -80
  256. package/build-module/components/dataviews/list-view.js.map +0 -1
  257. package/build-module/components/dataviews/text-filter.js +0 -36
  258. package/build-module/components/dataviews/text-filter.js.map +0 -1
  259. package/src/components/dataviews/list-view.js +0 -106
  260. package/src/components/dataviews/text-filter.js +0 -37
@@ -0,0 +1,194 @@
1
+ # DataView
2
+
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
+ ```
29
+
30
+ ## View
31
+
32
+ The view object configures how the dataset is visible to the user.
33
+
34
+ Example:
35
+
36
+ ```js
37
+ {
38
+ type: 'list',
39
+ perPage: 5,
40
+ page: 1,
41
+ sort: {
42
+ field: 'date',
43
+ direction: 'desc',
44
+ },
45
+ search: '',
46
+ filters: {
47
+ author: 2,
48
+ status: 'publish, draft'
49
+ },
50
+ visibleFilters: [ 'author', 'status' ],
51
+ hiddenFields: [ 'date', 'featured-image' ],
52
+ layout: {},
53
+ }
54
+ ```
55
+
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.
63
+ - `visibleFilters`: the `id` of the filters that are visible in the UI.
64
+ - `hiddenFields`: the `id` of the fields that are hidden in the UI.
65
+ - `layout`: ...
66
+
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:
70
+
71
+ ```js
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
+ }
104
+ ```
105
+
106
+ ## Fields
107
+
108
+ The fields describe the visible items for each record in the dataset.
109
+
110
+ Example:
111
+
112
+ ```js
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
+ },
124
+ {
125
+ id: 'author',
126
+ header: __( 'Author' ),
127
+ getValue: ( { item } ) => item.author,
128
+ render: ( { item } ) => {
129
+ return (
130
+ <a href="...">{ item.author }</a>
131
+ );
132
+ },
133
+ elements: [
134
+ { value: 1, label: 'Admin' }
135
+ { value: 2, label: 'User' }
136
+ ]
137
+ filters: [ 'enumeration' ],
138
+ }
139
+ ]
140
+ ```
141
+
142
+ - `id`: identifier for the field. Unique.
143
+ - `header`: the field's name to be shown in the UI.
144
+ - `getValue`: function that returns the value of the field.
145
+ - `render`: function that renders the field.
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.
148
+
149
+ ## Filters
150
+
151
+ Filters describe the conditions a record should match to be listed as part of the dataset. Filters are provided per field.
152
+
153
+ ```js
154
+ const field = [
155
+ {
156
+ id: 'author',
157
+ filters: [ 'enumeration' ],
158
+ }
159
+ ];
160
+
161
+ <DataViews
162
+ fields={ fields }
163
+ />
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
+ ```
@@ -0,0 +1,7 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { createContext } from '@wordpress/element';
5
+
6
+ const DataviewsContext = createContext( {} );
7
+ export default DataviewsContext;
@@ -1,14 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import {
5
- getCoreRowModel,
6
- getFilteredRowModel,
7
- getSortedRowModel,
8
- getPaginationRowModel,
9
- useReactTable,
10
- } from '@tanstack/react-table';
11
-
12
1
  /**
13
2
  * WordPress dependencies
14
3
  */
@@ -16,43 +5,75 @@ import {
16
5
  __experimentalVStack as VStack,
17
6
  __experimentalHStack as HStack,
18
7
  } from '@wordpress/components';
8
+ import { useMemo } from '@wordpress/element';
19
9
 
20
10
  /**
21
11
  * Internal dependencies
22
12
  */
23
- import ListView from './list-view';
24
- import { Pagination } from './pagination';
13
+ import ViewList from './view-list';
14
+ import Pagination from './pagination';
25
15
  import ViewActions from './view-actions';
26
- import TextFilter from './text-filter';
16
+ import Filters from './filters';
17
+ import Search from './search';
18
+ import { ViewGrid } from './view-grid';
27
19
 
28
20
  export default function DataViews( {
29
- data,
21
+ view,
22
+ onChangeView,
30
23
  fields,
31
- isLoading,
24
+ search = true,
25
+ searchLabel = undefined,
26
+ actions,
27
+ data,
28
+ isLoading = false,
32
29
  paginationInfo,
33
- options,
34
30
  } ) {
35
- const dataView = useReactTable( {
36
- data,
37
- columns: fields,
38
- ...options,
39
- getCoreRowModel: getCoreRowModel(),
40
- getFilteredRowModel: getFilteredRowModel(),
41
- getSortedRowModel: getSortedRowModel(),
42
- getPaginationRowModel: getPaginationRowModel(),
43
- } );
31
+ const ViewComponent = view.type === 'list' ? ViewList : ViewGrid;
32
+ const _fields = useMemo( () => {
33
+ return fields.map( ( field ) => ( {
34
+ ...field,
35
+ render: field.render || field.getValue,
36
+ } ) );
37
+ }, [ fields ] );
44
38
  return (
45
39
  <div className="dataviews-wrapper">
46
- <VStack spacing={ 4 }>
47
- <HStack justify="space-between">
48
- <TextFilter onChange={ dataView.setGlobalFilter } />
49
- <ViewActions dataView={ dataView } />
40
+ <VStack spacing={ 4 } justify="flex-start">
41
+ <HStack>
42
+ <HStack justify="start">
43
+ { search && (
44
+ <Search
45
+ label={ searchLabel }
46
+ view={ view }
47
+ onChangeView={ onChangeView }
48
+ />
49
+ ) }
50
+ <Filters
51
+ fields={ fields }
52
+ view={ view }
53
+ onChangeView={ onChangeView }
54
+ />
55
+ </HStack>
56
+ <HStack justify="end">
57
+ <ViewActions
58
+ fields={ fields }
59
+ view={ view }
60
+ onChangeView={ onChangeView }
61
+ />
62
+ </HStack>
50
63
  </HStack>
51
- { /* This component will be selected based on viewConfigs. Now we only have the list view. */ }
52
- <ListView dataView={ dataView } isLoading={ isLoading } />
64
+ <ViewComponent
65
+ fields={ _fields }
66
+ view={ view }
67
+ onChangeView={ onChangeView }
68
+ paginationInfo={ paginationInfo }
69
+ actions={ actions }
70
+ data={ data }
71
+ isLoading={ isLoading }
72
+ />
53
73
  <Pagination
54
- dataView={ dataView }
55
- totalItems={ paginationInfo?.totalItems }
74
+ view={ view }
75
+ onChangeView={ onChangeView }
76
+ paginationInfo={ paginationInfo }
56
77
  />
57
78
  </VStack>
58
79
  </div>
@@ -0,0 +1,75 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import InFilter from './in-filter';
10
+
11
+ export default function Filters( { fields, view, onChangeView } ) {
12
+ const filterIndex = {};
13
+ fields.forEach( ( field ) => {
14
+ if ( ! field.filters ) {
15
+ return;
16
+ }
17
+
18
+ field.filters.forEach( ( filter ) => {
19
+ let id = field.id;
20
+ if ( 'string' === typeof filter ) {
21
+ filterIndex[ id ] = {
22
+ id,
23
+ name: field.header,
24
+ type: filter,
25
+ };
26
+ }
27
+
28
+ if ( 'object' === typeof filter ) {
29
+ id = filter.id || field.id;
30
+ filterIndex[ id ] = {
31
+ id,
32
+ name: filter.name || field.header,
33
+ type: filter.type,
34
+ };
35
+ }
36
+
37
+ if ( 'enumeration' === filterIndex[ id ]?.type ) {
38
+ const elements = [
39
+ {
40
+ value: filter.resetValue || '',
41
+ label: filter.resetLabel || __( 'All' ),
42
+ },
43
+ ...( field.elements || [] ),
44
+ ];
45
+ filterIndex[ id ] = {
46
+ ...filterIndex[ id ],
47
+ elements,
48
+ };
49
+ }
50
+ } );
51
+ } );
52
+
53
+ return (
54
+ view.visibleFilters?.map( ( filterName ) => {
55
+ const filter = filterIndex[ filterName ];
56
+
57
+ if ( ! filter ) {
58
+ return null;
59
+ }
60
+
61
+ if ( filter.type === 'enumeration' ) {
62
+ return (
63
+ <InFilter
64
+ key={ filterName }
65
+ filter={ filter }
66
+ view={ view }
67
+ onChangeView={ onChangeView }
68
+ />
69
+ );
70
+ }
71
+
72
+ return null;
73
+ } ) || __( 'No filters available' )
74
+ );
75
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ __experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,
6
+ SelectControl,
7
+ } from '@wordpress/components';
8
+ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import { unlock } from '../../lock-unlock';
14
+
15
+ const { cleanEmptyObject } = unlock( blockEditorPrivateApis );
16
+
17
+ export default ( { filter, view, onChangeView } ) => {
18
+ return (
19
+ <SelectControl
20
+ value={ view.filters[ filter.id ] }
21
+ prefix={
22
+ <InputControlPrefixWrapper
23
+ as="span"
24
+ className="dataviews__select-control-prefix"
25
+ >
26
+ { filter.name + ':' }
27
+ </InputControlPrefixWrapper>
28
+ }
29
+ options={ filter.elements }
30
+ onChange={ ( value ) => {
31
+ if ( value === '' ) {
32
+ value = undefined;
33
+ }
34
+
35
+ onChangeView( ( currentView ) => ( {
36
+ ...currentView,
37
+ filters: cleanEmptyObject( {
38
+ ...currentView.filters,
39
+ [ filter.id ]: value,
40
+ } ),
41
+ } ) );
42
+ } }
43
+ />
44
+ );
45
+ };
@@ -1,2 +1 @@
1
1
  export { default as DataViews } from './dataviews';
2
- export { PAGE_SIZE_VALUES } from './view-actions';
@@ -0,0 +1,69 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ DropdownMenu,
6
+ MenuGroup,
7
+ MenuItem,
8
+ Button,
9
+ __experimentalHStack as HStack,
10
+ } from '@wordpress/components';
11
+ import { __ } from '@wordpress/i18n';
12
+ import { useMemo } from '@wordpress/element';
13
+ import { moreVertical } from '@wordpress/icons';
14
+
15
+ export default function ItemActions( { item, actions } ) {
16
+ const { primaryActions, secondaryActions } = useMemo( () => {
17
+ return actions.reduce(
18
+ ( accumulator, action ) => {
19
+ // If an action is eligible for all items, doesn't need
20
+ // to provide the `isEligible` function.
21
+ if ( action.isEligible && ! action.isEligible( item ) ) {
22
+ return accumulator;
23
+ }
24
+ if ( action.isPrimary && !! action.icon ) {
25
+ accumulator.primaryActions.push( action );
26
+ } else {
27
+ accumulator.secondaryActions.push( action );
28
+ }
29
+ return accumulator;
30
+ },
31
+ { primaryActions: [], secondaryActions: [] }
32
+ );
33
+ }, [ actions, item ] );
34
+ if ( ! primaryActions.length && ! secondaryActions.length ) {
35
+ return null;
36
+ }
37
+ return (
38
+ <HStack justify="flex-end">
39
+ { !! primaryActions.length &&
40
+ primaryActions.map( ( action ) => (
41
+ <Button
42
+ label={ action.label }
43
+ key={ action.id }
44
+ icon={ action.icon }
45
+ onClick={ () => action.perform( item ) }
46
+ isDestructive={ action.isDestructive }
47
+ size="compact"
48
+ />
49
+ ) ) }
50
+ { !! secondaryActions.length && (
51
+ <DropdownMenu icon={ moreVertical } label={ __( 'Actions' ) }>
52
+ { () => (
53
+ <MenuGroup>
54
+ { secondaryActions.map( ( action ) => (
55
+ <MenuItem
56
+ key={ action.id }
57
+ onClick={ () => action.perform( item ) }
58
+ isDestructive={ action.isDestructive }
59
+ >
60
+ { action.label }
61
+ </MenuItem>
62
+ ) ) }
63
+ </MenuGroup>
64
+ ) }
65
+ </DropdownMenu>
66
+ ) }
67
+ </HStack>
68
+ );
69
+ }
@@ -9,23 +9,16 @@ import {
9
9
  } from '@wordpress/components';
10
10
  import { createInterpolateElement } from '@wordpress/element';
11
11
  import { sprintf, __, _x, _n } from '@wordpress/i18n';
12
+ import { chevronRight, chevronLeft, previous, next } from '@wordpress/icons';
12
13
 
13
- /**
14
- * Internal dependencies
15
- */
16
- import { PageSizeControl } from './view-actions';
17
-
18
- // For now this is copied from the patterns list Pagination component, because
19
- // the datatable pagination starts from index zero(`0`). Eventually all lists will be
20
- // using this one.
21
- export function Pagination( {
22
- dataView,
23
- // If passed, use it, as it's for controlled pagination.
24
- totalItems = 0,
14
+ function Pagination( {
15
+ view,
16
+ onChangeView,
17
+ paginationInfo: { totalItems = 0, totalPages },
25
18
  } ) {
26
- const currentPage = dataView.getState().pagination.pageIndex + 1;
27
- const numPages = dataView.getPageCount();
28
- const _totalItems = totalItems || dataView.getCoreRowModel().rows.length;
19
+ if ( ! totalItems || ! totalPages ) {
20
+ return null;
21
+ }
29
22
  return (
30
23
  <HStack
31
24
  expanded={ false }
@@ -38,53 +31,72 @@ export function Pagination( {
38
31
  // translators: %s: Total number of entries.
39
32
  sprintf(
40
33
  // translators: %s: Total number of entries.
41
- _n( '%s item', '%s items', _totalItems ),
42
- _totalItems
34
+ _n( '%s item', '%s items', totalItems ),
35
+ totalItems
43
36
  )
44
37
  }
45
38
  </Text>
46
- { !! _totalItems && (
47
- <HStack expanded={ false } spacing={ 1 }>
48
- <Button
49
- variant="tertiary"
50
- onClick={ () => dataView.setPageIndex( 0 ) }
51
- disabled={ ! dataView.getCanPreviousPage() }
52
- aria-label={ __( 'First page' ) }
53
- >
54
- «
55
- </Button>
56
- <Button
57
- variant="tertiary"
58
- onClick={ () => dataView.previousPage() }
59
- disabled={ ! dataView.getCanPreviousPage() }
60
- aria-label={ __( 'Previous page' ) }
61
- >
62
-
63
- </Button>
39
+ { !! totalItems && (
40
+ <HStack expanded={ false } spacing={ 3 }>
64
41
  <HStack
65
42
  justify="flex-start"
66
43
  expanded={ false }
67
44
  spacing={ 1 }
45
+ >
46
+ <Button
47
+ onClick={ () =>
48
+ onChangeView( { ...view, page: 1 } )
49
+ }
50
+ disabled={ view.page === 1 }
51
+ label={ __( 'First page' ) }
52
+ icon={ previous }
53
+ showTooltip
54
+ size="compact"
55
+ />
56
+ <Button
57
+ onClick={ () =>
58
+ onChangeView( { ...view, page: view.page - 1 } )
59
+ }
60
+ disabled={ view.page === 1 }
61
+ label={ __( 'Previous page' ) }
62
+ icon={ chevronLeft }
63
+ showTooltip
64
+ size="compact"
65
+ />
66
+ </HStack>
67
+ <HStack
68
+ justify="flex-start"
69
+ expanded={ false }
70
+ spacing={ 2 }
68
71
  >
69
72
  { createInterpolateElement(
70
73
  sprintf(
71
74
  // translators: %1$s: Current page number, %2$s: Total number of pages.
72
75
  _x( '<CurrenPageControl /> of %2$s', 'paging' ),
73
- currentPage,
74
- numPages
76
+ view.page,
77
+ totalPages
75
78
  ),
76
79
  {
77
80
  CurrenPageControl: (
78
81
  <NumberControl
79
82
  aria-label={ __( 'Current page' ) }
80
83
  min={ 1 }
81
- max={ numPages }
84
+ max={ totalPages }
82
85
  onChange={ ( value ) => {
83
- if ( value > numPages ) return;
84
- dataView.setPageIndex( value - 1 );
86
+ if (
87
+ ! value ||
88
+ value < 1 ||
89
+ value > totalPages
90
+ ) {
91
+ return;
92
+ }
93
+ onChangeView( {
94
+ ...view,
95
+ page: value,
96
+ } );
85
97
  } }
86
98
  step="1"
87
- value={ currentPage }
99
+ value={ view.page }
88
100
  isDragEnabled={ false }
89
101
  spinControls="none"
90
102
  />
@@ -92,27 +104,36 @@ export function Pagination( {
92
104
  }
93
105
  ) }
94
106
  </HStack>
95
- <Button
96
- variant="tertiary"
97
- onClick={ () => dataView.nextPage() }
98
- disabled={ ! dataView.getCanNextPage() }
99
- aria-label={ __( 'Next page' ) }
100
- >
101
-
102
- </Button>
103
- <Button
104
- variant="tertiary"
105
- onClick={ () =>
106
- dataView.setPageIndex( dataView.getPageCount() - 1 )
107
- }
108
- disabled={ ! dataView.getCanNextPage() }
109
- aria-label={ __( 'Last page' ) }
107
+ <HStack
108
+ justify="flex-start"
109
+ expanded={ false }
110
+ spacing={ 1 }
110
111
  >
111
- »
112
- </Button>
112
+ <Button
113
+ onClick={ () =>
114
+ onChangeView( { ...view, page: view.page + 1 } )
115
+ }
116
+ disabled={ view.page >= totalPages }
117
+ label={ __( 'Next page' ) }
118
+ icon={ chevronRight }
119
+ showTooltip
120
+ size="compact"
121
+ />
122
+ <Button
123
+ onClick={ () =>
124
+ onChangeView( { ...view, page: totalPages } )
125
+ }
126
+ disabled={ view.page >= totalPages }
127
+ label={ __( 'Last page' ) }
128
+ icon={ next }
129
+ showTooltip
130
+ size="compact"
131
+ />
132
+ </HStack>
113
133
  </HStack>
114
134
  ) }
115
- <PageSizeControl dataView={ dataView } />
116
135
  </HStack>
117
136
  );
118
137
  }
138
+
139
+ export default Pagination;