@wordpress/dataviews 4.9.1-next.cd6172eb0.0 → 4.11.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 +28 -1
- package/LICENSE.md +1 -1
- package/README.md +337 -228
- package/build/components/dataviews/index.js +13 -1
- package/build/components/dataviews/index.js.map +1 -1
- package/build/components/dataviews-bulk-actions/index.js +30 -2
- package/build/components/dataviews-bulk-actions/index.js.map +1 -1
- package/build/components/dataviews-context/index.js +2 -1
- package/build/components/dataviews-context/index.js.map +1 -1
- package/build/components/dataviews-filters/add-filter.js +36 -30
- package/build/components/dataviews-filters/add-filter.js.map +1 -1
- package/build/components/dataviews-filters/filter-summary.js +1 -0
- package/build/components/dataviews-filters/filter-summary.js.map +1 -1
- package/build/components/dataviews-filters/index.js +4 -1
- package/build/components/dataviews-filters/index.js.map +1 -1
- package/build/components/dataviews-filters/reset-filters.js +1 -0
- package/build/components/dataviews-filters/reset-filters.js.map +1 -1
- package/build/components/dataviews-filters/search-widget.js +1 -0
- package/build/components/dataviews-filters/search-widget.js.map +1 -1
- package/build/components/dataviews-item-actions/index.js +68 -79
- package/build/components/dataviews-item-actions/index.js.map +1 -1
- package/build/components/dataviews-layout/index.js +3 -0
- package/build/components/dataviews-layout/index.js.map +1 -1
- package/build/components/dataviews-pagination/index.js +1 -0
- package/build/components/dataviews-pagination/index.js.map +1 -1
- package/build/components/dataviews-selection-checkbox/index.js +4 -3
- package/build/components/dataviews-selection-checkbox/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +235 -161
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/dataforms-layouts/data-form-layout.js +1 -0
- package/build/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build/dataforms-layouts/index.js +1 -0
- package/build/dataforms-layouts/index.js.map +1 -1
- package/build/dataforms-layouts/panel/index.js +1 -0
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/regular/index.js +1 -0
- package/build/dataforms-layouts/regular/index.js.map +1 -1
- package/build/dataviews-layouts/grid/index.js +108 -65
- package/build/dataviews-layouts/grid/index.js.map +1 -1
- package/build/dataviews-layouts/grid/preview-size-picker.js +22 -25
- package/build/dataviews-layouts/grid/preview-size-picker.js.map +1 -1
- package/build/dataviews-layouts/index.js +0 -60
- package/build/dataviews-layouts/index.js.map +1 -1
- package/build/dataviews-layouts/list/index.js +67 -33
- package/build/dataviews-layouts/list/index.js.map +1 -1
- package/build/dataviews-layouts/table/column-header-menu.js +119 -120
- package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build/dataviews-layouts/table/column-primary.js +59 -0
- package/build/dataviews-layouts/table/column-primary.js.map +1 -0
- package/build/dataviews-layouts/table/index.js +78 -88
- package/build/dataviews-layouts/table/index.js.map +1 -1
- package/build/dataviews-layouts/utils/get-clickable-item-props.js +2 -2
- package/build/dataviews-layouts/utils/get-clickable-item-props.js.map +1 -1
- package/build/filter-and-sort-data-view.js +1 -0
- package/build/filter-and-sort-data-view.js.map +1 -1
- package/build/normalize-fields.js +1 -0
- package/build/normalize-fields.js.map +1 -1
- package/build/normalize-form-fields.js +1 -0
- package/build/normalize-form-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils.js +1 -0
- package/build/utils.js.map +1 -1
- package/build/validation.js +1 -0
- package/build/validation.js.map +1 -1
- package/build-module/components/dataviews/index.js +13 -1
- package/build-module/components/dataviews/index.js.map +1 -1
- package/build-module/components/dataviews-bulk-actions/index.js +31 -3
- package/build-module/components/dataviews-bulk-actions/index.js.map +1 -1
- package/build-module/components/dataviews-context/index.js +2 -1
- package/build-module/components/dataviews-context/index.js.map +1 -1
- package/build-module/components/dataviews-filters/add-filter.js +37 -31
- package/build-module/components/dataviews-filters/add-filter.js.map +1 -1
- package/build-module/components/dataviews-filters/filter-summary.js +1 -0
- package/build-module/components/dataviews-filters/filter-summary.js.map +1 -1
- package/build-module/components/dataviews-filters/index.js +4 -1
- package/build-module/components/dataviews-filters/index.js.map +1 -1
- package/build-module/components/dataviews-filters/reset-filters.js +1 -0
- package/build-module/components/dataviews-filters/reset-filters.js.map +1 -1
- package/build-module/components/dataviews-filters/search-widget.js +1 -0
- package/build-module/components/dataviews-filters/search-widget.js.map +1 -1
- package/build-module/components/dataviews-item-actions/index.js +69 -79
- package/build-module/components/dataviews-item-actions/index.js.map +1 -1
- package/build-module/components/dataviews-layout/index.js +3 -0
- package/build-module/components/dataviews-layout/index.js.map +1 -1
- package/build-module/components/dataviews-pagination/index.js +1 -0
- package/build-module/components/dataviews-pagination/index.js.map +1 -1
- package/build-module/components/dataviews-selection-checkbox/index.js +4 -3
- package/build-module/components/dataviews-selection-checkbox/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +240 -166
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/dataforms-layouts/data-form-layout.js +1 -0
- package/build-module/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build-module/dataforms-layouts/index.js +1 -0
- package/build-module/dataforms-layouts/index.js.map +1 -1
- package/build-module/dataforms-layouts/panel/index.js +1 -0
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/regular/index.js +1 -0
- package/build-module/dataforms-layouts/regular/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/index.js +111 -68
- package/build-module/dataviews-layouts/grid/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/preview-size-picker.js +22 -25
- package/build-module/dataviews-layouts/grid/preview-size-picker.js.map +1 -1
- package/build-module/dataviews-layouts/index.js +0 -57
- package/build-module/dataviews-layouts/index.js.map +1 -1
- package/build-module/dataviews-layouts/list/index.js +67 -33
- package/build-module/dataviews-layouts/list/index.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-header-menu.js +119 -120
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-primary.js +52 -0
- package/build-module/dataviews-layouts/table/column-primary.js.map +1 -0
- package/build-module/dataviews-layouts/table/index.js +81 -91
- package/build-module/dataviews-layouts/table/index.js.map +1 -1
- package/build-module/dataviews-layouts/utils/get-clickable-item-props.js +2 -2
- package/build-module/dataviews-layouts/utils/get-clickable-item-props.js.map +1 -1
- package/build-module/filter-and-sort-data-view.js +1 -0
- package/build-module/filter-and-sort-data-view.js.map +1 -1
- package/build-module/normalize-fields.js +1 -0
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/normalize-form-fields.js +1 -0
- package/build-module/normalize-form-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/utils.js +1 -0
- package/build-module/utils.js.map +1 -1
- package/build-module/validation.js +1 -0
- package/build-module/validation.js.map +1 -1
- package/build-style/style-rtl.css +123 -121
- package/build-style/style.css +123 -121
- package/build-types/components/dataviews/index.d.ts +2 -1
- package/build-types/components/dataviews/index.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/index.story.d.ts +0 -1
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-context/index.d.ts +2 -0
- package/build-types/components/dataviews-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/add-filter.d.ts +3 -2
- package/build-types/components/dataviews-filters/add-filter.d.ts.map +1 -1
- package/build-types/components/dataviews-item-actions/index.d.ts +7 -9
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layout/index.d.ts.map +1 -1
- package/build-types/components/dataviews-selection-checkbox/index.d.ts +2 -2
- package/build-types/components/dataviews-selection-checkbox/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/preview-size-picker.d.ts.map +1 -1
- package/build-types/dataviews-layouts/index.d.ts +0 -4
- package/build-types/dataviews-layouts/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts +1 -0
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-primary.d.ts +15 -0
- package/build-types/dataviews-layouts/table/column-primary.d.ts.map +1 -0
- package/build-types/dataviews-layouts/table/index.d.ts +1 -1
- package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/utils/get-clickable-item-props.d.ts +3 -3
- package/build-types/dataviews-layouts/utils/get-clickable-item-props.d.ts.map +1 -1
- package/build-types/test/dataform.d.ts +2 -0
- package/build-types/test/dataform.d.ts.map +1 -0
- package/build-types/test/dataviews.d.ts +2 -0
- package/build-types/test/dataviews.d.ts.map +1 -0
- package/build-types/test/normalize-fields.d.ts +2 -0
- package/build-types/test/normalize-fields.d.ts.map +1 -0
- package/build-types/test/validation.d.ts +2 -0
- package/build-types/test/validation.d.ts.map +1 -0
- package/build-types/types.d.ts +25 -39
- package/build-types/types.d.ts.map +1 -1
- package/build-wp/index.js +1892 -1814
- package/build.js +1 -1
- package/package.json +13 -12
- package/src/components/dataviews/index.tsx +15 -1
- package/src/components/dataviews/stories/fixtures.tsx +0 -3
- package/src/components/dataviews/stories/index.story.tsx +14 -106
- package/src/components/dataviews/style.scss +32 -33
- package/src/components/dataviews-bulk-actions/index.tsx +43 -3
- package/src/components/dataviews-context/index.ts +3 -0
- package/src/components/dataviews-filters/add-filter.tsx +43 -39
- package/src/components/dataviews-filters/index.tsx +1 -1
- package/src/components/dataviews-footer/style.scss +0 -3
- package/src/components/dataviews-item-actions/index.tsx +90 -107
- package/src/components/dataviews-layout/index.tsx +2 -0
- package/src/components/dataviews-selection-checkbox/index.tsx +4 -4
- package/src/components/dataviews-view-config/index.tsx +347 -232
- package/src/components/dataviews-view-config/style.scss +17 -1
- package/src/dataviews-layouts/grid/index.tsx +150 -103
- package/src/dataviews-layouts/grid/preview-size-picker.tsx +25 -30
- package/src/dataviews-layouts/grid/style.scss +38 -56
- package/src/dataviews-layouts/index.ts +0 -88
- package/src/dataviews-layouts/list/index.tsx +95 -57
- package/src/dataviews-layouts/list/style.scss +10 -9
- package/src/dataviews-layouts/table/column-header-menu.tsx +183 -171
- package/src/dataviews-layouts/table/column-primary.tsx +65 -0
- package/src/dataviews-layouts/table/index.tsx +98 -133
- package/src/dataviews-layouts/table/style.scss +4 -1
- package/src/dataviews-layouts/utils/get-clickable-item-props.ts +9 -3
- package/src/test/dataform.tsx +348 -0
- package/src/test/dataviews.tsx +380 -0
- package/src/types.ts +27 -46
- package/tsconfig.json +14 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/form-field-visibility/index.js +0 -32
- package/build/components/form-field-visibility/index.js.map +0 -1
- package/build-module/components/form-field-visibility/index.js +0 -26
- package/build-module/components/form-field-visibility/index.js.map +0 -1
- package/build-types/components/form-field-visibility/index.d.ts +0 -11
- package/build-types/components/form-field-visibility/index.d.ts.map +0 -1
- package/src/components/form-field-visibility/index.tsx +0 -32
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# The `@wordpress/dataviews` package
|
|
2
2
|
|
|
3
|
-
The DataViews package offers two React components and a few
|
|
3
|
+
The DataViews package offers two React components and a few utilities to work with a list of data:
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
5
|
+
- `DataViews`: to render the dataset using different types of layouts (table, grid, list) and interaction capabilities (search, filters, sorting, etc.).
|
|
6
|
+
- `DataForm`: to edit the items of the dataset.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ npm install @wordpress/dataviews --save
|
|
|
15
15
|
|
|
16
16
|
## `DataViews`
|
|
17
17
|
|
|
18
|
-
<div class="callout callout-info">At <a href="https://wordpress.github.io/gutenberg/">WordPress Gutenberg's Storybook</a> there's
|
|
18
|
+
<div class="callout callout-info">At <a href="https://wordpress.github.io/gutenberg/">WordPress Gutenberg's Storybook</a> there's an <a href="https://wordpress.github.io/gutenberg/?path=/docs/dataviews-dataviews--docs">example implementation of the Dataviews component</a>.</div>
|
|
19
19
|
|
|
20
20
|
**Important note** If you're trying to use the `DataViews` component in a WordPress plugin or theme and you're building your scripts using the `@wordpress/scripts` package, you need to import the components from `@wordpress/dataviews/wp` instead of `@wordpress/dataviews`.
|
|
21
21
|
|
|
@@ -23,13 +23,15 @@ npm install @wordpress/dataviews --save
|
|
|
23
23
|
|
|
24
24
|
The `DataViews` component receives data and some other configuration to render the dataset. It'll call the `onChangeView` callback every time the user has interacted with the dataset in some way (sorted, filtered, changed layout, etc.):
|
|
25
25
|
|
|
26
|
-

|
|
27
27
|
|
|
28
28
|
Example:
|
|
29
29
|
|
|
30
30
|
```jsx
|
|
31
31
|
const Example = () => {
|
|
32
|
-
const onChangeView = () => {
|
|
32
|
+
const onChangeView = () => {
|
|
33
|
+
/* React to user changes. */
|
|
34
|
+
};
|
|
33
35
|
|
|
34
36
|
return (
|
|
35
37
|
<DataViews
|
|
@@ -45,7 +47,6 @@ const Example = () => {
|
|
|
45
47
|
};
|
|
46
48
|
```
|
|
47
49
|
|
|
48
|
-
|
|
49
50
|
### Properties
|
|
50
51
|
|
|
51
52
|
#### `data`: `Object[]`
|
|
@@ -68,13 +69,13 @@ const data = [
|
|
|
68
69
|
];
|
|
69
70
|
```
|
|
70
71
|
|
|
71
|
-
The data can come from anywhere, from a static JSON file to a dynamic source like
|
|
72
|
+
The data can come from anywhere, from a static JSON file to a dynamic source like an HTTP Request. It's the consumer's responsibility to query the data source appropriately and update the dataset based on the user's choices for sorting, filtering, etc.
|
|
72
73
|
|
|
73
74
|
Each record should have an `id` that identifies them uniquely. If they don't, the consumer should provide the `getItemId` property to `DataViews`: a function that returns an unique identifier for the record.
|
|
74
75
|
|
|
75
76
|
#### `getItemId`: `function`
|
|
76
77
|
|
|
77
|
-
|
|
78
|
+
A function that receives an item and returns a unique identifier for it.
|
|
78
79
|
|
|
79
80
|
It's optional. The field will get a default implementation by `DataViews` that returns the value of the `item[ id ]`.
|
|
80
81
|
|
|
@@ -87,6 +88,19 @@ Example:
|
|
|
87
88
|
}
|
|
88
89
|
```
|
|
89
90
|
|
|
91
|
+
#### `getItemLevel`: `function`
|
|
92
|
+
|
|
93
|
+
A function that receives an item and returns its hierarchical level. It's optional, but this property must be passed for DataViews to display the hierarchical levels of the data if `view.showLevels` is true.
|
|
94
|
+
|
|
95
|
+
Example:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
// Example implementation
|
|
99
|
+
{
|
|
100
|
+
getItemLevel={ ( item ) => item.level }
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
90
104
|
#### `fields`: `Object[]`
|
|
91
105
|
|
|
92
106
|
The fields describe the visible items for each record in the dataset and how they behave (how to sort them, display them, etc.). See "Fields API" for a description of every property.
|
|
@@ -165,6 +179,7 @@ const view = {
|
|
|
165
179
|
field: 'date',
|
|
166
180
|
direction: 'desc',
|
|
167
181
|
},
|
|
182
|
+
titleField: 'title',
|
|
168
183
|
fields: [ 'author', 'status' ],
|
|
169
184
|
layout: {},
|
|
170
185
|
};
|
|
@@ -185,54 +200,28 @@ Properties:
|
|
|
185
200
|
- `field`: the field used for sorting the dataset.
|
|
186
201
|
- `direction`: the direction to use for sorting, one of `asc` or `desc`.
|
|
187
202
|
|
|
188
|
-
- `
|
|
203
|
+
- `titleField`: The id of the field representing the title of the record.
|
|
204
|
+
- `mediaField`: The id of the field representing the media of the record.
|
|
205
|
+
- `descriptionField`: The id of the field representing the description of the record.
|
|
206
|
+
- `showTitle`: Whether the title should be shown in the UI. `true` by default.
|
|
207
|
+
- `showMedia`: Whether the media should be shown in the UI. `true` by default.
|
|
208
|
+
- `showDescription`: Whether the description should be shown in the UI. `true` by default.
|
|
209
|
+
- `showLevels`: Whether to display the hierarchical levels for the data. `false` by default. See related `getItemLevel` DataView prop.
|
|
210
|
+
- `fields`: a list of remaining field `id` that are visible in the UI and the specific order in which they are displayed.
|
|
189
211
|
- `layout`: config that is specific to a particular layout type.
|
|
190
212
|
|
|
191
213
|
##### Properties of `layout`
|
|
192
214
|
|
|
193
|
-
| Properties of `layout`
|
|
194
|
-
|
|
|
195
|
-
| `
|
|
196
|
-
| `
|
|
197
|
-
| `columnFields`: a list of field's `id` to render vertically stacked instead of horizontally (the default). | | ✓ | |
|
|
198
|
-
| `badgeFields`: a list of field's `id` to render without label and styled as badges. | | ✓ | |
|
|
199
|
-
| `combinedFields`: a list of "virtual" fields that are made by combining others. See "Combining fields" section. | ✓ | | |
|
|
200
|
-
| `styles`: additional `width`, `maxWidth`, `minWidth` styles for each field column. | ✓ | | |
|
|
201
|
-
|
|
202
|
-
##### Combining fields
|
|
203
|
-
|
|
204
|
-
The `table` layout has the ability to create "virtual" fields that are made out by combining existing ones.
|
|
205
|
-
|
|
206
|
-
Each "virtual field", has to provide an `id` and `label` (optionally a `header` instead), which have the same meaning as any other field.
|
|
207
|
-
|
|
208
|
-
Additionally, they need to provide:
|
|
209
|
-
|
|
210
|
-
- `children`: a list of field's `id` to combine
|
|
211
|
-
- `direction`: how should they be stacked, `vertical` or `horizontal`
|
|
212
|
-
|
|
213
|
-
For example, this is how you'd define a `site` field which is a combination of a `title` and `description` fields, which are not displayed:
|
|
214
|
-
|
|
215
|
-
```js
|
|
216
|
-
{
|
|
217
|
-
fields: [ 'site', 'status' ],
|
|
218
|
-
layout: {
|
|
219
|
-
combinedFields: [
|
|
220
|
-
{
|
|
221
|
-
id: 'site',
|
|
222
|
-
label: 'Site',
|
|
223
|
-
children: [ 'title', 'description' ],
|
|
224
|
-
direction: 'vertical',
|
|
225
|
-
}
|
|
226
|
-
]
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
```
|
|
215
|
+
| Properties of `layout` | Table | Grid | List |
|
|
216
|
+
| ----------------------------------------------------------------------------------- | ----- | ---- | ---- |
|
|
217
|
+
| `badgeFields`: a list of field's `id` to render without label and styled as badges. | | ✓ | |
|
|
218
|
+
| `styles`: additional `width`, `maxWidth`, `minWidth` styles for each field column. | ✓ | | |
|
|
230
219
|
|
|
231
220
|
#### `onChangeView`: `function`
|
|
232
221
|
|
|
233
222
|
Callback executed when the view has changed. It receives the new view object as a parameter.
|
|
234
223
|
|
|
235
|
-
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.
|
|
224
|
+
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, and how it is sorted or paginated. The consumer is responsible for using the view config to query the data provider and ensure the user decisions (sort, pagination, filters, etc.) are respected.
|
|
236
225
|
|
|
237
226
|
The following example shows how a view object is used to query the WordPress REST API via the entities abstraction. The same can be done with any other data provider.
|
|
238
227
|
|
|
@@ -255,6 +244,7 @@ function MyCustomPageTable() {
|
|
|
255
244
|
value: [ 'publish', 'draft' ],
|
|
256
245
|
},
|
|
257
246
|
],
|
|
247
|
+
titleField: 'title',
|
|
258
248
|
fields: [ 'author', 'status' ],
|
|
259
249
|
layout: {},
|
|
260
250
|
} );
|
|
@@ -328,8 +318,8 @@ const actions = [
|
|
|
328
318
|
RenderModal: ( { items, closeModal, onActionPerformed } ) => (
|
|
329
319
|
<div>
|
|
330
320
|
<p>Are you sure you want to delete { items.length } item(s)?</p>
|
|
331
|
-
<Button
|
|
332
|
-
variant="primary"
|
|
321
|
+
<Button
|
|
322
|
+
variant="primary"
|
|
333
323
|
onClick={() => {
|
|
334
324
|
console.log( 'Deleting items:', items );
|
|
335
325
|
onActionPerformed();
|
|
@@ -363,39 +353,40 @@ Whether the data is loading. `false` by default.
|
|
|
363
353
|
|
|
364
354
|
#### `defaultLayouts`: `Record< string, view >`
|
|
365
355
|
|
|
366
|
-
This property provides layout information about
|
|
356
|
+
This property provides layout information about active view types. If empty, this enables all layout types (see "Layout Types") with empty layout data.
|
|
367
357
|
|
|
368
358
|
For example, this is how you'd enable only the table view type:
|
|
369
359
|
|
|
370
360
|
```js
|
|
371
361
|
const defaultLayouts = {
|
|
372
362
|
table: {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
363
|
+
showMedia: false,
|
|
364
|
+
},
|
|
365
|
+
grid: {
|
|
366
|
+
showMedia: true,
|
|
376
367
|
},
|
|
377
368
|
};
|
|
378
369
|
```
|
|
379
370
|
|
|
380
|
-
The `defaultLayouts` property should be an object that includes properties named `table`, `grid`, or `list`.
|
|
371
|
+
The `defaultLayouts` property should be an object that includes properties named `table`, `grid`, or `list`. These properties are applied to the view object each time the user switches to the corresponding layout.
|
|
381
372
|
|
|
382
373
|
#### `selection`: `string[]`
|
|
383
374
|
|
|
384
375
|
The list of selected items' ids.
|
|
385
376
|
|
|
386
|
-
If `selection` and `onChangeSelection` are provided, the `DataViews` component behaves
|
|
377
|
+
If `selection` and `onChangeSelection` are provided, the `DataViews` component behaves like a controlled component. Otherwise, it behaves like an uncontrolled component.
|
|
387
378
|
|
|
388
379
|
#### `onChangeSelection`: `function`
|
|
389
380
|
|
|
390
|
-
Callback that signals the user selected one of more items. It receives the list of selected items'
|
|
381
|
+
Callback that signals the user selected one of more items. It receives the list of selected items' IDs as a parameter.
|
|
391
382
|
|
|
392
|
-
If `selection` and `onChangeSelection` are provided, the `DataViews` component behaves
|
|
383
|
+
If `selection` and `onChangeSelection` are provided, the `DataViews` component behaves like a controlled component. Otherwise, it behaves like an uncontrolled component.
|
|
393
384
|
|
|
394
|
-
|
|
385
|
+
#### `isItemClickable`: `function`
|
|
395
386
|
|
|
396
|
-
A function that determines if a media field or a primary field
|
|
387
|
+
A function that determines if a media field or a primary field is clickable. It receives an item as an argument and returns a boolean value indicating whether the item can be clicked.
|
|
397
388
|
|
|
398
|
-
|
|
389
|
+
#### `onClickItem`: `function`
|
|
399
390
|
|
|
400
391
|
A callback function that is triggered when a user clicks on a media field or primary field. This function is currently implemented only in the `grid` and `list` views.
|
|
401
392
|
|
|
@@ -420,8 +411,8 @@ const Example = () => {
|
|
|
420
411
|
form={ form }
|
|
421
412
|
onChange={ onChange }
|
|
422
413
|
/>
|
|
423
|
-
)
|
|
424
|
-
}
|
|
414
|
+
);
|
|
415
|
+
};
|
|
425
416
|
```
|
|
426
417
|
|
|
427
418
|
### Properties
|
|
@@ -430,7 +421,7 @@ const Example = () => {
|
|
|
430
421
|
|
|
431
422
|
A single item to be edited.
|
|
432
423
|
|
|
433
|
-
It can be
|
|
424
|
+
It can be thought of as a single record coming from the `data` property of `DataViews` — though it doesn't need to be. It can be totally separated or a mix of records if your app supports bulk editing.
|
|
434
425
|
|
|
435
426
|
#### `fields`: `Object[]`
|
|
436
427
|
|
|
@@ -464,8 +455,30 @@ const fields = [
|
|
|
464
455
|
|
|
465
456
|
#### `form`: `Object[]`
|
|
466
457
|
|
|
467
|
-
-
|
|
468
|
-
-
|
|
458
|
+
- `type`: either `regular` or `panel`.
|
|
459
|
+
- `labelPosition`: either `side`, `top`, or `none`.
|
|
460
|
+
- `fields`: a list of fields ids that should be rendered. Field ids can also be defined as an object and allow you to define a `layout`, `labelPosition` or `children` if displaying combined fields. See "Form Field API" for a description of every property.
|
|
461
|
+
|
|
462
|
+
Example:
|
|
463
|
+
|
|
464
|
+
```js
|
|
465
|
+
const form = {
|
|
466
|
+
type: 'panel',
|
|
467
|
+
fields: [
|
|
468
|
+
'title',
|
|
469
|
+
'data',
|
|
470
|
+
{
|
|
471
|
+
id: 'status',
|
|
472
|
+
label: 'Status & Visibility',
|
|
473
|
+
children: [ 'status', 'password' ],
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
id: 'featured_media',
|
|
477
|
+
layout: 'regular',
|
|
478
|
+
},
|
|
479
|
+
],
|
|
480
|
+
};
|
|
481
|
+
```
|
|
469
482
|
|
|
470
483
|
#### `onChange`: `function`
|
|
471
484
|
|
|
@@ -496,10 +509,10 @@ const onChange = ( edits ) => {
|
|
|
496
509
|
|
|
497
510
|
return (
|
|
498
511
|
<DataForm
|
|
499
|
-
data={data}
|
|
500
|
-
fields={fields}
|
|
501
|
-
form={form}
|
|
502
|
-
onChange={onChange}
|
|
512
|
+
data={ data }
|
|
513
|
+
fields={ fields }
|
|
514
|
+
form={ form }
|
|
515
|
+
onChange={ onChange }
|
|
503
516
|
/>
|
|
504
517
|
);
|
|
505
518
|
```
|
|
@@ -512,26 +525,26 @@ Utility to apply the view config (filters, search, sorting, and pagination) to a
|
|
|
512
525
|
|
|
513
526
|
Parameters:
|
|
514
527
|
|
|
515
|
-
-
|
|
516
|
-
-
|
|
517
|
-
-
|
|
528
|
+
- `data`: the dataset, as described in the "data" property of DataViews.
|
|
529
|
+
- `view`: the view config, as described in the "view" property of DataViews.
|
|
530
|
+
- `fields`: the fields config, as described in the "fields" property of DataViews.
|
|
518
531
|
|
|
519
532
|
Returns an object containing:
|
|
520
533
|
|
|
521
|
-
-
|
|
522
|
-
-
|
|
523
|
-
|
|
524
|
-
|
|
534
|
+
- `data`: the new dataset, with the view config applied.
|
|
535
|
+
- `paginationInfo`: object containing the following properties:
|
|
536
|
+
- `totalItems`: total number of items for the current view config.
|
|
537
|
+
- `totalPages`: total number of pages for the current view config.
|
|
525
538
|
|
|
526
539
|
### `isItemValid`
|
|
527
540
|
|
|
528
|
-
Utility to determine whether or not the given item's value is valid according to the current fields and form
|
|
541
|
+
Utility is used to determine whether or not the given item's value is valid according to the current fields and form configuration.
|
|
529
542
|
|
|
530
543
|
Parameters:
|
|
531
544
|
|
|
532
|
-
-
|
|
533
|
-
-
|
|
534
|
-
-
|
|
545
|
+
- `item`: the item, as described in the "data" property of DataForm.
|
|
546
|
+
- `fields`: the fields config, as described in the "fields" property of DataForm.
|
|
547
|
+
- `form`: the form config, as described in the "form" property of DataForm.
|
|
535
548
|
|
|
536
549
|
Returns a boolean indicating if the item is valid (true) or not (false).
|
|
537
550
|
|
|
@@ -541,17 +554,17 @@ Returns a boolean indicating if the item is valid (true) or not (false).
|
|
|
541
554
|
|
|
542
555
|
The unique identifier of the action.
|
|
543
556
|
|
|
544
|
-
-
|
|
545
|
-
-
|
|
546
|
-
-
|
|
557
|
+
- Type: `string`
|
|
558
|
+
- Required
|
|
559
|
+
- Example: `move-to-trash`
|
|
547
560
|
|
|
548
|
-
### `label`
|
|
561
|
+
### `label`
|
|
549
562
|
|
|
550
563
|
The user facing description of the action.
|
|
551
564
|
|
|
552
|
-
-
|
|
553
|
-
-
|
|
554
|
-
-
|
|
565
|
+
- Type: `string | function`
|
|
566
|
+
- Required
|
|
567
|
+
- Example:
|
|
555
568
|
|
|
556
569
|
```js
|
|
557
570
|
{
|
|
@@ -563,7 +576,7 @@ or
|
|
|
563
576
|
|
|
564
577
|
```js
|
|
565
578
|
{
|
|
566
|
-
label: ( items ) => items.length > 1 ? 'Delete items' : 'Delete item'
|
|
579
|
+
label: ( items ) => ( items.length > 1 ? 'Delete items' : 'Delete item' );
|
|
567
580
|
}
|
|
568
581
|
```
|
|
569
582
|
|
|
@@ -571,27 +584,27 @@ or
|
|
|
571
584
|
|
|
572
585
|
Whether the action should be displayed inline (primary) or only displayed in the "More actions" menu (secondary).
|
|
573
586
|
|
|
574
|
-
-
|
|
575
|
-
-
|
|
587
|
+
- Type: `boolean`
|
|
588
|
+
- Optional
|
|
576
589
|
|
|
577
590
|
### `icon`
|
|
578
591
|
|
|
579
592
|
Icon to show for primary actions.
|
|
580
593
|
|
|
581
|
-
-
|
|
582
|
-
-
|
|
594
|
+
- Type: SVG element
|
|
595
|
+
- Required for primary actions, optional for secondary actions.
|
|
583
596
|
|
|
584
597
|
### `isEligible`
|
|
585
598
|
|
|
586
599
|
Function that determines whether the action can be performed for a given record.
|
|
587
600
|
|
|
588
|
-
-
|
|
589
|
-
-
|
|
590
|
-
-
|
|
601
|
+
- Type: `function`
|
|
602
|
+
- Optional. If not present, action is considered eligible for all items.
|
|
603
|
+
- Example:
|
|
591
604
|
|
|
592
605
|
```js
|
|
593
606
|
{
|
|
594
|
-
isEligible: ( item ) => item.status === 'published'
|
|
607
|
+
isEligible: ( item ) => item.status === 'published';
|
|
595
608
|
}
|
|
596
609
|
```
|
|
597
610
|
|
|
@@ -599,47 +612,47 @@ Function that determines whether the action can be performed for a given record.
|
|
|
599
612
|
|
|
600
613
|
Whether the action can delete data, in which case the UI communicates it via a red color.
|
|
601
614
|
|
|
602
|
-
-
|
|
603
|
-
-
|
|
615
|
+
- Type: `boolean`
|
|
616
|
+
- Optional
|
|
604
617
|
|
|
605
618
|
### `supportsBulk`
|
|
606
619
|
|
|
607
620
|
Whether the action can operate over multiple items at once.
|
|
608
621
|
|
|
609
|
-
-
|
|
610
|
-
-
|
|
611
|
-
-
|
|
622
|
+
- Type: `boolean`
|
|
623
|
+
- Optional
|
|
624
|
+
- Default: `false`
|
|
612
625
|
|
|
613
626
|
### `disabled`
|
|
614
627
|
|
|
615
628
|
Whether the action is disabled.
|
|
616
629
|
|
|
617
|
-
-
|
|
618
|
-
-
|
|
619
|
-
-
|
|
630
|
+
- Type: `boolean`
|
|
631
|
+
- Optional
|
|
632
|
+
- Default: `false`
|
|
620
633
|
|
|
621
634
|
### `context`
|
|
622
635
|
|
|
623
636
|
Where this action would be visible.
|
|
624
637
|
|
|
625
|
-
-
|
|
626
|
-
-
|
|
627
|
-
-
|
|
638
|
+
- Type: `string`
|
|
639
|
+
- Optional
|
|
640
|
+
- One of: `list`, `single`
|
|
628
641
|
|
|
629
642
|
### `callback`
|
|
630
643
|
|
|
631
644
|
Function that performs the required action.
|
|
632
645
|
|
|
633
|
-
-
|
|
634
|
-
-
|
|
635
|
-
-
|
|
646
|
+
- Type: `function`
|
|
647
|
+
- Either `callback` or `RenderModal` must be provided. If `RenderModal` is provided, `callback` will be ignored
|
|
648
|
+
- Example:
|
|
636
649
|
|
|
637
650
|
```js
|
|
638
651
|
{
|
|
639
652
|
callback: ( items, { onActionPerformed } ) => {
|
|
640
653
|
// Perform action.
|
|
641
654
|
onActionPerformed?.( items );
|
|
642
|
-
}
|
|
655
|
+
};
|
|
643
656
|
}
|
|
644
657
|
```
|
|
645
658
|
|
|
@@ -647,9 +660,9 @@ Function that performs the required action.
|
|
|
647
660
|
|
|
648
661
|
Component to render UI in a modal for the action.
|
|
649
662
|
|
|
650
|
-
-
|
|
651
|
-
-
|
|
652
|
-
-
|
|
663
|
+
- Type: `ReactElement`
|
|
664
|
+
- Either `callback` or `RenderModal` must be provided. If `RenderModal` is provided, `callback` will be ignored.
|
|
665
|
+
- Example:
|
|
653
666
|
|
|
654
667
|
```jsx
|
|
655
668
|
{
|
|
@@ -673,7 +686,7 @@ Component to render UI in a modal for the action.
|
|
|
673
686
|
</HStack>
|
|
674
687
|
</form>
|
|
675
688
|
);
|
|
676
|
-
}
|
|
689
|
+
};
|
|
677
690
|
}
|
|
678
691
|
```
|
|
679
692
|
|
|
@@ -681,17 +694,16 @@ Component to render UI in a modal for the action.
|
|
|
681
694
|
|
|
682
695
|
Controls visibility of the modal's header when using `RenderModal`.
|
|
683
696
|
|
|
684
|
-
-
|
|
685
|
-
-
|
|
686
|
-
-
|
|
697
|
+
- Type: `boolean`
|
|
698
|
+
- Optional
|
|
699
|
+
- When false and using `RenderModal`, the action's label is used in modal header
|
|
687
700
|
|
|
688
701
|
### `modalHeader`
|
|
689
702
|
|
|
690
703
|
The header text to show in the modal.
|
|
691
704
|
|
|
692
|
-
-
|
|
693
|
-
-
|
|
694
|
-
|
|
705
|
+
- Type: `string`
|
|
706
|
+
- Optional
|
|
695
707
|
|
|
696
708
|
## Fields API
|
|
697
709
|
|
|
@@ -699,78 +711,88 @@ The header text to show in the modal.
|
|
|
699
711
|
|
|
700
712
|
The unique identifier of the field.
|
|
701
713
|
|
|
702
|
-
-
|
|
703
|
-
-
|
|
714
|
+
- Type: `string`.
|
|
715
|
+
- Required.
|
|
704
716
|
|
|
705
717
|
Example:
|
|
706
718
|
|
|
707
719
|
```js
|
|
708
|
-
{
|
|
720
|
+
{
|
|
721
|
+
id: 'field_id';
|
|
722
|
+
}
|
|
709
723
|
```
|
|
710
724
|
|
|
711
725
|
### `type`
|
|
712
726
|
|
|
713
727
|
Field type. One of `text`, `integer`, `datetime`.
|
|
714
728
|
|
|
715
|
-
If a field declares a `type`, it gets default implementations for the `sort`, `isValid`, and `Edit` functions
|
|
729
|
+
If a field declares a `type`, it gets default implementations for the `sort`, `isValid`, and `Edit` functions if no other values are specified.
|
|
716
730
|
|
|
717
|
-
-
|
|
718
|
-
-
|
|
731
|
+
- Type: `string`.
|
|
732
|
+
- Optional.
|
|
719
733
|
|
|
720
734
|
Example:
|
|
721
735
|
|
|
722
736
|
```js
|
|
723
|
-
{
|
|
737
|
+
{
|
|
738
|
+
type: 'text';
|
|
739
|
+
}
|
|
724
740
|
```
|
|
725
741
|
|
|
726
742
|
### `label`
|
|
727
743
|
|
|
728
744
|
The field's name. This will be used across the UI.
|
|
729
745
|
|
|
730
|
-
-
|
|
731
|
-
-
|
|
732
|
-
-
|
|
746
|
+
- Type: `string`.
|
|
747
|
+
- Optional.
|
|
748
|
+
- Defaults to the `id` value.
|
|
733
749
|
|
|
734
750
|
Example:
|
|
735
751
|
|
|
736
752
|
```js
|
|
737
|
-
{
|
|
753
|
+
{
|
|
754
|
+
label: 'Title';
|
|
755
|
+
}
|
|
738
756
|
```
|
|
739
757
|
|
|
740
758
|
### `header`
|
|
741
759
|
|
|
742
760
|
React component used by the layouts to display the field name — useful to add icons, etc. It's complementary to the `label` property.
|
|
743
761
|
|
|
744
|
-
-
|
|
745
|
-
-
|
|
746
|
-
-
|
|
747
|
-
-
|
|
748
|
-
-
|
|
762
|
+
- Type: React component.
|
|
763
|
+
- Optional.
|
|
764
|
+
- Defaults to the `label` value.
|
|
765
|
+
- Props: none.
|
|
766
|
+
- Returns a React element that represents the field's name.
|
|
749
767
|
|
|
750
768
|
Example:
|
|
751
769
|
|
|
752
770
|
```js
|
|
753
771
|
{
|
|
754
|
-
header: () => {
|
|
772
|
+
header: () => {
|
|
773
|
+
/* Returns a react element. */
|
|
774
|
+
};
|
|
755
775
|
}
|
|
756
776
|
```
|
|
757
777
|
|
|
758
778
|
### `getValue`
|
|
759
779
|
|
|
760
|
-
React component that returns the value of a field. This value is used
|
|
780
|
+
React component that returns the value of a field. This value is used to sort or filter the fields.
|
|
761
781
|
|
|
762
|
-
-
|
|
763
|
-
-
|
|
764
|
-
-
|
|
765
|
-
-
|
|
766
|
-
|
|
767
|
-
-
|
|
782
|
+
- Type: React component.
|
|
783
|
+
- Optional.
|
|
784
|
+
- Defaults to `item[ id ]`.
|
|
785
|
+
- Props:
|
|
786
|
+
- `item` value to be processed.
|
|
787
|
+
- Returns a value that represents the field.
|
|
768
788
|
|
|
769
789
|
Example:
|
|
770
790
|
|
|
771
791
|
```js
|
|
772
792
|
{
|
|
773
|
-
getValue: ( { item } ) => {
|
|
793
|
+
getValue: ( { item } ) => {
|
|
794
|
+
/* The field's value. */
|
|
795
|
+
};
|
|
774
796
|
}
|
|
775
797
|
```
|
|
776
798
|
|
|
@@ -778,18 +800,20 @@ Example:
|
|
|
778
800
|
|
|
779
801
|
React component that renders the field. This is used by the layouts.
|
|
780
802
|
|
|
781
|
-
-
|
|
782
|
-
-
|
|
783
|
-
-
|
|
784
|
-
-
|
|
785
|
-
|
|
786
|
-
-
|
|
803
|
+
- Type: React component.
|
|
804
|
+
- Optional.
|
|
805
|
+
- Defaults to `getValue`.
|
|
806
|
+
- Props
|
|
807
|
+
- `item` value to be processed.
|
|
808
|
+
- Returns a React element that represents the field's value.
|
|
787
809
|
|
|
788
810
|
Example:
|
|
789
811
|
|
|
790
812
|
```js
|
|
791
813
|
{
|
|
792
|
-
render: ( { item} ) => {
|
|
814
|
+
render: ( { item } ) => {
|
|
815
|
+
/* React element to be displayed. */
|
|
816
|
+
};
|
|
793
817
|
}
|
|
794
818
|
```
|
|
795
819
|
|
|
@@ -797,26 +821,21 @@ Example:
|
|
|
797
821
|
|
|
798
822
|
React component that renders the control to edit the field.
|
|
799
823
|
|
|
800
|
-
-
|
|
801
|
-
-
|
|
802
|
-
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
-
|
|
824
|
+
- Type: React component | `string`. If it's a string, it needs to be one of `text`, `integer`, `datetime`, `radio`, `select`.
|
|
825
|
+
- Required by DataForm. Optional if the field provided a `type`.
|
|
826
|
+
- Props:
|
|
827
|
+
- `data`: the item to be processed
|
|
828
|
+
- `field`: the field definition
|
|
829
|
+
- `onChange`: the callback with the updates
|
|
830
|
+
- `hideLabelFromVision`: boolean representing if the label should be hidden
|
|
831
|
+
- Returns a React element to edit the field's value.
|
|
808
832
|
|
|
809
833
|
Example:
|
|
810
834
|
|
|
811
835
|
```js
|
|
812
836
|
// A custom control defined by the field.
|
|
813
837
|
{
|
|
814
|
-
Edit: ( {
|
|
815
|
-
data,
|
|
816
|
-
field,
|
|
817
|
-
onChange,
|
|
818
|
-
hideLabelFromVision
|
|
819
|
-
} ) => {
|
|
838
|
+
Edit: ( { data, field, onChange, hideLabelFromVision } ) => {
|
|
820
839
|
const value = field.getValue( { item: data } );
|
|
821
840
|
|
|
822
841
|
return (
|
|
@@ -826,14 +845,14 @@ Example:
|
|
|
826
845
|
hideLabelFromVision
|
|
827
846
|
/>
|
|
828
847
|
);
|
|
829
|
-
}
|
|
848
|
+
};
|
|
830
849
|
}
|
|
831
850
|
```
|
|
832
851
|
|
|
833
852
|
```js
|
|
834
853
|
// Use one of the core controls.
|
|
835
854
|
{
|
|
836
|
-
Edit: 'radio'
|
|
855
|
+
Edit: 'radio';
|
|
837
856
|
}
|
|
838
857
|
```
|
|
839
858
|
|
|
@@ -841,7 +860,7 @@ Example:
|
|
|
841
860
|
// Edit is optional when field's type is present.
|
|
842
861
|
// The field will use the default Edit function for text.
|
|
843
862
|
{
|
|
844
|
-
type: 'text'
|
|
863
|
+
type: 'text';
|
|
845
864
|
}
|
|
846
865
|
```
|
|
847
866
|
|
|
@@ -858,16 +877,16 @@ Example:
|
|
|
858
877
|
|
|
859
878
|
Function to sort the records.
|
|
860
879
|
|
|
861
|
-
-
|
|
862
|
-
-
|
|
863
|
-
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
880
|
+
- Type: `function`.
|
|
881
|
+
- Optional.
|
|
882
|
+
- Args
|
|
883
|
+
- `a`: the first item to compare
|
|
884
|
+
- `b`: the second item to compare
|
|
885
|
+
- `direction`: either `asc` (ascending) or `desc` (descending)
|
|
886
|
+
- Returns a number where:
|
|
887
|
+
- a negative value indicates that `a` should come before `b`
|
|
888
|
+
- a positive value indicates that `a` should come after `b`
|
|
889
|
+
- 0 indicates that `a` and `b` are considered equal
|
|
871
890
|
|
|
872
891
|
Example:
|
|
873
892
|
|
|
@@ -878,7 +897,7 @@ Example:
|
|
|
878
897
|
return direction === 'asc'
|
|
879
898
|
? a.localeCompare( b )
|
|
880
899
|
: b.localeCompare( a );
|
|
881
|
-
}
|
|
900
|
+
};
|
|
882
901
|
}
|
|
883
902
|
```
|
|
884
903
|
|
|
@@ -886,7 +905,7 @@ Example:
|
|
|
886
905
|
// If field type is provided,
|
|
887
906
|
// the field gets a default sort function.
|
|
888
907
|
{
|
|
889
|
-
type: 'number'
|
|
908
|
+
type: 'number';
|
|
890
909
|
}
|
|
891
910
|
```
|
|
892
911
|
|
|
@@ -894,8 +913,10 @@ Example:
|
|
|
894
913
|
// Even if a field type is provided,
|
|
895
914
|
// fields can override the default sort function assigned for that type.
|
|
896
915
|
{
|
|
897
|
-
type: 'number'
|
|
898
|
-
sort: ( a, b, direction ) => {
|
|
916
|
+
type: 'number';
|
|
917
|
+
sort: ( a, b, direction ) => {
|
|
918
|
+
/* Custom sort */
|
|
919
|
+
};
|
|
899
920
|
}
|
|
900
921
|
```
|
|
901
922
|
|
|
@@ -903,13 +924,13 @@ Example:
|
|
|
903
924
|
|
|
904
925
|
Function to validate a field's value.
|
|
905
926
|
|
|
906
|
-
-
|
|
907
|
-
-
|
|
908
|
-
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
-
|
|
927
|
+
- Type: function.
|
|
928
|
+
- Optional.
|
|
929
|
+
- Args
|
|
930
|
+
- `item`: the data to validate
|
|
931
|
+
- `context`: an object containing the following props:
|
|
932
|
+
- `elements`: the elements defined by the field
|
|
933
|
+
- Returns a boolean, indicating if the field is valid or not.
|
|
913
934
|
|
|
914
935
|
Example:
|
|
915
936
|
|
|
@@ -918,7 +939,7 @@ Example:
|
|
|
918
939
|
{
|
|
919
940
|
isValid: ( item, context ) => {
|
|
920
941
|
return !! item;
|
|
921
|
-
}
|
|
942
|
+
};
|
|
922
943
|
}
|
|
923
944
|
```
|
|
924
945
|
|
|
@@ -943,18 +964,20 @@ Example:
|
|
|
943
964
|
|
|
944
965
|
Function that indicates if the field should be visible.
|
|
945
966
|
|
|
946
|
-
-
|
|
947
|
-
-
|
|
948
|
-
-
|
|
949
|
-
|
|
950
|
-
-
|
|
967
|
+
- Type: `function`.
|
|
968
|
+
- Optional.
|
|
969
|
+
- Args
|
|
970
|
+
- `item`: the data to be processed
|
|
971
|
+
- Returns a `boolean` indicating if the field should be visible (`true`) or not (`false`).
|
|
951
972
|
|
|
952
973
|
Example:
|
|
953
974
|
|
|
954
975
|
```js
|
|
955
976
|
// Custom isVisible function.
|
|
956
977
|
{
|
|
957
|
-
isVisible: ( item ) => {
|
|
978
|
+
isVisible: ( item ) => {
|
|
979
|
+
/* Custom implementation. */
|
|
980
|
+
};
|
|
958
981
|
}
|
|
959
982
|
```
|
|
960
983
|
|
|
@@ -962,54 +985,60 @@ Example:
|
|
|
962
985
|
|
|
963
986
|
Boolean indicating if the field is sortable.
|
|
964
987
|
|
|
965
|
-
-
|
|
966
|
-
-
|
|
967
|
-
-
|
|
988
|
+
- Type: `boolean`.
|
|
989
|
+
- Optional.
|
|
990
|
+
- Defaults to `true`.
|
|
968
991
|
|
|
969
992
|
Example:
|
|
970
993
|
|
|
971
994
|
```js
|
|
972
|
-
{
|
|
995
|
+
{
|
|
996
|
+
enableSorting: true;
|
|
997
|
+
}
|
|
973
998
|
```
|
|
974
999
|
|
|
975
1000
|
### `enableHiding`
|
|
976
1001
|
|
|
977
1002
|
Boolean indicating if the field can be hidden.
|
|
978
1003
|
|
|
979
|
-
-
|
|
980
|
-
-
|
|
981
|
-
-
|
|
1004
|
+
- Type: `boolean`.
|
|
1005
|
+
- Optional.
|
|
1006
|
+
- Defaults to `true`.
|
|
982
1007
|
|
|
983
1008
|
Example:
|
|
984
1009
|
|
|
985
1010
|
```js
|
|
986
|
-
{
|
|
1011
|
+
{
|
|
1012
|
+
enableHiding: true;
|
|
1013
|
+
}
|
|
987
1014
|
```
|
|
988
1015
|
|
|
989
1016
|
### `enableGlobalSearch`
|
|
990
1017
|
|
|
991
1018
|
Boolean indicating if the field is searchable.
|
|
992
1019
|
|
|
993
|
-
-
|
|
994
|
-
-
|
|
995
|
-
-
|
|
1020
|
+
- Type: `boolean`.
|
|
1021
|
+
- Optional.
|
|
1022
|
+
- Defaults to `false`.
|
|
996
1023
|
|
|
997
1024
|
Example:
|
|
998
1025
|
|
|
999
1026
|
```js
|
|
1000
|
-
{
|
|
1027
|
+
{
|
|
1028
|
+
enableGlobalSearch: true;
|
|
1029
|
+
}
|
|
1001
1030
|
```
|
|
1002
1031
|
|
|
1003
1032
|
### `elements`
|
|
1004
1033
|
|
|
1005
|
-
List of valid values for a field. If provided, it creates a DataViews' filter for the field. DataForm's edit control will use these values
|
|
1034
|
+
List of valid values for a field. If provided, it creates a DataViews' filter for the field. DataForm's edit control will also use these values. (See `Edit` field property.)
|
|
1006
1035
|
|
|
1007
|
-
-
|
|
1008
|
-
-
|
|
1009
|
-
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1036
|
+
- Type: `array` of objects.
|
|
1037
|
+
- Optional.
|
|
1038
|
+
- Each object can have the following properties:
|
|
1039
|
+
- `value`: the value to match against the field's value. (Required)
|
|
1040
|
+
- `label`: the name to display to users. (Required)
|
|
1041
|
+
- `description`: optional, a longer description of the item.
|
|
1013
1042
|
|
|
1014
1043
|
Example:
|
|
1015
1044
|
|
|
@@ -1020,7 +1049,7 @@ Example:
|
|
|
1020
1049
|
{ value: '2', label: 'Product B' },
|
|
1021
1050
|
{ value: '3', label: 'Product C' },
|
|
1022
1051
|
{ value: '4', label: 'Product D' },
|
|
1023
|
-
]
|
|
1052
|
+
];
|
|
1024
1053
|
}
|
|
1025
1054
|
```
|
|
1026
1055
|
|
|
@@ -1028,11 +1057,11 @@ Example:
|
|
|
1028
1057
|
|
|
1029
1058
|
Configuration of the filters.
|
|
1030
1059
|
|
|
1031
|
-
-
|
|
1032
|
-
-
|
|
1033
|
-
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1060
|
+
- Type: `object`.
|
|
1061
|
+
- Optional.
|
|
1062
|
+
- Properties:
|
|
1063
|
+
- `operators`: the list of operators supported by the field. See "operators" below. A filter will support the `isAny` and `isNone` multi-selection operators by default.
|
|
1064
|
+
- `isPrimary`: boolean, optional. Indicates if the filter is primary. 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.
|
|
1036
1065
|
|
|
1037
1066
|
Operators:
|
|
1038
1067
|
|
|
@@ -1045,7 +1074,7 @@ Operators:
|
|
|
1045
1074
|
| `isAll` | Multiple items | `AND`. The item's field has all of the values in the list. | Category is all: Book, Review, Science Fiction |
|
|
1046
1075
|
| `isNotAll` | Multiple items | `NOT AND`. The item's field doesn't have all of the values in the list. | Category is not all: Book, Review, Science Fiction |
|
|
1047
1076
|
|
|
1048
|
-
`is` and `isNot` are single-selection operators, while `isAny`, `isNone`, `isAll`, and `isNotALl` are multi-selection.
|
|
1077
|
+
`is` and `isNot` are single-selection operators, while `isAny`, `isNone`, `isAll`, and `isNotALl` are multi-selection. A filter with no operators declared will support the `isAny` and `isNone` multi-selection operators by default. A filter cannot mix single-selection & multi-selection operators; if a single-selection operator is present in the list of valid operators, the multi-selection ones will be discarded, and the filter won't allow selecting more than one item.
|
|
1049
1078
|
|
|
1050
1079
|
Example:
|
|
1051
1080
|
|
|
@@ -1053,7 +1082,7 @@ Example:
|
|
|
1053
1082
|
// Set a filter as primary.
|
|
1054
1083
|
{
|
|
1055
1084
|
filterBy: {
|
|
1056
|
-
isPrimary: true
|
|
1085
|
+
isPrimary: true;
|
|
1057
1086
|
}
|
|
1058
1087
|
}
|
|
1059
1088
|
```
|
|
@@ -1062,7 +1091,7 @@ Example:
|
|
|
1062
1091
|
// Configure a filter as single-selection.
|
|
1063
1092
|
{
|
|
1064
1093
|
filterBy: {
|
|
1065
|
-
operators: [ `is`, `isNot` ]
|
|
1094
|
+
operators: [ `is`, `isNot` ];
|
|
1066
1095
|
}
|
|
1067
1096
|
}
|
|
1068
1097
|
```
|
|
@@ -1071,11 +1100,91 @@ Example:
|
|
|
1071
1100
|
// Configure a filter as multi-selection with all the options.
|
|
1072
1101
|
{
|
|
1073
1102
|
filterBy: {
|
|
1074
|
-
operators: [ `isAny`, `isNone`, `isAll`, `isNotAll` ]
|
|
1103
|
+
operators: [ `isAny`, `isNone`, `isAll`, `isNotAll` ];
|
|
1075
1104
|
}
|
|
1076
1105
|
}
|
|
1077
1106
|
```
|
|
1078
1107
|
|
|
1108
|
+
## Form Field API
|
|
1109
|
+
|
|
1110
|
+
### `id`
|
|
1111
|
+
|
|
1112
|
+
The unique identifier of the field.
|
|
1113
|
+
|
|
1114
|
+
- Type: `string`.
|
|
1115
|
+
- Required.
|
|
1116
|
+
|
|
1117
|
+
Example:
|
|
1118
|
+
|
|
1119
|
+
```js
|
|
1120
|
+
{
|
|
1121
|
+
id: 'field_id';
|
|
1122
|
+
}
|
|
1123
|
+
```
|
|
1124
|
+
|
|
1125
|
+
### `layout`
|
|
1126
|
+
|
|
1127
|
+
The same as the `form.type`, either `regular` or `panel` only for the individual field. It defaults to `form.type`.
|
|
1128
|
+
|
|
1129
|
+
- Type: `string`.
|
|
1130
|
+
|
|
1131
|
+
Example:
|
|
1132
|
+
|
|
1133
|
+
```js
|
|
1134
|
+
{
|
|
1135
|
+
id: 'field_id',
|
|
1136
|
+
layout: 'regular'
|
|
1137
|
+
}
|
|
1138
|
+
```
|
|
1139
|
+
|
|
1140
|
+
### `labelPosition`
|
|
1141
|
+
|
|
1142
|
+
The same as the `form.labelPosition`, either `side`, `top`, or `none` for the individual field. It defaults to `form.labelPosition`.
|
|
1143
|
+
|
|
1144
|
+
- Type: `string`.
|
|
1145
|
+
|
|
1146
|
+
Example:
|
|
1147
|
+
|
|
1148
|
+
```js
|
|
1149
|
+
{
|
|
1150
|
+
id: 'field_id',
|
|
1151
|
+
labelPosition: 'none'
|
|
1152
|
+
}
|
|
1153
|
+
```
|
|
1154
|
+
|
|
1155
|
+
### `label`
|
|
1156
|
+
|
|
1157
|
+
The label used when displaying a combined field, this requires the use of `children` as well.
|
|
1158
|
+
|
|
1159
|
+
- Type: `string`.
|
|
1160
|
+
|
|
1161
|
+
Example:
|
|
1162
|
+
|
|
1163
|
+
```js
|
|
1164
|
+
{
|
|
1165
|
+
id: 'field_id',
|
|
1166
|
+
label: 'Combined Field',
|
|
1167
|
+
children: [ 'field1', 'field2' ]
|
|
1168
|
+
}
|
|
1169
|
+
```
|
|
1170
|
+
|
|
1171
|
+
### `children`
|
|
1172
|
+
|
|
1173
|
+
Groups a set of fields defined within children. For example if you want to display multiple fields within the Panel dropdown you can use children ( see example ).
|
|
1174
|
+
|
|
1175
|
+
- Type: `Array< string | FormField >`.
|
|
1176
|
+
|
|
1177
|
+
Example:
|
|
1178
|
+
|
|
1179
|
+
```js
|
|
1180
|
+
{
|
|
1181
|
+
id: 'status',
|
|
1182
|
+
layout: 'panel',
|
|
1183
|
+
label: 'Combined Field',
|
|
1184
|
+
children: [ 'field1', 'field2' ],
|
|
1185
|
+
}
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1079
1188
|
## Contributing to this package
|
|
1080
1189
|
|
|
1081
1190
|
This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
|