Repository navigation
Update README for DataViews, DataForm, Field API #75881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0a7ed8b
Document missing isValid values
oandregal 55d7336
Document validity
oandregal d226692
Document format prop for datetime fields
oandregal 1ef0842
Document density for list layout
oandregal 3623c07
Update view object docs
oandregal 815f4b5
Document DataForm details layout
oandregal 42f4b9d
Add missing row styles and form field description
oandregal 87b49ae
Document missing props for Edit
oandregal 9dd5963
Update last bits
oandregal f459d37
Update changelog
oandregal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,7 +207,7 @@ const view = { | |
|
|
||
| Properties: | ||
|
|
||
| - `type`: view type, one of `table`, `grid`, `list`. See "Layout types". | ||
| - `type`: view type, one of `table`, `grid`, `list`, `activity`, `pickerTable`, `pickerGrid`. See "Layout types". | ||
| - `search`: the text search applied to the dataset. | ||
| - `filters`: the filters applied to the dataset. Each item describes: | ||
| - `field`: which field this filter is bound to. | ||
|
|
@@ -230,15 +230,17 @@ Properties: | |
|
|
||
| - `field`: the field used for grouping the dataset. | ||
| - `direction`: the direction to use for sorting the groups, one of `asc` or `desc`. Default `asc`. | ||
| - `showLabel`: whether to show the field label in the group header. `true` by default. | ||
|
|
||
| - `infiniteScrollEnabled`: whether infinite scroll is enabled. `false` by default. | ||
| - `fields`: a list of remaining field `id` that are visible in the UI and the specific order in which they are displayed. | ||
| - `layout`: config that is specific to a particular layout type. | ||
|
|
||
| ##### Properties of `layout` | ||
|
|
||
| | Props / Layout | `table` | `pickerTable` | `grid` | `pickerGrid` | `list` | `activity` | | ||
| | -------------- | ------- | ------------- | ------ | ------------ | ------ | ---------- | | ||
| | `density` | ✓ | ✓ | | | | ✓ | | ||
| | `density` | ✓ | ✓ | | | ✓ | ✓ | | ||
| | `enableMoving` | ✓ | ✓ | | | | | | ||
| | `styles` | ✓ | ✓ | | | | | | ||
| | `badgeFields` | | | ✓ | ✓ | | | | ||
|
|
@@ -248,10 +250,10 @@ Properties: | |
|
|
||
| - `density`: one of `comfortable`, `balanced`, or `compact`. Configures the size and spacing of the layout. | ||
| - `enableMoving`: whether the table columns should display moving controls. | ||
| - `styles`: additional `width`, `maxWidth`, `minWidth`, `align` styles for each field column. | ||
| - `styles`: additional `width`, `maxWidth`, `minWidth`, `align` styles for each field column. The `align` property accepts `'start'`, `'center'`, or `'end'`. | ||
|
|
||
| **For column alignment (`align` property), follow these guidelines:** | ||
| Right-align whenever the cell value is fundamentally quantitative—numbers, decimals, currency, percentages—so that digits and decimal points line up, aiding comparison and calculation. Otherwise, default to left-alignment for all other types (text, codes, labels, dates). | ||
| Right-align (`'end'`) whenever the cell value is fundamentally quantitative—numbers, decimals, currency, percentages—so that digits and decimal points line up, aiding comparison and calculation. Otherwise, default to left-alignment (`'start'`) for all other types (text, codes, labels, dates). | ||
|
|
||
| `grid` and `pickerGrid` layout: | ||
|
|
||
|
|
@@ -260,7 +262,7 @@ Right-align whenever the cell value is fundamentally quantitative—numbers, dec | |
|
|
||
| `list` layout: | ||
|
|
||
| - None | ||
| - `density`: one of `comfortable`, `balanced`, or `compact`. Configures the size and spacing of the layout. | ||
|
|
||
| `activity` layout: | ||
|
|
||
|
|
@@ -400,7 +402,7 @@ What text to show in the search input. "Search" by default. | |
|
|
||
| Whether the data is loading. `false` by default. | ||
|
|
||
| #### `defaultLayouts`: `Record< string, view >` | ||
| #### `defaultLayouts`: `Object` | ||
|
|
||
| This property limits the available layout and provides layout information about active view types. If empty, this enables all layout types (see "Layout Types") with empty layout data. | ||
|
|
||
|
|
@@ -417,7 +419,7 @@ const defaultLayouts = { | |
| }; | ||
| ``` | ||
|
|
||
| The `defaultLayouts` property should be an object that includes properties named `table`, `grid`, `list`, and `activity`. These properties are applied to the view object each time the user switches to the corresponding layout. | ||
| The `defaultLayouts` property should be an object that includes properties named `table`, `grid`, `list`, `activity`, `pickerTable`, and `pickerGrid`. These properties are applied to the view object each time the user switches to the corresponding layout. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly with my above comment, we should probably not include the picker layouts here, right? |
||
|
|
||
| #### `selection`: `string[]` | ||
|
|
||
|
|
@@ -823,7 +825,7 @@ const fields = [ | |
| ]; | ||
| ``` | ||
|
|
||
| #### `form`: `Object[]` | ||
| #### `form`: `Object` | ||
|
|
||
| - `layout`: an object describing the layout used to render the top-level fields present in `fields`. See `layout` prop in "Form Field API". | ||
| - `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. | ||
|
|
@@ -893,7 +895,9 @@ return ( | |
|
|
||
| Object that determines the validation status of each field. There's a `useFormValidity` hook that can be used to create the validity object — see the utility below. This section documents the `validity` object in case you want to create it via other means. | ||
|
|
||
| The top-level props of the `validity` object are the field IDs. Fields declare their validity status for each of the validation rules supported: `required`, `elements`, `custom`. If a rule is valid, it should not be present in the object; if a field is valid for all the rules, it should not be present in the object either. | ||
| The top-level props of the `validity` object are the field IDs. Fields declare their validity status for each of the validation rules supported: `required`, `elements`, `pattern`, `minLength`, `maxLength`, `min`, `max`, `custom`. If a rule is valid, it should not be present in the object; if a field is valid for all the rules, it should not be present in the object either. | ||
|
|
||
| A field's validity can also contain a `children` property (`Record<string, FieldValidity>`) for nested field validity when using combined fields. | ||
|
|
||
| For example: | ||
|
|
||
|
|
@@ -910,6 +914,32 @@ For example: | |
| "message": "Value must be one of the elements." | ||
| } | ||
| }, | ||
| "slug": { | ||
| "pattern": { | ||
| "type": "invalid", | ||
| "message": "Must match the required pattern." | ||
| } | ||
| }, | ||
| "description": { | ||
| "minLength": { | ||
| "type": "invalid", | ||
| "message": "Must be at least 10 characters." | ||
| }, | ||
| "maxLength": { | ||
| "type": "invalid", | ||
| "message": "Must be at most 200 characters." | ||
| } | ||
| }, | ||
| "price": { | ||
| "min": { | ||
| "type": "invalid", | ||
| "message": "Must be at least 0." | ||
| }, | ||
| "max": { | ||
| "type": "invalid", | ||
| "message": "Must be at most 9999." | ||
| } | ||
| }, | ||
| "publisher": { | ||
| "custom": { | ||
| "type": "validating", | ||
|
|
@@ -982,6 +1012,26 @@ Returns an object containing: | |
| type: 'invalid', | ||
| message: 'Value must be one of the elements.' // Optional | ||
| }, | ||
| pattern: { | ||
| type: 'invalid', | ||
| message: 'Must match the required pattern.' | ||
| }, | ||
| minLength: { | ||
| type: 'invalid', | ||
| message: 'Must be at least 10 characters.' | ||
| }, | ||
| maxLength: { | ||
| type: 'invalid', | ||
| message: 'Must be at most 200 characters.' | ||
| }, | ||
| min: { | ||
| type: 'invalid', | ||
| message: 'Must be at least 0.' | ||
| }, | ||
| max: { | ||
| type: 'invalid', | ||
| message: 'Must be at most 9999.' | ||
| }, | ||
| custom: { | ||
| type: 'validating', | ||
| message: 'Validating...' | ||
|
|
@@ -1084,7 +1134,7 @@ Function that performs the required action. | |
|
|
||
| ```js | ||
| { | ||
| callback: ( items, { onActionPerformed } ) => { | ||
| callback: ( items, { registry, onActionPerformed } ) => { | ||
| // Perform action. | ||
| onActionPerformed?.( items ); | ||
| }; | ||
|
|
@@ -1231,7 +1281,7 @@ Example: | |
|
|
||
| React element used by some layouts (table, grid) to display the field name — useful to add icons, etc. | ||
|
|
||
| - Type: React element. | ||
| - Type: `string` | React element. | ||
| - Optional. | ||
| - Defaults to the `label` value. | ||
|
|
||
|
|
@@ -1533,6 +1583,8 @@ Finally, the field author can always provide its own custom `Edit` control. It r | |
| - `field`: the field definition | ||
| - `onChange`: the callback with the updates | ||
| - `hideLabelFromVision`: boolean representing if the label should be hidden | ||
| - `markWhenOptional`: boolean indicating whether to label the control as "optional" when the field is not required, instead of showing "required" | ||
| - `operator`: the currently selected filter operator for this field. Used by DataViews filters to determine which control to render based on the operator type | ||
| - `validity`: object representing the validity of the field's value (see validity section) | ||
| - `config`: object representing extra config for the component: | ||
| - `prefix`: a React component to be rendered as a prefix | ||
|
|
@@ -1621,6 +1673,11 @@ Object that contains the validation rules for the field. If a rule is not met, t | |
|
|
||
| - `required`: boolean indicating whether the field is required or not. Disabled by default. | ||
| - `elements`: boolean restricting selection to the provided list of elements only. Enabled by default. The `array` Edit control uses it to restrict the input values. | ||
| - `pattern`: a regex pattern string that the field value must match. | ||
| - `minLength`: minimum string length for the field value. | ||
| - `maxLength`: maximum string length for the field value. | ||
| - `min`: minimum numeric value for the field. | ||
| - `max`: maximum numeric value for the field. | ||
| - `custom`: a function that validates a field's value. If the value is invalid, the function should return a string explaining why the value is invalid. Otherwise, the function must return null. | ||
|
|
||
| Fields that define a type come with default validation for the type. For example, the `integer` type ensures that the value is a valid integer: | ||
|
|
@@ -1952,11 +2009,30 @@ Valid operators per field type: | |
|
|
||
| ### `format` | ||
|
|
||
| Display format configuration for fields. Supported for date, number, and integer fields. This configuration affects how the field is displayed in the `render` method, the `Edit` control, and filter controls. | ||
| Display format configuration for fields. Supported for `datetime`, `date`, `number`, and `integer` fields. This configuration affects how the field is displayed in the `render` method, the `Edit` control, and filter controls. | ||
|
|
||
| - Type: `object`. | ||
| - Optional. | ||
|
|
||
| For `datetime` fields: | ||
| - Properties: | ||
| - `datetime`: The format string using PHP date format (e.g., `'M j, Y g:i a'` for `'Jan 1, 2021 2:30 pm'`). Optional, defaults to WordPress date format settings. | ||
| - `weekStartsOn`: Specifies the first day of the week for calendar controls. One of 0, 1, 2, 3, 4, 5, 6. Optional, defaults to WordPress "Week Starts On" setting, whose value is 0 (Sunday). | ||
|
|
||
| Example: | ||
|
|
||
| ```js | ||
| { | ||
| id: 'createdAt', | ||
| type: 'datetime', | ||
| label: 'Created At', | ||
| format: { | ||
| datetime: 'M j, Y g:i a', | ||
| weekStartsOn: 1, | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| For `date` fields: | ||
| - Properties: | ||
| - `date`: The format string using PHP date format (e.g., 'F j, Y' for 'March 10, 2023'). Optional, defaults to WordPress "Date Format" setting. | ||
|
|
@@ -2035,7 +2111,7 @@ Example: | |
|
|
||
| ### `layout` | ||
|
|
||
| Represents the type of layout used to render the field. It'll be one of Regular, Panel, Card, or Row. This prop is the same as the `form.layout` prop. | ||
| Represents the type of layout used to render the field. It'll be one of Regular, Panel, Card, Row, or Details. This prop is the same as the `form.layout` prop. | ||
|
|
||
| #### Regular | ||
|
|
||
|
|
@@ -2116,6 +2192,7 @@ For example: | |
|
|
||
| - `type`: `row`. Required. | ||
| - `alignment`: one of `start`, `center`, or `end`. Optional. `center` by default. | ||
| - `styles`: an object mapping field IDs to style objects. Each style object supports a `flex` property (any valid CSS `flex` value) to control how the field sizes within the row. Optional. | ||
|
|
||
| The Row layout displays fields horizontally in a single row. It's particularly useful for grouping related fields that should be displayed side by side. This layout can be used both as a top-level form layout and for individual field groups. | ||
|
|
||
|
|
@@ -2126,7 +2203,30 @@ For example: | |
| id: 'field_id', | ||
| layout: { | ||
| type: 'row', | ||
| alignment: 'start' | ||
| alignment: 'start', | ||
| styles: { | ||
| field1: { flex: '1 1 auto' }, | ||
| field2: { flex: '0 0 200px' }, | ||
| }, | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| #### Details | ||
|
|
||
| - `type`: `details`. Required. | ||
| - `summary`: Summary field configuration. Optional. Specifies which field to display in the details summary. A string (single field ID) | ||
|
|
||
| The Details layout renders the field inside a collapsible `<details>` HTML element. The `summary` property controls the text shown in the disclosure summary. | ||
|
|
||
| For example: | ||
|
|
||
| ```js | ||
| { | ||
| id: 'field_id', | ||
| layout: { | ||
| type: 'details', | ||
| summary: 'summaryFieldId' | ||
| }, | ||
| } | ||
| ``` | ||
|
|
@@ -2147,6 +2247,24 @@ Example: | |
| } | ||
| ``` | ||
|
|
||
| ### `description` | ||
|
|
||
| A string describing the form field's purpose or usage. Used to provide additional context. | ||
|
|
||
| - Type: `string`. | ||
| - Optional. | ||
|
|
||
| Example: | ||
|
|
||
| ```js | ||
| { | ||
| id: 'field_id', | ||
| label: 'Status & Visibility', | ||
| description: 'Control the publish status and visibility of the post.', | ||
| children: [ 'status', 'password' ], | ||
| } | ||
| ``` | ||
|
|
||
| ### `children` | ||
|
|
||
| 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 ). | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we just add
activityhere since the the picker layouts work only for DataViewsPicker?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The view object here is documented for the two components and there's pre-existing mentions in the documentation as well (see layout table). I agree with you we need a better differentiation and this needs to be looked at.