@wordpress/dataviews 4.10.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 +19 -9
- package/LICENSE.md +1 -1
- package/README.md +309 -175
- package/build/components/dataviews/index.js +12 -1
- package/build/components/dataviews/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 +35 -30
- package/build/components/dataviews-filters/add-filter.js.map +1 -1
- package/build/components/dataviews-filters/index.js +3 -1
- package/build/components/dataviews-filters/index.js.map +1 -1
- package/build/components/dataviews-item-actions/index.js +24 -19
- package/build/components/dataviews-item-actions/index.js.map +1 -1
- package/build/components/dataviews-layout/index.js +2 -0
- package/build/components/dataviews-layout/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +48 -43
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/dataviews-layouts/grid/index.js +12 -5
- 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/list/index.js +27 -20
- package/build/dataviews-layouts/list/index.js.map +1 -1
- package/build/dataviews-layouts/table/column-header-menu.js +102 -99
- package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build/dataviews-layouts/table/column-primary.js +7 -3
- package/build/dataviews-layouts/table/column-primary.js.map +1 -1
- package/build/dataviews-layouts/table/index.js +4 -0
- package/build/dataviews-layouts/table/index.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/components/dataviews/index.js +12 -1
- package/build-module/components/dataviews/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 +36 -31
- package/build-module/components/dataviews-filters/add-filter.js.map +1 -1
- package/build-module/components/dataviews-filters/index.js +3 -1
- package/build-module/components/dataviews-filters/index.js.map +1 -1
- package/build-module/components/dataviews-item-actions/index.js +24 -19
- package/build-module/components/dataviews-item-actions/index.js.map +1 -1
- package/build-module/components/dataviews-layout/index.js +2 -0
- package/build-module/components/dataviews-layout/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +49 -44
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/index.js +14 -7
- 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/list/index.js +27 -20
- package/build-module/dataviews-layouts/list/index.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-header-menu.js +102 -99
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-primary.js +7 -3
- package/build-module/dataviews-layouts/table/column-primary.js.map +1 -1
- package/build-module/dataviews-layouts/table/index.js +4 -0
- package/build-module/dataviews-layouts/table/index.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-style/style-rtl.css +45 -55
- package/build-style/style.css +45 -55
- 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-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.map +1 -1
- package/build-types/components/dataviews-layout/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/list/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-primary.d.ts +2 -1
- package/build-types/dataviews-layouts/table/column-primary.d.ts.map +1 -1
- 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/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 +5 -0
- package/build-types/types.d.ts.map +1 -1
- package/build-wp/index.js +1209 -999
- package/package.json +13 -12
- package/src/components/dataviews/index.tsx +15 -1
- package/src/components/dataviews/style.scss +0 -1
- 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 +25 -27
- package/src/components/dataviews-layout/index.tsx +2 -0
- package/src/components/dataviews-view-config/index.tsx +52 -43
- package/src/components/dataviews-view-config/style.scss +0 -1
- package/src/dataviews-layouts/grid/index.tsx +17 -5
- package/src/dataviews-layouts/grid/preview-size-picker.tsx +25 -30
- package/src/dataviews-layouts/grid/style.scss +24 -33
- package/src/dataviews-layouts/list/index.tsx +35 -27
- package/src/dataviews-layouts/list/style.scss +5 -5
- package/src/dataviews-layouts/table/column-header-menu.tsx +152 -148
- package/src/dataviews-layouts/table/column-primary.tsx +7 -0
- package/src/dataviews-layouts/table/index.tsx +10 -0
- package/src/dataviews-layouts/table/style.scss +0 -1
- package/src/test/dataform.tsx +348 -0
- package/src/test/dataviews.tsx +380 -0
- package/src/types.ts +6 -0
- 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
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
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
|
|
|
@@ -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[]`
|
|
@@ -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.
|
|
@@ -185,21 +199,23 @@ Properties:
|
|
|
185
199
|
|
|
186
200
|
- `field`: the field used for sorting the dataset.
|
|
187
201
|
- `direction`: the direction to use for sorting, one of `asc` or `desc`.
|
|
202
|
+
|
|
188
203
|
- `titleField`: The id of the field representing the title of the record.
|
|
189
204
|
- `mediaField`: The id of the field representing the media of the record.
|
|
190
205
|
- `descriptionField`: The id of the field representing the description of the record.
|
|
191
206
|
- `showTitle`: Whether the title should be shown in the UI. `true` by default.
|
|
192
207
|
- `showMedia`: Whether the media should be shown in the UI. `true` by default.
|
|
193
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.
|
|
194
210
|
- `fields`: a list of remaining field `id` that are visible in the UI and the specific order in which they are displayed.
|
|
195
211
|
- `layout`: config that is specific to a particular layout type.
|
|
196
212
|
|
|
197
213
|
##### Properties of `layout`
|
|
198
214
|
|
|
199
|
-
| Properties of `layout`
|
|
200
|
-
|
|
|
201
|
-
| `badgeFields`: a list of field's `id` to render without label and styled as badges.
|
|
202
|
-
| `styles`: additional `width`, `maxWidth`, `minWidth` styles for each field column.
|
|
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. | ✓ | | |
|
|
203
219
|
|
|
204
220
|
#### `onChangeView`: `function`
|
|
205
221
|
|
|
@@ -302,8 +318,8 @@ const actions = [
|
|
|
302
318
|
RenderModal: ( { items, closeModal, onActionPerformed } ) => (
|
|
303
319
|
<div>
|
|
304
320
|
<p>Are you sure you want to delete { items.length } item(s)?</p>
|
|
305
|
-
<Button
|
|
306
|
-
variant="primary"
|
|
321
|
+
<Button
|
|
322
|
+
variant="primary"
|
|
307
323
|
onClick={() => {
|
|
308
324
|
console.log( 'Deleting items:', items );
|
|
309
325
|
onActionPerformed();
|
|
@@ -348,7 +364,7 @@ const defaultLayouts = {
|
|
|
348
364
|
},
|
|
349
365
|
grid: {
|
|
350
366
|
showMedia: true,
|
|
351
|
-
}
|
|
367
|
+
},
|
|
352
368
|
};
|
|
353
369
|
```
|
|
354
370
|
|
|
@@ -366,11 +382,11 @@ Callback that signals the user selected one of more items. It receives the list
|
|
|
366
382
|
|
|
367
383
|
If `selection` and `onChangeSelection` are provided, the `DataViews` component behaves like a controlled component. Otherwise, it behaves like an uncontrolled component.
|
|
368
384
|
|
|
369
|
-
|
|
385
|
+
#### `isItemClickable`: `function`
|
|
370
386
|
|
|
371
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.
|
|
372
388
|
|
|
373
|
-
|
|
389
|
+
#### `onClickItem`: `function`
|
|
374
390
|
|
|
375
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.
|
|
376
392
|
|
|
@@ -395,8 +411,8 @@ const Example = () => {
|
|
|
395
411
|
form={ form }
|
|
396
412
|
onChange={ onChange }
|
|
397
413
|
/>
|
|
398
|
-
)
|
|
399
|
-
}
|
|
414
|
+
);
|
|
415
|
+
};
|
|
400
416
|
```
|
|
401
417
|
|
|
402
418
|
### Properties
|
|
@@ -439,8 +455,30 @@ const fields = [
|
|
|
439
455
|
|
|
440
456
|
#### `form`: `Object[]`
|
|
441
457
|
|
|
442
|
-
-
|
|
443
|
-
-
|
|
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
|
+
```
|
|
444
482
|
|
|
445
483
|
#### `onChange`: `function`
|
|
446
484
|
|
|
@@ -471,10 +509,10 @@ const onChange = ( edits ) => {
|
|
|
471
509
|
|
|
472
510
|
return (
|
|
473
511
|
<DataForm
|
|
474
|
-
data={data}
|
|
475
|
-
fields={fields}
|
|
476
|
-
form={form}
|
|
477
|
-
onChange={onChange}
|
|
512
|
+
data={ data }
|
|
513
|
+
fields={ fields }
|
|
514
|
+
form={ form }
|
|
515
|
+
onChange={ onChange }
|
|
478
516
|
/>
|
|
479
517
|
);
|
|
480
518
|
```
|
|
@@ -487,16 +525,16 @@ Utility to apply the view config (filters, search, sorting, and pagination) to a
|
|
|
487
525
|
|
|
488
526
|
Parameters:
|
|
489
527
|
|
|
490
|
-
-
|
|
491
|
-
-
|
|
492
|
-
-
|
|
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.
|
|
493
531
|
|
|
494
532
|
Returns an object containing:
|
|
495
533
|
|
|
496
|
-
-
|
|
497
|
-
-
|
|
498
|
-
|
|
499
|
-
|
|
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.
|
|
500
538
|
|
|
501
539
|
### `isItemValid`
|
|
502
540
|
|
|
@@ -504,9 +542,9 @@ Utility is used to determine whether or not the given item's value is valid acco
|
|
|
504
542
|
|
|
505
543
|
Parameters:
|
|
506
544
|
|
|
507
|
-
-
|
|
508
|
-
-
|
|
509
|
-
-
|
|
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.
|
|
510
548
|
|
|
511
549
|
Returns a boolean indicating if the item is valid (true) or not (false).
|
|
512
550
|
|
|
@@ -516,17 +554,17 @@ Returns a boolean indicating if the item is valid (true) or not (false).
|
|
|
516
554
|
|
|
517
555
|
The unique identifier of the action.
|
|
518
556
|
|
|
519
|
-
-
|
|
520
|
-
-
|
|
521
|
-
-
|
|
557
|
+
- Type: `string`
|
|
558
|
+
- Required
|
|
559
|
+
- Example: `move-to-trash`
|
|
522
560
|
|
|
523
|
-
### `label`
|
|
561
|
+
### `label`
|
|
524
562
|
|
|
525
563
|
The user facing description of the action.
|
|
526
564
|
|
|
527
|
-
-
|
|
528
|
-
-
|
|
529
|
-
-
|
|
565
|
+
- Type: `string | function`
|
|
566
|
+
- Required
|
|
567
|
+
- Example:
|
|
530
568
|
|
|
531
569
|
```js
|
|
532
570
|
{
|
|
@@ -538,7 +576,7 @@ or
|
|
|
538
576
|
|
|
539
577
|
```js
|
|
540
578
|
{
|
|
541
|
-
label: ( items ) => items.length > 1 ? 'Delete items' : 'Delete item'
|
|
579
|
+
label: ( items ) => ( items.length > 1 ? 'Delete items' : 'Delete item' );
|
|
542
580
|
}
|
|
543
581
|
```
|
|
544
582
|
|
|
@@ -546,27 +584,27 @@ or
|
|
|
546
584
|
|
|
547
585
|
Whether the action should be displayed inline (primary) or only displayed in the "More actions" menu (secondary).
|
|
548
586
|
|
|
549
|
-
-
|
|
550
|
-
-
|
|
587
|
+
- Type: `boolean`
|
|
588
|
+
- Optional
|
|
551
589
|
|
|
552
590
|
### `icon`
|
|
553
591
|
|
|
554
592
|
Icon to show for primary actions.
|
|
555
593
|
|
|
556
|
-
-
|
|
557
|
-
-
|
|
594
|
+
- Type: SVG element
|
|
595
|
+
- Required for primary actions, optional for secondary actions.
|
|
558
596
|
|
|
559
597
|
### `isEligible`
|
|
560
598
|
|
|
561
599
|
Function that determines whether the action can be performed for a given record.
|
|
562
600
|
|
|
563
|
-
-
|
|
564
|
-
-
|
|
565
|
-
-
|
|
601
|
+
- Type: `function`
|
|
602
|
+
- Optional. If not present, action is considered eligible for all items.
|
|
603
|
+
- Example:
|
|
566
604
|
|
|
567
605
|
```js
|
|
568
606
|
{
|
|
569
|
-
isEligible: ( item ) => item.status === 'published'
|
|
607
|
+
isEligible: ( item ) => item.status === 'published';
|
|
570
608
|
}
|
|
571
609
|
```
|
|
572
610
|
|
|
@@ -574,47 +612,47 @@ Function that determines whether the action can be performed for a given record.
|
|
|
574
612
|
|
|
575
613
|
Whether the action can delete data, in which case the UI communicates it via a red color.
|
|
576
614
|
|
|
577
|
-
-
|
|
578
|
-
-
|
|
615
|
+
- Type: `boolean`
|
|
616
|
+
- Optional
|
|
579
617
|
|
|
580
618
|
### `supportsBulk`
|
|
581
619
|
|
|
582
620
|
Whether the action can operate over multiple items at once.
|
|
583
621
|
|
|
584
|
-
-
|
|
585
|
-
-
|
|
586
|
-
-
|
|
622
|
+
- Type: `boolean`
|
|
623
|
+
- Optional
|
|
624
|
+
- Default: `false`
|
|
587
625
|
|
|
588
626
|
### `disabled`
|
|
589
627
|
|
|
590
628
|
Whether the action is disabled.
|
|
591
629
|
|
|
592
|
-
-
|
|
593
|
-
-
|
|
594
|
-
-
|
|
630
|
+
- Type: `boolean`
|
|
631
|
+
- Optional
|
|
632
|
+
- Default: `false`
|
|
595
633
|
|
|
596
634
|
### `context`
|
|
597
635
|
|
|
598
636
|
Where this action would be visible.
|
|
599
637
|
|
|
600
|
-
-
|
|
601
|
-
-
|
|
602
|
-
-
|
|
638
|
+
- Type: `string`
|
|
639
|
+
- Optional
|
|
640
|
+
- One of: `list`, `single`
|
|
603
641
|
|
|
604
642
|
### `callback`
|
|
605
643
|
|
|
606
644
|
Function that performs the required action.
|
|
607
645
|
|
|
608
|
-
-
|
|
609
|
-
-
|
|
610
|
-
-
|
|
646
|
+
- Type: `function`
|
|
647
|
+
- Either `callback` or `RenderModal` must be provided. If `RenderModal` is provided, `callback` will be ignored
|
|
648
|
+
- Example:
|
|
611
649
|
|
|
612
650
|
```js
|
|
613
651
|
{
|
|
614
652
|
callback: ( items, { onActionPerformed } ) => {
|
|
615
653
|
// Perform action.
|
|
616
654
|
onActionPerformed?.( items );
|
|
617
|
-
}
|
|
655
|
+
};
|
|
618
656
|
}
|
|
619
657
|
```
|
|
620
658
|
|
|
@@ -622,9 +660,9 @@ Function that performs the required action.
|
|
|
622
660
|
|
|
623
661
|
Component to render UI in a modal for the action.
|
|
624
662
|
|
|
625
|
-
-
|
|
626
|
-
-
|
|
627
|
-
-
|
|
663
|
+
- Type: `ReactElement`
|
|
664
|
+
- Either `callback` or `RenderModal` must be provided. If `RenderModal` is provided, `callback` will be ignored.
|
|
665
|
+
- Example:
|
|
628
666
|
|
|
629
667
|
```jsx
|
|
630
668
|
{
|
|
@@ -648,7 +686,7 @@ Component to render UI in a modal for the action.
|
|
|
648
686
|
</HStack>
|
|
649
687
|
</form>
|
|
650
688
|
);
|
|
651
|
-
}
|
|
689
|
+
};
|
|
652
690
|
}
|
|
653
691
|
```
|
|
654
692
|
|
|
@@ -656,17 +694,16 @@ Component to render UI in a modal for the action.
|
|
|
656
694
|
|
|
657
695
|
Controls visibility of the modal's header when using `RenderModal`.
|
|
658
696
|
|
|
659
|
-
-
|
|
660
|
-
-
|
|
661
|
-
-
|
|
697
|
+
- Type: `boolean`
|
|
698
|
+
- Optional
|
|
699
|
+
- When false and using `RenderModal`, the action's label is used in modal header
|
|
662
700
|
|
|
663
701
|
### `modalHeader`
|
|
664
702
|
|
|
665
703
|
The header text to show in the modal.
|
|
666
704
|
|
|
667
|
-
-
|
|
668
|
-
-
|
|
669
|
-
|
|
705
|
+
- Type: `string`
|
|
706
|
+
- Optional
|
|
670
707
|
|
|
671
708
|
## Fields API
|
|
672
709
|
|
|
@@ -674,13 +711,15 @@ The header text to show in the modal.
|
|
|
674
711
|
|
|
675
712
|
The unique identifier of the field.
|
|
676
713
|
|
|
677
|
-
-
|
|
678
|
-
-
|
|
714
|
+
- Type: `string`.
|
|
715
|
+
- Required.
|
|
679
716
|
|
|
680
717
|
Example:
|
|
681
718
|
|
|
682
719
|
```js
|
|
683
|
-
{
|
|
720
|
+
{
|
|
721
|
+
id: 'field_id';
|
|
722
|
+
}
|
|
684
723
|
```
|
|
685
724
|
|
|
686
725
|
### `type`
|
|
@@ -689,44 +728,50 @@ Field type. One of `text`, `integer`, `datetime`.
|
|
|
689
728
|
|
|
690
729
|
If a field declares a `type`, it gets default implementations for the `sort`, `isValid`, and `Edit` functions if no other values are specified.
|
|
691
730
|
|
|
692
|
-
-
|
|
693
|
-
-
|
|
731
|
+
- Type: `string`.
|
|
732
|
+
- Optional.
|
|
694
733
|
|
|
695
734
|
Example:
|
|
696
735
|
|
|
697
736
|
```js
|
|
698
|
-
{
|
|
737
|
+
{
|
|
738
|
+
type: 'text';
|
|
739
|
+
}
|
|
699
740
|
```
|
|
700
741
|
|
|
701
742
|
### `label`
|
|
702
743
|
|
|
703
744
|
The field's name. This will be used across the UI.
|
|
704
745
|
|
|
705
|
-
-
|
|
706
|
-
-
|
|
707
|
-
-
|
|
746
|
+
- Type: `string`.
|
|
747
|
+
- Optional.
|
|
748
|
+
- Defaults to the `id` value.
|
|
708
749
|
|
|
709
750
|
Example:
|
|
710
751
|
|
|
711
752
|
```js
|
|
712
|
-
{
|
|
753
|
+
{
|
|
754
|
+
label: 'Title';
|
|
755
|
+
}
|
|
713
756
|
```
|
|
714
757
|
|
|
715
758
|
### `header`
|
|
716
759
|
|
|
717
760
|
React component used by the layouts to display the field name — useful to add icons, etc. It's complementary to the `label` property.
|
|
718
761
|
|
|
719
|
-
-
|
|
720
|
-
-
|
|
721
|
-
-
|
|
722
|
-
-
|
|
723
|
-
-
|
|
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.
|
|
724
767
|
|
|
725
768
|
Example:
|
|
726
769
|
|
|
727
770
|
```js
|
|
728
771
|
{
|
|
729
|
-
header: () => {
|
|
772
|
+
header: () => {
|
|
773
|
+
/* Returns a react element. */
|
|
774
|
+
};
|
|
730
775
|
}
|
|
731
776
|
```
|
|
732
777
|
|
|
@@ -734,18 +779,20 @@ Example:
|
|
|
734
779
|
|
|
735
780
|
React component that returns the value of a field. This value is used to sort or filter the fields.
|
|
736
781
|
|
|
737
|
-
-
|
|
738
|
-
-
|
|
739
|
-
-
|
|
740
|
-
-
|
|
741
|
-
|
|
742
|
-
-
|
|
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.
|
|
743
788
|
|
|
744
789
|
Example:
|
|
745
790
|
|
|
746
791
|
```js
|
|
747
792
|
{
|
|
748
|
-
getValue: ( { item } ) => {
|
|
793
|
+
getValue: ( { item } ) => {
|
|
794
|
+
/* The field's value. */
|
|
795
|
+
};
|
|
749
796
|
}
|
|
750
797
|
```
|
|
751
798
|
|
|
@@ -753,18 +800,20 @@ Example:
|
|
|
753
800
|
|
|
754
801
|
React component that renders the field. This is used by the layouts.
|
|
755
802
|
|
|
756
|
-
-
|
|
757
|
-
-
|
|
758
|
-
-
|
|
759
|
-
-
|
|
760
|
-
|
|
761
|
-
-
|
|
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.
|
|
762
809
|
|
|
763
810
|
Example:
|
|
764
811
|
|
|
765
812
|
```js
|
|
766
813
|
{
|
|
767
|
-
render: ( { item} ) => {
|
|
814
|
+
render: ( { item } ) => {
|
|
815
|
+
/* React element to be displayed. */
|
|
816
|
+
};
|
|
768
817
|
}
|
|
769
818
|
```
|
|
770
819
|
|
|
@@ -772,26 +821,21 @@ Example:
|
|
|
772
821
|
|
|
773
822
|
React component that renders the control to edit the field.
|
|
774
823
|
|
|
775
|
-
-
|
|
776
|
-
-
|
|
777
|
-
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
-
|
|
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.
|
|
783
832
|
|
|
784
833
|
Example:
|
|
785
834
|
|
|
786
835
|
```js
|
|
787
836
|
// A custom control defined by the field.
|
|
788
837
|
{
|
|
789
|
-
Edit: ( {
|
|
790
|
-
data,
|
|
791
|
-
field,
|
|
792
|
-
onChange,
|
|
793
|
-
hideLabelFromVision
|
|
794
|
-
} ) => {
|
|
838
|
+
Edit: ( { data, field, onChange, hideLabelFromVision } ) => {
|
|
795
839
|
const value = field.getValue( { item: data } );
|
|
796
840
|
|
|
797
841
|
return (
|
|
@@ -801,14 +845,14 @@ Example:
|
|
|
801
845
|
hideLabelFromVision
|
|
802
846
|
/>
|
|
803
847
|
);
|
|
804
|
-
}
|
|
848
|
+
};
|
|
805
849
|
}
|
|
806
850
|
```
|
|
807
851
|
|
|
808
852
|
```js
|
|
809
853
|
// Use one of the core controls.
|
|
810
854
|
{
|
|
811
|
-
Edit: 'radio'
|
|
855
|
+
Edit: 'radio';
|
|
812
856
|
}
|
|
813
857
|
```
|
|
814
858
|
|
|
@@ -816,7 +860,7 @@ Example:
|
|
|
816
860
|
// Edit is optional when field's type is present.
|
|
817
861
|
// The field will use the default Edit function for text.
|
|
818
862
|
{
|
|
819
|
-
type: 'text'
|
|
863
|
+
type: 'text';
|
|
820
864
|
}
|
|
821
865
|
```
|
|
822
866
|
|
|
@@ -833,16 +877,16 @@ Example:
|
|
|
833
877
|
|
|
834
878
|
Function to sort the records.
|
|
835
879
|
|
|
836
|
-
-
|
|
837
|
-
-
|
|
838
|
-
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
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
|
|
846
890
|
|
|
847
891
|
Example:
|
|
848
892
|
|
|
@@ -853,7 +897,7 @@ Example:
|
|
|
853
897
|
return direction === 'asc'
|
|
854
898
|
? a.localeCompare( b )
|
|
855
899
|
: b.localeCompare( a );
|
|
856
|
-
}
|
|
900
|
+
};
|
|
857
901
|
}
|
|
858
902
|
```
|
|
859
903
|
|
|
@@ -861,7 +905,7 @@ Example:
|
|
|
861
905
|
// If field type is provided,
|
|
862
906
|
// the field gets a default sort function.
|
|
863
907
|
{
|
|
864
|
-
type: 'number'
|
|
908
|
+
type: 'number';
|
|
865
909
|
}
|
|
866
910
|
```
|
|
867
911
|
|
|
@@ -869,8 +913,10 @@ Example:
|
|
|
869
913
|
// Even if a field type is provided,
|
|
870
914
|
// fields can override the default sort function assigned for that type.
|
|
871
915
|
{
|
|
872
|
-
type: 'number'
|
|
873
|
-
sort: ( a, b, direction ) => {
|
|
916
|
+
type: 'number';
|
|
917
|
+
sort: ( a, b, direction ) => {
|
|
918
|
+
/* Custom sort */
|
|
919
|
+
};
|
|
874
920
|
}
|
|
875
921
|
```
|
|
876
922
|
|
|
@@ -878,13 +924,13 @@ Example:
|
|
|
878
924
|
|
|
879
925
|
Function to validate a field's value.
|
|
880
926
|
|
|
881
|
-
-
|
|
882
|
-
-
|
|
883
|
-
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
-
|
|
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.
|
|
888
934
|
|
|
889
935
|
Example:
|
|
890
936
|
|
|
@@ -893,7 +939,7 @@ Example:
|
|
|
893
939
|
{
|
|
894
940
|
isValid: ( item, context ) => {
|
|
895
941
|
return !! item;
|
|
896
|
-
}
|
|
942
|
+
};
|
|
897
943
|
}
|
|
898
944
|
```
|
|
899
945
|
|
|
@@ -918,18 +964,20 @@ Example:
|
|
|
918
964
|
|
|
919
965
|
Function that indicates if the field should be visible.
|
|
920
966
|
|
|
921
|
-
-
|
|
922
|
-
-
|
|
923
|
-
-
|
|
924
|
-
|
|
925
|
-
-
|
|
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`).
|
|
926
972
|
|
|
927
973
|
Example:
|
|
928
974
|
|
|
929
975
|
```js
|
|
930
976
|
// Custom isVisible function.
|
|
931
977
|
{
|
|
932
|
-
isVisible: ( item ) => {
|
|
978
|
+
isVisible: ( item ) => {
|
|
979
|
+
/* Custom implementation. */
|
|
980
|
+
};
|
|
933
981
|
}
|
|
934
982
|
```
|
|
935
983
|
|
|
@@ -937,54 +985,60 @@ Example:
|
|
|
937
985
|
|
|
938
986
|
Boolean indicating if the field is sortable.
|
|
939
987
|
|
|
940
|
-
-
|
|
941
|
-
-
|
|
942
|
-
-
|
|
988
|
+
- Type: `boolean`.
|
|
989
|
+
- Optional.
|
|
990
|
+
- Defaults to `true`.
|
|
943
991
|
|
|
944
992
|
Example:
|
|
945
993
|
|
|
946
994
|
```js
|
|
947
|
-
{
|
|
995
|
+
{
|
|
996
|
+
enableSorting: true;
|
|
997
|
+
}
|
|
948
998
|
```
|
|
949
999
|
|
|
950
1000
|
### `enableHiding`
|
|
951
1001
|
|
|
952
1002
|
Boolean indicating if the field can be hidden.
|
|
953
1003
|
|
|
954
|
-
-
|
|
955
|
-
-
|
|
956
|
-
-
|
|
1004
|
+
- Type: `boolean`.
|
|
1005
|
+
- Optional.
|
|
1006
|
+
- Defaults to `true`.
|
|
957
1007
|
|
|
958
1008
|
Example:
|
|
959
1009
|
|
|
960
1010
|
```js
|
|
961
|
-
{
|
|
1011
|
+
{
|
|
1012
|
+
enableHiding: true;
|
|
1013
|
+
}
|
|
962
1014
|
```
|
|
963
1015
|
|
|
964
1016
|
### `enableGlobalSearch`
|
|
965
1017
|
|
|
966
1018
|
Boolean indicating if the field is searchable.
|
|
967
1019
|
|
|
968
|
-
-
|
|
969
|
-
-
|
|
970
|
-
-
|
|
1020
|
+
- Type: `boolean`.
|
|
1021
|
+
- Optional.
|
|
1022
|
+
- Defaults to `false`.
|
|
971
1023
|
|
|
972
1024
|
Example:
|
|
973
1025
|
|
|
974
1026
|
```js
|
|
975
|
-
{
|
|
1027
|
+
{
|
|
1028
|
+
enableGlobalSearch: true;
|
|
1029
|
+
}
|
|
976
1030
|
```
|
|
977
1031
|
|
|
978
1032
|
### `elements`
|
|
979
1033
|
|
|
980
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.)
|
|
981
1035
|
|
|
982
|
-
-
|
|
983
|
-
-
|
|
984
|
-
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
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.
|
|
988
1042
|
|
|
989
1043
|
Example:
|
|
990
1044
|
|
|
@@ -995,7 +1049,7 @@ Example:
|
|
|
995
1049
|
{ value: '2', label: 'Product B' },
|
|
996
1050
|
{ value: '3', label: 'Product C' },
|
|
997
1051
|
{ value: '4', label: 'Product D' },
|
|
998
|
-
]
|
|
1052
|
+
];
|
|
999
1053
|
}
|
|
1000
1054
|
```
|
|
1001
1055
|
|
|
@@ -1003,11 +1057,11 @@ Example:
|
|
|
1003
1057
|
|
|
1004
1058
|
Configuration of the filters.
|
|
1005
1059
|
|
|
1006
|
-
-
|
|
1007
|
-
-
|
|
1008
|
-
-
|
|
1009
|
-
|
|
1010
|
-
|
|
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.
|
|
1011
1065
|
|
|
1012
1066
|
Operators:
|
|
1013
1067
|
|
|
@@ -1028,7 +1082,7 @@ Example:
|
|
|
1028
1082
|
// Set a filter as primary.
|
|
1029
1083
|
{
|
|
1030
1084
|
filterBy: {
|
|
1031
|
-
isPrimary: true
|
|
1085
|
+
isPrimary: true;
|
|
1032
1086
|
}
|
|
1033
1087
|
}
|
|
1034
1088
|
```
|
|
@@ -1037,7 +1091,7 @@ Example:
|
|
|
1037
1091
|
// Configure a filter as single-selection.
|
|
1038
1092
|
{
|
|
1039
1093
|
filterBy: {
|
|
1040
|
-
operators: [ `is`, `isNot` ]
|
|
1094
|
+
operators: [ `is`, `isNot` ];
|
|
1041
1095
|
}
|
|
1042
1096
|
}
|
|
1043
1097
|
```
|
|
@@ -1046,11 +1100,91 @@ Example:
|
|
|
1046
1100
|
// Configure a filter as multi-selection with all the options.
|
|
1047
1101
|
{
|
|
1048
1102
|
filterBy: {
|
|
1049
|
-
operators: [ `isAny`, `isNone`, `isAll`, `isNotAll` ]
|
|
1103
|
+
operators: [ `isAny`, `isNone`, `isAll`, `isNotAll` ];
|
|
1050
1104
|
}
|
|
1051
1105
|
}
|
|
1052
1106
|
```
|
|
1053
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
|
+
|
|
1054
1188
|
## Contributing to this package
|
|
1055
1189
|
|
|
1056
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.
|