@wordpress/dataviews 0.5.2 → 0.6.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.
- package/CHANGELOG.md +2 -0
- package/README.md +156 -111
- package/build/view-grid.js +12 -3
- package/build/view-grid.js.map +1 -1
- package/build-module/view-grid.js +13 -4
- package/build-module/view-grid.js.map +1 -1
- package/build-style/style-rtl.css +3 -3
- package/build-style/style.css +3 -3
- package/package.json +11 -11
- package/src/stories/index.story.js +12 -16
- package/src/style.scss +3 -3
- package/src/view-grid.js +41 -23
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -12,85 +12,147 @@ npm install @wordpress/dataviews --save
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
```jsx
|
|
16
|
+
const Example = () => {
|
|
17
|
+
|
|
18
|
+
// Declare data, fields, etc.
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<DataViews
|
|
22
|
+
data={ data }
|
|
23
|
+
fields={ fields }
|
|
24
|
+
view={ view }
|
|
25
|
+
onChangeView={ onChangeView }
|
|
26
|
+
actions={ actions }
|
|
27
|
+
paginationInfo={ paginationInfo }
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Properties
|
|
34
|
+
|
|
35
|
+
### `data`: `Object[]`
|
|
34
36
|
|
|
35
37
|
The dataset to work with, represented as a one-dimensional array.
|
|
36
38
|
|
|
37
39
|
Example:
|
|
38
40
|
|
|
39
41
|
```js
|
|
40
|
-
[
|
|
41
|
-
{
|
|
42
|
-
|
|
42
|
+
const data = [
|
|
43
|
+
{
|
|
44
|
+
id: 1,
|
|
45
|
+
title: "Title",
|
|
46
|
+
author: "Admin",
|
|
47
|
+
date: "2012-04-23T18:25:43.511Z"
|
|
48
|
+
},
|
|
49
|
+
{ /* ... */ }
|
|
43
50
|
]
|
|
44
51
|
```
|
|
45
52
|
|
|
46
|
-
By default, dataviews would use each record's `id` as an unique identifier. If it's not, the consumer should provide a `getItemId` function that returns one.
|
|
53
|
+
By default, dataviews would use each record's `id` as an unique identifier. If it's not, the consumer should provide a `getItemId` function that returns one.
|
|
47
54
|
|
|
48
|
-
|
|
55
|
+
### `fields`: `Object[]`
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
- `totalPages`: the total number of pages, taking into account the total items in the dataset and the number of items per page provided by the user.
|
|
57
|
+
The fields describe the visible items for each record in the dataset.
|
|
52
58
|
|
|
53
|
-
|
|
59
|
+
Example:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
const fields = [
|
|
63
|
+
{
|
|
64
|
+
id: 'title',
|
|
65
|
+
header: 'Title',
|
|
66
|
+
getValue: ({ item }) => item.title,
|
|
67
|
+
enableHiding: false,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: 'date',
|
|
71
|
+
header: 'Date',
|
|
72
|
+
getValue: ( { item } ) => item.date,
|
|
73
|
+
render: ( { item } ) => {
|
|
74
|
+
return (
|
|
75
|
+
<time>{ getFormattedDate( item.date ) }</time>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'author',
|
|
81
|
+
header: __( 'Author' ),
|
|
82
|
+
getValue: ( { item } ) => item.author,
|
|
83
|
+
render: ( { item } ) => {
|
|
84
|
+
return (
|
|
85
|
+
<a href="...">{ item.author }</a>
|
|
86
|
+
);
|
|
87
|
+
},
|
|
88
|
+
type: 'enumeration',
|
|
89
|
+
elements: [
|
|
90
|
+
{ value: 1, label: 'Admin' }
|
|
91
|
+
{ value: 2, label: 'User' }
|
|
92
|
+
]
|
|
93
|
+
enableSorting: false
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Each field is an object with the following properties:
|
|
99
|
+
|
|
100
|
+
- `id`: identifier for the field. Unique.
|
|
101
|
+
- `header`: the field's name to be shown in the UI.
|
|
102
|
+
- `getValue`: function that returns the value of the field.
|
|
103
|
+
- `render`: function that renders the field. Optional, `getValue` will be used if `render` is not defined.
|
|
104
|
+
- `elements`: the set of valid values for the field's value.
|
|
105
|
+
- `type`: the type of the field. Used to generate the proper filters. Only `enumeration` available at the moment. See "Field types".
|
|
106
|
+
- `enableSorting`: whether the data can be sorted by the given field. True by default.
|
|
107
|
+
- `enableHiding`: whether the field can be hidden. True by default.
|
|
108
|
+
- `filterBy`: configuration for the filters.
|
|
109
|
+
- `operators`: the list of operators supported by the field.
|
|
110
|
+
- `isPrimary`: whether it is a primary filter. A primary filter is always visible and is not listed in the "Add filter" component, except for the list layout where it behaves like a secondary filter.
|
|
111
|
+
|
|
112
|
+
### `view`: `object`
|
|
54
113
|
|
|
55
114
|
The view object configures how the dataset is visible to the user.
|
|
56
115
|
|
|
57
116
|
Example:
|
|
58
117
|
|
|
59
118
|
```js
|
|
60
|
-
{
|
|
119
|
+
const view = {
|
|
61
120
|
type: 'table',
|
|
62
|
-
perPage: 5,
|
|
63
|
-
page: 1,
|
|
64
|
-
sort: {
|
|
65
|
-
field: 'date',
|
|
66
|
-
direction: 'desc',
|
|
67
|
-
},
|
|
68
121
|
search: '',
|
|
69
122
|
filters: [
|
|
70
123
|
{ field: 'author', operator: 'in', value: 2 },
|
|
71
124
|
{ field: 'status', operator: 'in', value: 'publish,draft' }
|
|
72
125
|
],
|
|
126
|
+
page: 1,
|
|
127
|
+
perPage: 5,
|
|
128
|
+
sort: {
|
|
129
|
+
field: 'date',
|
|
130
|
+
direction: 'desc',
|
|
131
|
+
},
|
|
73
132
|
hiddenFields: [ 'date', 'featured-image' ],
|
|
74
133
|
layout: {},
|
|
75
134
|
}
|
|
76
135
|
```
|
|
77
136
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
- `
|
|
81
|
-
- `sort.field`: field used for sorting the dataset.
|
|
82
|
-
- `sort.direction`: the direction to use for sorting, one of `asc` or `desc`.
|
|
137
|
+
Properties:
|
|
138
|
+
|
|
139
|
+
- `type`: view type, one of `table`, `grid`, `list`. See "Layout types".
|
|
83
140
|
- `search`: the text search applied to the dataset.
|
|
84
141
|
- `filters`: the filters applied to the dataset. Each item describes:
|
|
85
142
|
- `field`: which field this filter is bound to.
|
|
86
143
|
- `operator`: which type of filter it is. One of `in`, `notIn`. See "Operator types".
|
|
87
144
|
- `value`: the actual value selected by the user.
|
|
145
|
+
- `perPage`: number of records to show per page.
|
|
146
|
+
- `page`: the page that is visible.
|
|
147
|
+
- `sort`:
|
|
148
|
+
- `field`: the field used for sorting the dataset.
|
|
149
|
+
- `direction`: the direction to use for sorting, one of `asc` or `desc`.
|
|
88
150
|
- `hiddenFields`: the `id` of the fields that are hidden in the UI.
|
|
89
151
|
- `layout`: config that is specific to a particular layout type.
|
|
90
152
|
- `mediaField`: used by the `grid` and `list` layouts. The `id` of the field to be used for rendering each card's media.
|
|
91
|
-
- `primaryField`: used by the `grid` and `list` layouts. The `id` of the field to be highlighted in each card/
|
|
153
|
+
- `primaryField`: used by the `table`, `grid` and `list` layouts. The `id` of the field to be highlighted in each row/card/item.
|
|
92
154
|
|
|
93
|
-
### onChangeView
|
|
155
|
+
### `onChangeView`: `function`
|
|
94
156
|
|
|
95
157
|
The view is a representation of the visible state of the dataset: what type of layout is used to display it (table, grid, etc.), how the dataset is filtered, how it is sorted or paginated.
|
|
96
158
|
|
|
@@ -147,65 +209,17 @@ function MyCustomPageTable() {
|
|
|
147
209
|
data={ records }
|
|
148
210
|
view={ view }
|
|
149
211
|
onChangeView={ setView }
|
|
150
|
-
|
|
212
|
+
// ...
|
|
151
213
|
/>
|
|
152
214
|
);
|
|
153
215
|
}
|
|
154
216
|
```
|
|
155
217
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
The fields describe the visible items for each record in the dataset.
|
|
159
|
-
|
|
160
|
-
Example:
|
|
161
|
-
|
|
162
|
-
```js
|
|
163
|
-
[
|
|
164
|
-
{
|
|
165
|
-
id: 'date',
|
|
166
|
-
header: __( 'Date' ),
|
|
167
|
-
getValue: ( { item } ) => item.date,
|
|
168
|
-
render: ( { item } ) => {
|
|
169
|
-
return (
|
|
170
|
-
<time>{ getFormattedDate( item.date ) }</time>
|
|
171
|
-
);
|
|
172
|
-
},
|
|
173
|
-
enableHiding: false
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
id: 'author',
|
|
177
|
-
header: __( 'Author' ),
|
|
178
|
-
getValue: ( { item } ) => item.author,
|
|
179
|
-
render: ( { item } ) => {
|
|
180
|
-
return (
|
|
181
|
-
<a href="...">{ item.author }</a>
|
|
182
|
-
);
|
|
183
|
-
},
|
|
184
|
-
type: 'enumeration',
|
|
185
|
-
elements: [
|
|
186
|
-
{ value: 1, label: 'Admin' }
|
|
187
|
-
{ value: 2, label: 'User' }
|
|
188
|
-
]
|
|
189
|
-
enableSorting: false
|
|
190
|
-
}
|
|
191
|
-
]
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
- `id`: identifier for the field. Unique.
|
|
195
|
-
- `header`: the field's name to be shown in the UI.
|
|
196
|
-
- `getValue`: function that returns the value of the field.
|
|
197
|
-
- `render`: function that renders the field.
|
|
198
|
-
- `elements`: the set of valid values for the field's value.
|
|
199
|
-
- `type`: the type of the field. Used to generate the proper filters. Only `enumeration` available at the moment. See "Field types".
|
|
200
|
-
- `enableSorting`: whether the data can be sorted by the given field. True by default.
|
|
201
|
-
- `enableHiding`: whether the field can be hidden. True by default.
|
|
202
|
-
- `filterBy`: configuration for the filters.
|
|
203
|
-
- `operators`: the list of operators supported by the field.
|
|
204
|
-
- `isPrimary`: whether it is a primary filter. A primary filter is always visible and is not listed in the "Add filter" component, except for the list layout where it behaves like a secondary filter.
|
|
218
|
+
### `actions`: `Object[]`
|
|
205
219
|
|
|
206
|
-
|
|
220
|
+
Collection of operations that can be performed upon each record.
|
|
207
221
|
|
|
208
|
-
|
|
222
|
+
Each action is an object with the following properties:
|
|
209
223
|
|
|
210
224
|
- `id`: string, required. Unique identifier of the action. For example, `move-to-trash`.
|
|
211
225
|
- `label`: string, required. User facing description of the action. For example, `Move to Trash`.
|
|
@@ -217,28 +231,59 @@ Array of operations that can be performed upon each record. Each action is an ob
|
|
|
217
231
|
- `RenderModal`: ReactElement, optional. If an action requires that some UI be rendered in a modal, it can provide a component which takes as props the record as `item` and a `closeModal` function. When this prop is provided, the `callback` property is ignored.
|
|
218
232
|
- `hideModalHeader`: boolean, optional. This property is used in combination with `RenderModal` and controls the visibility of the modal's header. If the action renders a modal and doesn't hide the header, the action's label is going to be used in the modal's header.
|
|
219
233
|
|
|
234
|
+
### `paginationInfo`: `Object`
|
|
235
|
+
|
|
236
|
+
- `totalItems`: the total number of items in the datasets.
|
|
237
|
+
- `totalPages`: the total number of pages, taking into account the total items in the dataset and the number of items per page provided by the user.
|
|
238
|
+
|
|
239
|
+
### `search`: `boolean`
|
|
240
|
+
|
|
241
|
+
Whether the search input is enabled. `true` by default.
|
|
242
|
+
|
|
243
|
+
### `searchLabel`: `string`
|
|
244
|
+
|
|
245
|
+
What text to show in the search input. "Search" by default.
|
|
246
|
+
|
|
247
|
+
### `getItemId`: `function`
|
|
248
|
+
|
|
249
|
+
Function that receives an item and returns an unique identifier for it. By default, it uses the `id` of the item as unique identifier. If it's not, the consumer should provide their own.
|
|
250
|
+
|
|
251
|
+
### `isLoading`: `boolean`
|
|
252
|
+
|
|
253
|
+
Whether the data is loading. `false` by default.
|
|
254
|
+
|
|
255
|
+
### `supportedLayouts`: `String[]`
|
|
256
|
+
|
|
257
|
+
Array of layouts supported. By default, all are: `table`, `grid`, `list`.
|
|
258
|
+
|
|
259
|
+
### `deferredRendering`: `boolean`
|
|
260
|
+
|
|
261
|
+
Whether the items should be rendered asynchronously. Useful when there's a field that takes a lot of time (e.g.: previews). `false` by default.
|
|
262
|
+
|
|
263
|
+
### `onSelectionChange`: `function`
|
|
264
|
+
|
|
265
|
+
Callback that signals the user selected one of more items, and takes them as parameter. So far, only the `list` view implements it.
|
|
266
|
+
|
|
267
|
+
### `onDetailsChange`: `function`
|
|
268
|
+
|
|
269
|
+
Callback that signals the user triggered the details for one of more items, and takes them as paremeter. So far, only the `list` view implements it.
|
|
270
|
+
|
|
220
271
|
## Types
|
|
221
272
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
- `
|
|
235
|
-
- `
|
|
236
|
-
- `getItemId`: function that receives an item and returns an unique identifier for it. By default, it uses the `id` of the item as unique identifier. If it's not, the consumer should provide their own.
|
|
237
|
-
- `isLoading`: whether the data is loading. `false` by default.
|
|
238
|
-
- `supportedLayouts`: array of layouts supported. By default, all are: `table`, `grid`, `list`.
|
|
239
|
-
- `deferredRendering`: whether the items should be rendered asynchronously. Useful when there's a field that takes a lot of time (e.g.: previews). `false` by default.
|
|
240
|
-
- `onSelectionChange`: callback that signals the user selected one of more items, and takes them as parameter. So far, only the `list` view implements it.
|
|
241
|
-
- `onDetailsChange`: callback that signals the user triggered the details for one of more items, and takes them as paremeter. So far, only the `list` view implements it.
|
|
273
|
+
### Layouts
|
|
274
|
+
|
|
275
|
+
- `table`: the view uses a table layout.
|
|
276
|
+
- `grid`: the view uses a grid layout.
|
|
277
|
+
- `list`: the view uses a list layout.
|
|
278
|
+
|
|
279
|
+
### Fields
|
|
280
|
+
|
|
281
|
+
- `enumeration`: the field value should be taken and can be filtered from a closed list of elements.
|
|
282
|
+
|
|
283
|
+
### Operators
|
|
284
|
+
|
|
285
|
+
- `in`: operator to be used in filters for fields of type `enumeration`.
|
|
286
|
+
- `notIn`: operator to be used in filters for fields of type `enumeration`.
|
|
242
287
|
|
|
243
288
|
## Contributing to this package
|
|
244
289
|
|
package/build/view-grid.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.default = ViewGrid;
|
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
10
|
var _components = require("@wordpress/components");
|
|
11
|
+
var _i18n = require("@wordpress/i18n");
|
|
11
12
|
var _compose = require("@wordpress/compose");
|
|
12
13
|
var _element = require("@wordpress/element");
|
|
13
14
|
var _itemActions = _interopRequireDefault(require("./item-actions"));
|
|
@@ -116,6 +117,7 @@ function ViewGrid({
|
|
|
116
117
|
fields,
|
|
117
118
|
view,
|
|
118
119
|
actions,
|
|
120
|
+
isLoading,
|
|
119
121
|
getItemId,
|
|
120
122
|
deferredRendering,
|
|
121
123
|
selection,
|
|
@@ -128,11 +130,13 @@ function ViewGrid({
|
|
|
128
130
|
step: 3
|
|
129
131
|
});
|
|
130
132
|
const usedData = deferredRendering ? shownData : data;
|
|
131
|
-
|
|
133
|
+
const hasData = !!usedData?.length;
|
|
134
|
+
return (0, _react.createElement)(_react.Fragment, null, hasData && (0, _react.createElement)(_components.__experimentalGrid, {
|
|
132
135
|
gap: 6,
|
|
133
136
|
columns: 2,
|
|
134
137
|
alignment: "top",
|
|
135
|
-
className: "dataviews-view-grid"
|
|
138
|
+
className: "dataviews-view-grid",
|
|
139
|
+
"aria-busy": isLoading
|
|
136
140
|
}, usedData.map(item => {
|
|
137
141
|
return (0, _react.createElement)(GridItem, {
|
|
138
142
|
key: getItemId(item),
|
|
@@ -146,6 +150,11 @@ function ViewGrid({
|
|
|
146
150
|
primaryField: primaryField,
|
|
147
151
|
visibleFields: visibleFields
|
|
148
152
|
});
|
|
149
|
-
}))
|
|
153
|
+
})), !hasData && (0, _react.createElement)("div", {
|
|
154
|
+
className: (0, _classnames.default)({
|
|
155
|
+
'dataviews-loading': isLoading,
|
|
156
|
+
'dataviews-no-results': !isLoading
|
|
157
|
+
})
|
|
158
|
+
}, (0, _react.createElement)("p", null, isLoading ? (0, _i18n.__)('Loading…') : (0, _i18n.__)('No results'))));
|
|
150
159
|
}
|
|
151
160
|
//# sourceMappingURL=view-grid.js.map
|
package/build/view-grid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_classnames","_interopRequireDefault","require","_components","_compose","_element","_itemActions","_singleSelectionCheckbox","GridItem","selection","data","onSelectionChange","getItemId","item","actions","mediaField","primaryField","visibleFields","hasNoPointerEvents","setHasNoPointerEvents","useState","id","isSelected","includes","_react","createElement","__experimentalVStack","spacing","key","className","classnames","onMouseDown","event","ctrlKey","metaKey","filter","_item","itemId","onClick","render","__experimentalHStack","justify","default","isCompact","map","field","renderedValue","Tooltip","text","header","placement","ViewGrid","fields","view","deferredRendering","find","layout","hiddenFields","shownData","useAsyncList","step","usedData","__experimentalGrid","gap","columns","alignment"],"sources":["@wordpress/dataviews/src/view-grid.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalGrid as Grid,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tTooltip,\n} from '@wordpress/components';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ItemActions from './item-actions';\nimport SingleSelectionCheckbox from './single-selection-checkbox';\n\nfunction GridItem( {\n\tselection,\n\tdata,\n\tonSelectionChange,\n\tgetItemId,\n\titem,\n\tactions,\n\tmediaField,\n\tprimaryField,\n\tvisibleFields,\n} ) {\n\tconst [ hasNoPointerEvents, setHasNoPointerEvents ] = useState( false );\n\tconst id = getItemId( item );\n\tconst isSelected = selection.includes( id );\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 0 }\n\t\t\tkey={ id }\n\t\t\tclassName={ classnames( 'dataviews-view-grid__card', {\n\t\t\t\t'is-selected': isSelected,\n\t\t\t\t'has-no-pointer-events': hasNoPointerEvents,\n\t\t\t} ) }\n\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\tif ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\tsetHasNoPointerEvents( true );\n\t\t\t\t\tif ( ! isSelected ) {\n\t\t\t\t\t\tonSelectionChange(\n\t\t\t\t\t\t\tdata.filter( ( _item ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId?.( _item );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\titemId === id ||\n\t\t\t\t\t\t\t\t\tselection.includes( itemId )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tonSelectionChange(\n\t\t\t\t\t\t\tdata.filter( ( _item ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId?.( _item );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\titemId !== id &&\n\t\t\t\t\t\t\t\t\tselection.includes( itemId )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonClick={ () => {\n\t\t\t\tif ( hasNoPointerEvents ) {\n\t\t\t\t\tsetHasNoPointerEvents( false );\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"dataviews-view-grid__media\">\n\t\t\t\t{ mediaField?.render( { item } ) }\n\t\t\t</div>\n\t\t\t<HStack\n\t\t\t\tjustify=\"space-between\"\n\t\t\t\tclassName=\"dataviews-view-grid__title-actions\"\n\t\t\t>\n\t\t\t\t<SingleSelectionCheckbox\n\t\t\t\t\tid={ id }\n\t\t\t\t\titem={ item }\n\t\t\t\t\tselection={ selection }\n\t\t\t\t\tonSelectionChange={ onSelectionChange }\n\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tprimaryField={ primaryField }\n\t\t\t\t/>\n\t\t\t\t<HStack className=\"dataviews-view-grid__primary-field\">\n\t\t\t\t\t{ primaryField?.render( { item } ) }\n\t\t\t\t</HStack>\n\t\t\t\t<ItemActions item={ item } actions={ actions } isCompact />\n\t\t\t</HStack>\n\t\t\t<VStack className=\"dataviews-view-grid__fields\" spacing={ 3 }>\n\t\t\t\t{ visibleFields.map( ( field ) => {\n\t\t\t\t\tconst renderedValue = field.render( {\n\t\t\t\t\t\titem,\n\t\t\t\t\t} );\n\t\t\t\t\tif ( ! renderedValue ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<VStack\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field\"\n\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Tooltip text={ field.header } placement=\"left\">\n\t\t\t\t\t\t\t\t<div className=\"dataviews-view-grid__field-value\">\n\t\t\t\t\t\t\t\t\t{ renderedValue }\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</VStack>\n\t\t</VStack>\n\t);\n}\n\nexport default function ViewGrid( {\n\tdata,\n\tfields,\n\tview,\n\tactions,\n\tgetItemId,\n\tdeferredRendering,\n\tselection,\n\tonSelectionChange,\n} ) {\n\tconst mediaField = fields.find(\n\t\t( field ) => field.id === view.layout.mediaField\n\t);\n\tconst primaryField = fields.find(\n\t\t( field ) => field.id === view.layout.primaryField\n\t);\n\tconst visibleFields = fields.filter(\n\t\t( field ) =>\n\t\t\t! view.hiddenFields.includes( field.id ) &&\n\t\t\t! [ view.layout.mediaField, view.layout.primaryField ].includes(\n\t\t\t\tfield.id\n\t\t\t)\n\t);\n\tconst shownData = useAsyncList( data, { step: 3 } );\n\tconst usedData = deferredRendering ? shownData : data;\n\treturn (\n\t\t<Grid\n\t\t\tgap={ 6 }\n\t\t\tcolumns={ 2 }\n\t\t\talignment=\"top\"\n\t\t\tclassName=\"dataviews-view-grid\"\n\t\t>\n\t\t\t{ usedData.map( ( item ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<GridItem\n\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\tonSelectionChange={ onSelectionChange }\n\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\tprimaryField={ primaryField }\n\t\t\t\t\t\tvisibleFields={ visibleFields }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</Grid>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AAMA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAKA,IAAAI,YAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,wBAAA,GAAAN,sBAAA,CAAAC,OAAA;AArBA;AACA;AACA;;AAGA;AACA;AACA;;AAUA;AACA;AACA;;AAIA,SAASM,QAAQA,CAAE;EAClBC,SAAS;EACTC,IAAI;EACJC,iBAAiB;EACjBC,SAAS;EACTC,IAAI;EACJC,OAAO;EACPC,UAAU;EACVC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,kBAAkB,EAAEC,qBAAqB,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EACvE,MAAMC,EAAE,GAAGT,SAAS,CAAEC,IAAK,CAAC;EAC5B,MAAMS,UAAU,GAAGb,SAAS,CAACc,QA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,EAAGA,SAAW;MACvBC,IAAI,EAAGA,IAAM;MACbC,iBAAiB,EAAGA,iBAAmB;MACvCC,SAAS,EAAGA,SAAW;MACvBC,IAAI,EAAGA,IAAM;MACbC,OAAO,EAAGA,OAAS;MACnBC,UAAU,EAAGA,UAAY;MACzBC,YAAY,EAAGA,YAAc;MAC7BC,aAAa,EAAGA;IAAe,CAC/B,CAAC;EAEJ,CAAE,CACG,CAAC;AAET"}
|
|
1
|
+
{"version":3,"names":["_classnames","_interopRequireDefault","require","_components","_i18n","_compose","_element","_itemActions","_singleSelectionCheckbox","GridItem","selection","data","onSelectionChange","getItemId","item","actions","mediaField","primaryField","visibleFields","hasNoPointerEvents","setHasNoPointerEvents","useState","id","isSelected","includes","_react","createElement","__experimentalVStack","spacing","key","className","classnames","onMouseDown","event","ctrlKey","metaKey","filter","_item","itemId","onClick","render","__experimentalHStack","justify","default","isCompact","map","field","renderedValue","Tooltip","text","header","placement","ViewGrid","fields","view","isLoading","deferredRendering","find","layout","hiddenFields","shownData","useAsyncList","step","usedData","hasData","length","Fragment","__experimentalGrid","gap","columns","alignment","__"],"sources":["@wordpress/dataviews/src/view-grid.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalGrid as Grid,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tTooltip,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ItemActions from './item-actions';\nimport SingleSelectionCheckbox from './single-selection-checkbox';\n\nfunction GridItem( {\n\tselection,\n\tdata,\n\tonSelectionChange,\n\tgetItemId,\n\titem,\n\tactions,\n\tmediaField,\n\tprimaryField,\n\tvisibleFields,\n} ) {\n\tconst [ hasNoPointerEvents, setHasNoPointerEvents ] = useState( false );\n\tconst id = getItemId( item );\n\tconst isSelected = selection.includes( id );\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 0 }\n\t\t\tkey={ id }\n\t\t\tclassName={ classnames( 'dataviews-view-grid__card', {\n\t\t\t\t'is-selected': isSelected,\n\t\t\t\t'has-no-pointer-events': hasNoPointerEvents,\n\t\t\t} ) }\n\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\tif ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\tsetHasNoPointerEvents( true );\n\t\t\t\t\tif ( ! isSelected ) {\n\t\t\t\t\t\tonSelectionChange(\n\t\t\t\t\t\t\tdata.filter( ( _item ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId?.( _item );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\titemId === id ||\n\t\t\t\t\t\t\t\t\tselection.includes( itemId )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tonSelectionChange(\n\t\t\t\t\t\t\tdata.filter( ( _item ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId?.( _item );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\titemId !== id &&\n\t\t\t\t\t\t\t\t\tselection.includes( itemId )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonClick={ () => {\n\t\t\t\tif ( hasNoPointerEvents ) {\n\t\t\t\t\tsetHasNoPointerEvents( false );\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"dataviews-view-grid__media\">\n\t\t\t\t{ mediaField?.render( { item } ) }\n\t\t\t</div>\n\t\t\t<HStack\n\t\t\t\tjustify=\"space-between\"\n\t\t\t\tclassName=\"dataviews-view-grid__title-actions\"\n\t\t\t>\n\t\t\t\t<SingleSelectionCheckbox\n\t\t\t\t\tid={ id }\n\t\t\t\t\titem={ item }\n\t\t\t\t\tselection={ selection }\n\t\t\t\t\tonSelectionChange={ onSelectionChange }\n\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tprimaryField={ primaryField }\n\t\t\t\t/>\n\t\t\t\t<HStack className=\"dataviews-view-grid__primary-field\">\n\t\t\t\t\t{ primaryField?.render( { item } ) }\n\t\t\t\t</HStack>\n\t\t\t\t<ItemActions item={ item } actions={ actions } isCompact />\n\t\t\t</HStack>\n\t\t\t<VStack className=\"dataviews-view-grid__fields\" spacing={ 3 }>\n\t\t\t\t{ visibleFields.map( ( field ) => {\n\t\t\t\t\tconst renderedValue = field.render( {\n\t\t\t\t\t\titem,\n\t\t\t\t\t} );\n\t\t\t\t\tif ( ! renderedValue ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<VStack\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field\"\n\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Tooltip text={ field.header } placement=\"left\">\n\t\t\t\t\t\t\t\t<div className=\"dataviews-view-grid__field-value\">\n\t\t\t\t\t\t\t\t\t{ renderedValue }\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</VStack>\n\t\t</VStack>\n\t);\n}\n\nexport default function ViewGrid( {\n\tdata,\n\tfields,\n\tview,\n\tactions,\n\tisLoading,\n\tgetItemId,\n\tdeferredRendering,\n\tselection,\n\tonSelectionChange,\n} ) {\n\tconst mediaField = fields.find(\n\t\t( field ) => field.id === view.layout.mediaField\n\t);\n\tconst primaryField = fields.find(\n\t\t( field ) => field.id === view.layout.primaryField\n\t);\n\tconst visibleFields = fields.filter(\n\t\t( field ) =>\n\t\t\t! view.hiddenFields.includes( field.id ) &&\n\t\t\t! [ view.layout.mediaField, view.layout.primaryField ].includes(\n\t\t\t\tfield.id\n\t\t\t)\n\t);\n\tconst shownData = useAsyncList( data, { step: 3 } );\n\tconst usedData = deferredRendering ? shownData : data;\n\tconst hasData = !! usedData?.length;\n\treturn (\n\t\t<>\n\t\t\t{ hasData && (\n\t\t\t\t<Grid\n\t\t\t\t\tgap={ 6 }\n\t\t\t\t\tcolumns={ 2 }\n\t\t\t\t\talignment=\"top\"\n\t\t\t\t\tclassName=\"dataviews-view-grid\"\n\t\t\t\t\taria-busy={ isLoading }\n\t\t\t\t>\n\t\t\t\t\t{ usedData.map( ( item ) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<GridItem\n\t\t\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\tonSelectionChange={ onSelectionChange }\n\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\tprimaryField={ primaryField }\n\t\t\t\t\t\t\t\tvisibleFields={ visibleFields }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t</Grid>\n\t\t\t) }\n\t\t\t{ ! hasData && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t'dataviews-loading': isLoading,\n\t\t\t\t\t\t'dataviews-no-results': ! isLoading,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<p>{ isLoading ? __( 'Loading…' ) : __( 'No results' ) }</p>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,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K6B,SAAS,GAAG,IAAAgB,QAAE,EAAE,UAAW,CAAC,GAAG,IAAAA,QAAE,EAAE,YAAa,CAAM,CACvD,CAEL,CAAC;AAEL"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
2
|
/**
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
@@ -8,6 +8,7 @@ import classnames from 'classnames';
|
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { __experimentalGrid as Grid, __experimentalHStack as HStack, __experimentalVStack as VStack, Tooltip } from '@wordpress/components';
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
11
12
|
import { useAsyncList } from '@wordpress/compose';
|
|
12
13
|
import { useState } from '@wordpress/element';
|
|
13
14
|
|
|
@@ -108,6 +109,7 @@ export default function ViewGrid({
|
|
|
108
109
|
fields,
|
|
109
110
|
view,
|
|
110
111
|
actions,
|
|
112
|
+
isLoading,
|
|
111
113
|
getItemId,
|
|
112
114
|
deferredRendering,
|
|
113
115
|
selection,
|
|
@@ -120,11 +122,13 @@ export default function ViewGrid({
|
|
|
120
122
|
step: 3
|
|
121
123
|
});
|
|
122
124
|
const usedData = deferredRendering ? shownData : data;
|
|
123
|
-
|
|
125
|
+
const hasData = !!usedData?.length;
|
|
126
|
+
return createElement(Fragment, null, hasData && createElement(Grid, {
|
|
124
127
|
gap: 6,
|
|
125
128
|
columns: 2,
|
|
126
129
|
alignment: "top",
|
|
127
|
-
className: "dataviews-view-grid"
|
|
130
|
+
className: "dataviews-view-grid",
|
|
131
|
+
"aria-busy": isLoading
|
|
128
132
|
}, usedData.map(item => {
|
|
129
133
|
return createElement(GridItem, {
|
|
130
134
|
key: getItemId(item),
|
|
@@ -138,6 +142,11 @@ export default function ViewGrid({
|
|
|
138
142
|
primaryField: primaryField,
|
|
139
143
|
visibleFields: visibleFields
|
|
140
144
|
});
|
|
141
|
-
}))
|
|
145
|
+
})), !hasData && createElement("div", {
|
|
146
|
+
className: classnames({
|
|
147
|
+
'dataviews-loading': isLoading,
|
|
148
|
+
'dataviews-no-results': !isLoading
|
|
149
|
+
})
|
|
150
|
+
}, createElement("p", null, isLoading ? __('Loading…') : __('No results'))));
|
|
142
151
|
}
|
|
143
152
|
//# sourceMappingURL=view-grid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["classnames","__experimentalGrid","Grid","__experimentalHStack","HStack","__experimentalVStack","VStack","Tooltip","useAsyncList","useState","ItemActions","SingleSelectionCheckbox","GridItem","selection","data","onSelectionChange","getItemId","item","actions","mediaField","primaryField","visibleFields","hasNoPointerEvents","setHasNoPointerEvents","id","isSelected","includes","createElement","spacing","key","className","onMouseDown","event","ctrlKey","metaKey","filter","_item","itemId","onClick","render","justify","isCompact","map","field","renderedValue","text","header","placement","ViewGrid","fields","view","deferredRendering","find","layout","hiddenFields","shownData","step","usedData","gap","columns","alignment"],"sources":["@wordpress/dataviews/src/view-grid.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalGrid as Grid,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tTooltip,\n} from '@wordpress/components';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ItemActions from './item-actions';\nimport SingleSelectionCheckbox from './single-selection-checkbox';\n\nfunction GridItem( {\n\tselection,\n\tdata,\n\tonSelectionChange,\n\tgetItemId,\n\titem,\n\tactions,\n\tmediaField,\n\tprimaryField,\n\tvisibleFields,\n} ) {\n\tconst [ hasNoPointerEvents, setHasNoPointerEvents ] = useState( false );\n\tconst id = getItemId( item );\n\tconst isSelected = selection.includes( id );\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 0 }\n\t\t\tkey={ id }\n\t\t\tclassName={ classnames( 'dataviews-view-grid__card', {\n\t\t\t\t'is-selected': isSelected,\n\t\t\t\t'has-no-pointer-events': hasNoPointerEvents,\n\t\t\t} ) }\n\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\tif ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\tsetHasNoPointerEvents( true );\n\t\t\t\t\tif ( ! isSelected ) {\n\t\t\t\t\t\tonSelectionChange(\n\t\t\t\t\t\t\tdata.filter( ( _item ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId?.( _item );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\titemId === id ||\n\t\t\t\t\t\t\t\t\tselection.includes( itemId )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tonSelectionChange(\n\t\t\t\t\t\t\tdata.filter( ( _item ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId?.( _item );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\titemId !== id &&\n\t\t\t\t\t\t\t\t\tselection.includes( itemId )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonClick={ () => {\n\t\t\t\tif ( hasNoPointerEvents ) {\n\t\t\t\t\tsetHasNoPointerEvents( false );\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"dataviews-view-grid__media\">\n\t\t\t\t{ mediaField?.render( { item } ) }\n\t\t\t</div>\n\t\t\t<HStack\n\t\t\t\tjustify=\"space-between\"\n\t\t\t\tclassName=\"dataviews-view-grid__title-actions\"\n\t\t\t>\n\t\t\t\t<SingleSelectionCheckbox\n\t\t\t\t\tid={ id }\n\t\t\t\t\titem={ item }\n\t\t\t\t\tselection={ selection }\n\t\t\t\t\tonSelectionChange={ onSelectionChange }\n\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tprimaryField={ primaryField }\n\t\t\t\t/>\n\t\t\t\t<HStack className=\"dataviews-view-grid__primary-field\">\n\t\t\t\t\t{ primaryField?.render( { item } ) }\n\t\t\t\t</HStack>\n\t\t\t\t<ItemActions item={ item } actions={ actions } isCompact />\n\t\t\t</HStack>\n\t\t\t<VStack className=\"dataviews-view-grid__fields\" spacing={ 3 }>\n\t\t\t\t{ visibleFields.map( ( field ) => {\n\t\t\t\t\tconst renderedValue = field.render( {\n\t\t\t\t\t\titem,\n\t\t\t\t\t} );\n\t\t\t\t\tif ( ! renderedValue ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<VStack\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field\"\n\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Tooltip text={ field.header } placement=\"left\">\n\t\t\t\t\t\t\t\t<div className=\"dataviews-view-grid__field-value\">\n\t\t\t\t\t\t\t\t\t{ renderedValue }\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</VStack>\n\t\t</VStack>\n\t);\n}\n\nexport default function ViewGrid( {\n\tdata,\n\tfields,\n\tview,\n\tactions,\n\tgetItemId,\n\tdeferredRendering,\n\tselection,\n\tonSelectionChange,\n} ) {\n\tconst mediaField = fields.find(\n\t\t( field ) => field.id === view.layout.mediaField\n\t);\n\tconst primaryField = fields.find(\n\t\t( field ) => field.id === view.layout.primaryField\n\t);\n\tconst visibleFields = fields.filter(\n\t\t( field ) =>\n\t\t\t! view.hiddenFields.includes( field.id ) &&\n\t\t\t! [ view.layout.mediaField, view.layout.primaryField ].includes(\n\t\t\t\tfield.id\n\t\t\t)\n\t);\n\tconst shownData = useAsyncList( data, { step: 3 } );\n\tconst usedData = deferredRendering ? shownData : data;\n\treturn (\n\t\t<Grid\n\t\t\tgap={ 6 }\n\t\t\tcolumns={ 2 }\n\t\t\talignment=\"top\"\n\t\t\tclassName=\"dataviews-view-grid\"\n\t\t>\n\t\t\t{ usedData.map( ( item ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<GridItem\n\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\tonSelectionChange={ onSelectionChange }\n\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\tprimaryField={ primaryField }\n\t\t\t\t\t\tvisibleFields={ visibleFields }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</Grid>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SACCC,kBAAkB,IAAIC,IAAI,EAC1BC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,OAAO,QACD,uBAAuB;AAC9B,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,QAAQ,QAAQ,oBAAoB;;AAE7C;AACA;AACA;AACA,OAAOC,WAAW,MAAM,gBAAgB;AACxC,OAAOC,uBAAuB,MAAM,6BAA6B;AAEjE,SAASC,QAAQA,CAAE;EAClBC,SAAS;EACTC,IAAI;EACJC,iBAAiB;EACjBC,SAAS;EACTC,IAAI;EACJC,OAAO;EACPC,UAAU;EACVC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,kBAAkB,EAAEC,qBAAqB,CAAE,GAAGd,QAAQ,CAAE,KAAM,CAAC;EACvE,MAAMe,EAAE,GAAGR,SAAS,CAAEC,IAAK,CAAC;EAC5B,MAAMQ,UAAU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AAM,CAAClC,UACvC,CAAC;EACD,MAAMC,YAAY,GAAG6B,MAAM,CAACG,IAAI,CAC7BT,KAAK,IAAMA,KAAK,CAACnB,EAAE,KAAK0B,IAAI,CAACG,MAAM,CAACjC,YACvC,CAAC;EACD,MAAMC,aAAa,GAAG4B,MAAM,CAACd,MAAM,CAChCQ,KAAK,IACN,CAAEO,IAAI,CAACI,YAAY,CAAC5B,QAAQ,CAAEiB,KAAK,CAACnB,EAAG,CAAC,IACxC,CAAE,CAAE0B,IAAI,CAACG,MAAM,CAAClC,UAAU,EAAE+B,IAAI,CAACG,MAAM,CAACjC,YAAY,CAAE,CAACM,QAAQ,CAC9DiB,KAAK,CAACnB,EACP,CACF,CAAC;EACD,MAAM+B,SAAS,GAAG/C,YAAY,CAAEM,IAAI,EAAE;IAAE0C,IAAI,EAAE;EAAE,CAAE,CAAC;EACnD,MAAMC,QAAQ,GAAGN,iBAAiB,GAAGI,SAAS,GAAGzC,IAAI;EACrD,OACCa,aAAA,CAACzB,IAAI;IACJwD,GAAG,EAAG,CAAG;IACTC,OAAO,EAAG,CAAG;IACbC,SAAS,EAAC,KAAK;IACf9B,SAAS,EAAC;EAAqB,GAE7B2B,QAAQ,CAACf,GAAG,CAAIzB,IAAI,IAAM;IAC3B,OACCU,aAAA,CAACf,QAAQ;MACRiB,GAAG,EAAGb,SAAS,CAAEC,IAAK,CAAG;MACzBJ,SAAS,EAAGA,SAAW;MACvBC,IAAI,EAAGA,IAAM;MACbC,iBAAiB,EAAGA,iBAAmB;MACvCC,SAAS,EAAGA,SAAW;MACvBC,IAAI,EAAGA,IAAM;MACbC,OAAO,EAAGA,OAAS;MACnBC,UAAU,EAAGA,UAAY;MACzBC,YAAY,EAAGA,YAAc;MAC7BC,aAAa,EAAGA;IAAe,CAC/B,CAAC;EAEJ,CAAE,CACG,CAAC;AAET"}
|
|
1
|
+
{"version":3,"names":["classnames","__experimentalGrid","Grid","__experimentalHStack","HStack","__experimentalVStack","VStack","Tooltip","__","useAsyncList","useState","ItemActions","SingleSelectionCheckbox","GridItem","selection","data","onSelectionChange","getItemId","item","actions","mediaField","primaryField","visibleFields","hasNoPointerEvents","setHasNoPointerEvents","id","isSelected","includes","createElement","spacing","key","className","onMouseDown","event","ctrlKey","metaKey","filter","_item","itemId","onClick","render","justify","isCompact","map","field","renderedValue","text","header","placement","ViewGrid","fields","view","isLoading","deferredRendering","find","layout","hiddenFields","shownData","step","usedData","hasData","length","Fragment","gap","columns","alignment"],"sources":["@wordpress/dataviews/src/view-grid.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalGrid as Grid,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tTooltip,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ItemActions from './item-actions';\nimport SingleSelectionCheckbox from './single-selection-checkbox';\n\nfunction GridItem( {\n\tselection,\n\tdata,\n\tonSelectionChange,\n\tgetItemId,\n\titem,\n\tactions,\n\tmediaField,\n\tprimaryField,\n\tvisibleFields,\n} ) {\n\tconst [ hasNoPointerEvents, setHasNoPointerEvents ] = useState( false );\n\tconst id = getItemId( item );\n\tconst isSelected = selection.includes( id );\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 0 }\n\t\t\tkey={ id }\n\t\t\tclassName={ classnames( 'dataviews-view-grid__card', {\n\t\t\t\t'is-selected': isSelected,\n\t\t\t\t'has-no-pointer-events': hasNoPointerEvents,\n\t\t\t} ) }\n\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\tif ( event.ctrlKey || event.metaKey ) {\n\t\t\t\t\tsetHasNoPointerEvents( true );\n\t\t\t\t\tif ( ! isSelected ) {\n\t\t\t\t\t\tonSelectionChange(\n\t\t\t\t\t\t\tdata.filter( ( _item ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId?.( _item );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\titemId === id ||\n\t\t\t\t\t\t\t\t\tselection.includes( itemId )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tonSelectionChange(\n\t\t\t\t\t\t\tdata.filter( ( _item ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId?.( _item );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\titemId !== id &&\n\t\t\t\t\t\t\t\t\tselection.includes( itemId )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonClick={ () => {\n\t\t\t\tif ( hasNoPointerEvents ) {\n\t\t\t\t\tsetHasNoPointerEvents( false );\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"dataviews-view-grid__media\">\n\t\t\t\t{ mediaField?.render( { item } ) }\n\t\t\t</div>\n\t\t\t<HStack\n\t\t\t\tjustify=\"space-between\"\n\t\t\t\tclassName=\"dataviews-view-grid__title-actions\"\n\t\t\t>\n\t\t\t\t<SingleSelectionCheckbox\n\t\t\t\t\tid={ id }\n\t\t\t\t\titem={ item }\n\t\t\t\t\tselection={ selection }\n\t\t\t\t\tonSelectionChange={ onSelectionChange }\n\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tprimaryField={ primaryField }\n\t\t\t\t/>\n\t\t\t\t<HStack className=\"dataviews-view-grid__primary-field\">\n\t\t\t\t\t{ primaryField?.render( { item } ) }\n\t\t\t\t</HStack>\n\t\t\t\t<ItemActions item={ item } actions={ actions } isCompact />\n\t\t\t</HStack>\n\t\t\t<VStack className=\"dataviews-view-grid__fields\" spacing={ 3 }>\n\t\t\t\t{ visibleFields.map( ( field ) => {\n\t\t\t\t\tconst renderedValue = field.render( {\n\t\t\t\t\t\titem,\n\t\t\t\t\t} );\n\t\t\t\t\tif ( ! renderedValue ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<VStack\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field\"\n\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Tooltip text={ field.header } placement=\"left\">\n\t\t\t\t\t\t\t\t<div className=\"dataviews-view-grid__field-value\">\n\t\t\t\t\t\t\t\t\t{ renderedValue }\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</VStack>\n\t\t</VStack>\n\t);\n}\n\nexport default function ViewGrid( {\n\tdata,\n\tfields,\n\tview,\n\tactions,\n\tisLoading,\n\tgetItemId,\n\tdeferredRendering,\n\tselection,\n\tonSelectionChange,\n} ) {\n\tconst mediaField = fields.find(\n\t\t( field ) => field.id === view.layout.mediaField\n\t);\n\tconst primaryField = fields.find(\n\t\t( field ) => field.id === view.layout.primaryField\n\t);\n\tconst visibleFields = fields.filter(\n\t\t( field ) =>\n\t\t\t! view.hiddenFields.includes( field.id ) &&\n\t\t\t! [ view.layout.mediaField, view.layout.primaryField ].includes(\n\t\t\t\tfield.id\n\t\t\t)\n\t);\n\tconst shownData = useAsyncList( data, { step: 3 } );\n\tconst usedData = deferredRendering ? shownData : data;\n\tconst hasData = !! usedData?.length;\n\treturn (\n\t\t<>\n\t\t\t{ hasData && (\n\t\t\t\t<Grid\n\t\t\t\t\tgap={ 6 }\n\t\t\t\t\tcolumns={ 2 }\n\t\t\t\t\talignment=\"top\"\n\t\t\t\t\tclassName=\"dataviews-view-grid\"\n\t\t\t\t\taria-busy={ isLoading }\n\t\t\t\t>\n\t\t\t\t\t{ usedData.map( ( item ) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<GridItem\n\t\t\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\tonSelectionChange={ onSelectionChange }\n\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\tprimaryField={ primaryField }\n\t\t\t\t\t\t\t\tvisibleFields={ visibleFields }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t</Grid>\n\t\t\t) }\n\t\t\t{ ! hasData && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t'dataviews-loading': isLoading,\n\t\t\t\t\t\t'dataviews-no-results': ! isLoading,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<p>{ isLoading ? __( 'Loading…' ) : __( 'No results' ) }</p>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SACCC,kBAAkB,IAAIC,IAAI,EAC1BC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,OAAO,QACD,uBAAuB;AAC9B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,QAAQ,QAAQ,oBAAoB;;AAE7C;AACA;AACA;AACA,OAAOC,WAAW,MAAM,gBAAgB;AACxC,OAAOC,uBAAuB,MAAM,6BAA6B;AAEjE,SAASC,QAAQA,CAAE;EAClBC,SAAS;EACTC,IAAI;EACJC,iBAAiB;EACjBC,SAAS;EACTC,I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AAW;MACvBC,IAAI,EAAGA,IAAM;MACbC,iBAAiB,EAAGA,iBAAmB;MACvCC,SAAS,EAAGA,SAAW;MACvBC,IAAI,EAAGA,IAAM;MACbC,OAAO,EAAGA,OAAS;MACnBC,UAAU,EAAGA,UAAY;MACzBC,YAAY,EAAGA,YAAc;MAC7BC,aAAa,EAAGA;IAAe,CAC/B,CAAC;EAEJ,CAAE,CACG,CACN,EACC,CAAEsC,OAAO,IACVhC,aAAA;IACCG,SAAS,EAAG/B,UAAU,CAAE;MACvB,mBAAmB,EAAEoD,SAAS;MAC9B,sBAAsB,EAAE,CAAEA;IAC3B,CAAE;EAAG,GAELxB,aAAA,YAAKwB,SAAS,GAAG5C,EAAE,CAAE,UAAW,CAAC,GAAGA,EAAE,CAAE,YAAa,CAAM,CACvD,CAEL,CAAC;AAEL"}
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
}
|
|
172
172
|
.dataviews-view-table th {
|
|
173
173
|
text-align: right;
|
|
174
|
-
color:
|
|
174
|
+
color: #1e1e1e;
|
|
175
175
|
font-weight: normal;
|
|
176
176
|
font-size: 13px;
|
|
177
177
|
}
|
|
@@ -569,7 +569,7 @@
|
|
|
569
569
|
margin-block-end: 0;
|
|
570
570
|
}
|
|
571
571
|
.dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item:hover, .dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item[data-active-item], .dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item:focus {
|
|
572
|
-
background-color: var(--wp-
|
|
572
|
+
background-color: var(--wp-admin-theme-color);
|
|
573
573
|
color: #fff;
|
|
574
574
|
}
|
|
575
575
|
.dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item:hover .dataviews-search-widget-filter-combobox-item-check, .dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item[data-active-item] .dataviews-search-widget-filter-combobox-item-check, .dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item:focus .dataviews-search-widget-filter-combobox-item-check {
|
|
@@ -656,7 +656,7 @@
|
|
|
656
656
|
}
|
|
657
657
|
.dataviews-search-widget-filter-combobox__wrapper .dataviews-search-widget-filter-combobox__input:focus {
|
|
658
658
|
background: #fff;
|
|
659
|
-
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-
|
|
659
|
+
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
|
|
660
660
|
}
|
|
661
661
|
.dataviews-search-widget-filter-combobox__wrapper .dataviews-search-widget-filter-combobox__input::placeholder {
|
|
662
662
|
color: #757575;
|
package/build-style/style.css
CHANGED
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
}
|
|
172
172
|
.dataviews-view-table th {
|
|
173
173
|
text-align: left;
|
|
174
|
-
color:
|
|
174
|
+
color: #1e1e1e;
|
|
175
175
|
font-weight: normal;
|
|
176
176
|
font-size: 13px;
|
|
177
177
|
}
|
|
@@ -569,7 +569,7 @@
|
|
|
569
569
|
margin-block-end: 0;
|
|
570
570
|
}
|
|
571
571
|
.dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item:hover, .dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item[data-active-item], .dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item:focus {
|
|
572
|
-
background-color: var(--wp-
|
|
572
|
+
background-color: var(--wp-admin-theme-color);
|
|
573
573
|
color: #fff;
|
|
574
574
|
}
|
|
575
575
|
.dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item:hover .dataviews-search-widget-filter-combobox-item-check, .dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item[data-active-item] .dataviews-search-widget-filter-combobox-item-check, .dataviews-search-widget-filter-combobox-list .dataviews-search-widget-filter-combobox-item:focus .dataviews-search-widget-filter-combobox-item-check {
|
|
@@ -656,7 +656,7 @@
|
|
|
656
656
|
}
|
|
657
657
|
.dataviews-search-widget-filter-combobox__wrapper .dataviews-search-widget-filter-combobox__input:focus {
|
|
658
658
|
background: #fff;
|
|
659
|
-
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-
|
|
659
|
+
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
|
|
660
660
|
}
|
|
661
661
|
.dataviews-search-widget-filter-combobox__wrapper .dataviews-search-widget-filter-combobox__input::placeholder {
|
|
662
662
|
color: #757575;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/dataviews",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "DataViews is a component that provides an API to render datasets using different types of layouts (table, grid, list, etc.).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@ariakit/react": "^0.3.12",
|
|
31
31
|
"@babel/runtime": "^7.16.0",
|
|
32
|
-
"@wordpress/a11y": "^3.
|
|
33
|
-
"@wordpress/components": "^
|
|
34
|
-
"@wordpress/compose": "^6.
|
|
35
|
-
"@wordpress/element": "^5.
|
|
36
|
-
"@wordpress/i18n": "^4.
|
|
37
|
-
"@wordpress/icons": "^9.
|
|
38
|
-
"@wordpress/keycodes": "^3.
|
|
39
|
-
"@wordpress/primitives": "^3.
|
|
40
|
-
"@wordpress/private-apis": "^0.
|
|
32
|
+
"@wordpress/a11y": "^3.52.0",
|
|
33
|
+
"@wordpress/components": "^27.0.0",
|
|
34
|
+
"@wordpress/compose": "^6.29.0",
|
|
35
|
+
"@wordpress/element": "^5.29.0",
|
|
36
|
+
"@wordpress/i18n": "^4.52.0",
|
|
37
|
+
"@wordpress/icons": "^9.43.0",
|
|
38
|
+
"@wordpress/keycodes": "^3.52.0",
|
|
39
|
+
"@wordpress/primitives": "^3.50.0",
|
|
40
|
+
"@wordpress/private-apis": "^0.34.0",
|
|
41
41
|
"classnames": "^2.3.1",
|
|
42
42
|
"remove-accents": "^0.5.0"
|
|
43
43
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "c139588f4c668b38bafbc5431f2f4e3903dbe683"
|
|
51
51
|
}
|
|
@@ -6,9 +6,9 @@ import { useState, useMemo, useCallback } from '@wordpress/element';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { DataViews
|
|
10
|
-
|
|
9
|
+
import { DataViews } from '../index';
|
|
11
10
|
import { DEFAULT_VIEW, actions, data } from './fixtures';
|
|
11
|
+
import { LAYOUT_GRID, LAYOUT_TABLE } from '../constants';
|
|
12
12
|
|
|
13
13
|
const meta = {
|
|
14
14
|
title: 'DataViews (Experimental)/DataViews',
|
|
@@ -17,7 +17,9 @@ const meta = {
|
|
|
17
17
|
export default meta;
|
|
18
18
|
|
|
19
19
|
const defaultConfigPerViewType = {
|
|
20
|
-
[ LAYOUT_TABLE ]: {
|
|
20
|
+
[ LAYOUT_TABLE ]: {
|
|
21
|
+
primaryField: 'title',
|
|
22
|
+
},
|
|
21
23
|
[ LAYOUT_GRID ]: {
|
|
22
24
|
mediaField: 'image',
|
|
23
25
|
primaryField: 'title',
|
|
@@ -100,23 +102,19 @@ export const Default = ( props ) => {
|
|
|
100
102
|
};
|
|
101
103
|
}, [ view ] );
|
|
102
104
|
const onChangeView = useCallback(
|
|
103
|
-
(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
: viewUpdater;
|
|
108
|
-
if ( updatedView.type !== view.type ) {
|
|
109
|
-
updatedView = {
|
|
110
|
-
...updatedView,
|
|
105
|
+
( newView ) => {
|
|
106
|
+
if ( newView.type !== view.type ) {
|
|
107
|
+
newView = {
|
|
108
|
+
...newView,
|
|
111
109
|
layout: {
|
|
112
|
-
...defaultConfigPerViewType[
|
|
110
|
+
...defaultConfigPerViewType[ newView.type ],
|
|
113
111
|
},
|
|
114
112
|
};
|
|
115
113
|
}
|
|
116
114
|
|
|
117
|
-
setView(
|
|
115
|
+
setView( newView );
|
|
118
116
|
},
|
|
119
|
-
[ view, setView ]
|
|
117
|
+
[ view.type, setView ]
|
|
120
118
|
);
|
|
121
119
|
return (
|
|
122
120
|
<DataViews
|
|
@@ -131,7 +129,5 @@ export const Default = ( props ) => {
|
|
|
131
129
|
};
|
|
132
130
|
Default.args = {
|
|
133
131
|
actions,
|
|
134
|
-
getItemId: ( item ) => item.id,
|
|
135
|
-
isLoading: false,
|
|
136
132
|
supportedLayouts: [ LAYOUT_TABLE, LAYOUT_GRID ],
|
|
137
133
|
};
|
package/src/style.scss
CHANGED
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
}
|
|
68
68
|
th {
|
|
69
69
|
text-align: left;
|
|
70
|
-
color:
|
|
70
|
+
color: $gray-900;
|
|
71
71
|
font-weight: normal;
|
|
72
72
|
font-size: $default-font-size;
|
|
73
73
|
}
|
|
@@ -527,7 +527,7 @@
|
|
|
527
527
|
&:hover,
|
|
528
528
|
&[data-active-item],
|
|
529
529
|
&:focus {
|
|
530
|
-
background-color: var(--wp-
|
|
530
|
+
background-color: var(--wp-admin-theme-color);
|
|
531
531
|
color: $white;
|
|
532
532
|
|
|
533
533
|
.dataviews-search-widget-filter-combobox-item-check {
|
|
@@ -587,7 +587,7 @@
|
|
|
587
587
|
|
|
588
588
|
&:focus {
|
|
589
589
|
background: $white;
|
|
590
|
-
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-
|
|
590
|
+
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
|
|
591
591
|
}
|
|
592
592
|
|
|
593
593
|
&::placeholder {
|
package/src/view-grid.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
__experimentalVStack as VStack,
|
|
13
13
|
Tooltip,
|
|
14
14
|
} from '@wordpress/components';
|
|
15
|
+
import { __ } from '@wordpress/i18n';
|
|
15
16
|
import { useAsyncList } from '@wordpress/compose';
|
|
16
17
|
import { useState } from '@wordpress/element';
|
|
17
18
|
|
|
@@ -128,6 +129,7 @@ export default function ViewGrid( {
|
|
|
128
129
|
fields,
|
|
129
130
|
view,
|
|
130
131
|
actions,
|
|
132
|
+
isLoading,
|
|
131
133
|
getItemId,
|
|
132
134
|
deferredRendering,
|
|
133
135
|
selection,
|
|
@@ -148,29 +150,45 @@ export default function ViewGrid( {
|
|
|
148
150
|
);
|
|
149
151
|
const shownData = useAsyncList( data, { step: 3 } );
|
|
150
152
|
const usedData = deferredRendering ? shownData : data;
|
|
153
|
+
const hasData = !! usedData?.length;
|
|
151
154
|
return (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
155
|
+
<>
|
|
156
|
+
{ hasData && (
|
|
157
|
+
<Grid
|
|
158
|
+
gap={ 6 }
|
|
159
|
+
columns={ 2 }
|
|
160
|
+
alignment="top"
|
|
161
|
+
className="dataviews-view-grid"
|
|
162
|
+
aria-busy={ isLoading }
|
|
163
|
+
>
|
|
164
|
+
{ usedData.map( ( item ) => {
|
|
165
|
+
return (
|
|
166
|
+
<GridItem
|
|
167
|
+
key={ getItemId( item ) }
|
|
168
|
+
selection={ selection }
|
|
169
|
+
data={ data }
|
|
170
|
+
onSelectionChange={ onSelectionChange }
|
|
171
|
+
getItemId={ getItemId }
|
|
172
|
+
item={ item }
|
|
173
|
+
actions={ actions }
|
|
174
|
+
mediaField={ mediaField }
|
|
175
|
+
primaryField={ primaryField }
|
|
176
|
+
visibleFields={ visibleFields }
|
|
177
|
+
/>
|
|
178
|
+
);
|
|
179
|
+
} ) }
|
|
180
|
+
</Grid>
|
|
181
|
+
) }
|
|
182
|
+
{ ! hasData && (
|
|
183
|
+
<div
|
|
184
|
+
className={ classnames( {
|
|
185
|
+
'dataviews-loading': isLoading,
|
|
186
|
+
'dataviews-no-results': ! isLoading,
|
|
187
|
+
} ) }
|
|
188
|
+
>
|
|
189
|
+
<p>{ isLoading ? __( 'Loading…' ) : __( 'No results' ) }</p>
|
|
190
|
+
</div>
|
|
191
|
+
) }
|
|
192
|
+
</>
|
|
175
193
|
);
|
|
176
194
|
}
|