Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a5c00fe
Initial implementation
straku Sep 11, 2025
e0ce670
TEMP: Change fixtures to use nested data
straku Sep 11, 2025
6430200
Temp: Add story with nested data for DataForm
straku Sep 12, 2025
423d60e
Change approach to typing an item and update usage
straku Sep 12, 2025
3153f67
Fix tests
straku Sep 12, 2025
898024a
Add setValue to boolean field in the stories
straku Sep 12, 2025
4fdb8de
Allow `DeepPartial< Item >` to accept full `Item`
straku Sep 12, 2025
508f710
Rely on `DeepPartial` in `setValue`
straku Sep 12, 2025
1e15efe
Disable validation in filter controls
straku Sep 12, 2025
d1e45c8
Filters: prepare data and field
oandregal Sep 12, 2025
3e0c027
Update custom Edit to match the DeepPartial shape of onChange
oandregal Sep 12, 2025
2070e12
Use Item instead of DeepPartial<Item> as parameter to getValue and se…
oandregal Sep 12, 2025
d3467a3
Fix modal with nested data
oandregal Sep 12, 2025
cb4cdcd
Update story and fix the DeepPartial type definition.
oandregal Sep 12, 2025
e761011
Port new tests to existing test file
oandregal Sep 12, 2025
af025fb
Revert changes to fields
oandregal Sep 12, 2025
9f33dbe
Adapt new places after rebase
oandregal Sep 12, 2025
ed9a157
Fix author field in DataForm story
straku Sep 15, 2025
05fc231
Remove unused import, finer scope for useCallback dependencies
straku Sep 15, 2025
2bf7cb0
Add comment for DeepPartial type
straku Sep 15, 2025
6ffd2ec
Doc changes
straku Sep 15, 2025
684463a
Use setValue for custom validation functions item argument
straku Sep 15, 2025
a26aebd
Update readme after validation changes
straku Sep 15, 2025
ad84488
Story: return partial, not item
oandregal Sep 16, 2025
f848c91
Do not make password required in a custom rule
oandregal Sep 16, 2025
661c3f0
Filters: setValue should return a partial
oandregal Sep 16, 2025
6e1cfa7
Revert "Update readme after validation changes"
straku Sep 16, 2025
eb9be76
Use full item for custom validation functions
straku Sep 16, 2025
c69e9d2
Fix wrong conflict resolution
straku Sep 16, 2025
131bc7e
Fix onChange for date related controls
straku Sep 16, 2025
ed0226e
Improve internal types used in date control: DateRange
oandregal Sep 16, 2025
8c15df5
Improve internal types used in Date control: DateRelative
oandregal Sep 16, 2025
ad9aed6
Datetime: fix relative filter
oandregal Sep 16, 2025
5d332a3
Integer control: improve internal types and checks
oandregal Sep 16, 2025
1f7b912
ToggleControl: fix validation
oandregal Sep 16, 2025
28fc311
Add changelog entry
oandregal Sep 16, 2025
bfa4bdc
DataForm panel: fix modal (changes accumulate)
oandregal Sep 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Features

- Field API: introduce `setValue` to fix DataViews filters and DataForm panel layout (modal) when working with nested data. [#71604](https://github.com/WordPress/gutenberg/pull/71604)
- Introduce a new `DataViewsPicker` component. [#70971](https://github.com/WordPress/gutenberg/pull/70971)
- Dataform: Add new `telephone` field type and field control. [#71498](https://github.com/WordPress/gutenberg/pull/71498)
- DataForm: introduce a new `row` layout, check the README for details. [#71124](https://github.com/WordPress/gutenberg/pull/71124)
Expand Down
117 changes: 106 additions & 11 deletions packages/dataviews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -989,24 +989,119 @@ Example:
}
```

### `getValue`
### `getValue` and `setValue`

React component that returns the value of a field. This value is used to sort or filter the fields.
These functions control how field values are read from and written to your data structure.

- Type: React component.
Both functions are optional and automatically generated from the field's `id` when not provided. The `id` is treated as a dot-notation path (e.g., `"user.profile.name"` accesses `item.user.profile.name`).

#### `getValue`

Function that extracts the field value from an item. This value is used to sort, filter, and display the field.

- Type: `function`.
- Optional.
- Defaults to `item[ id ]`.
- Props:
- `item` value to be processed.
- Returns a value that represents the field.
- Args:
- `item`: the data item to be processed.
- Returns the field's value.

Example:
#### `setValue`

Function that creates a partial item object with updated field values. This is used by DataForm for editing operations and determines the structure of data passed to the `onChange` callback.

- Type: `function`.
- Optional.
- Args:
- `item`: the current item being edited.
- `value`: the new value to be set for the field.
- Returns a partial item object with the changes to be applied.

#### Simple field access

For basic field access, you only need to specify the field `id`. Both `getValue` and `setValue` are automatically generated:

```js
// Data structure
const item = {
title: 'Hello World',
author: 'John Doe'
};

// Field definition
{
getValue: ( { item } ) => {
/* The field's value. */
};
id: 'title',
label: 'Title'
// getValue: automatically becomes ( { item } ) => item.title
// setValue: automatically becomes ( { value } ) => ( { title: value } )
}
```

#### Nested data access

Use dot notation in the field `id` to access nested properties:

```js
// Data structure
const item = {
user: {
profile: {
name: 'John Doe',
email: '[email protected]'
}
}
};

// Field definition - using dot notation (automatic)
{
id: 'user.profile.name',
label: 'User Name'
// getValue: automatically becomes ( { item } ) => item.user.profile.name
// setValue: automatically becomes ( { value } ) => ( { user: { profile: { name: value } } } )
}

// Alternative - using simple ID with custom functions
{
id: 'userName',
label: 'User Name',
getValue: ( { item } ) => item.user.profile.name,
setValue: ( { value } ) => ( {
user: {
profile: { name: value }
}
} )
}
```

#### Custom data transformation

Provide custom `getValue` and `setValue` functions when you need to transform data between the storage format and display format:

```js
// Data structure
const item = {
user: {
preferences: {
notifications: true
}
}
};

// Field definition - transform boolean to string options
{
id: 'notifications',
label: 'Notifications',
Edit: 'radio',
elements: [
{ label: 'Enabled', value: 'enabled' },
{ label: 'Disabled', value: 'disabled' }
],
getValue: ( { item } ) =>
item.user.preferences.notifications === true ? 'enabled' : 'disabled',
setValue: ( { value } ) => ( {
user: {
preferences: { notifications: value === 'enabled' }
}
} )
}
```

Expand Down
1 change: 1 addition & 0 deletions packages/dataviews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"clsx": "^2.1.1",
"colord": "^2.7.0",
"date-fns": "^4.1.0",
"deepmerge": "4.3.1",
"fast-deep-equal": "^3.1.3",
"remove-accents": "^0.5.0"
},
Expand Down
Loading
Loading