Skip to content

Fix: Support setValue in fields to handle nested data updates in DataViews filters and forms #70989

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

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

Jeelislive
Copy link

fixes an issue where user-input filters and edit forms in DataViews didn’t work correctly for fields that use nested values with a getValue function (e.g., title.raw).

What’s changed:

  • Added support for an optional setValue function in field definitions.
  • Updated filters and form logic to use setValue when provided.
  • Ensures proper data shape when filtering or editing nested field values.

This keeps field logic (get/set) inside the field definition and avoids breaking data formats.

Fixes #70957

@Jeelislive Jeelislive requested a review from oandregal as a code owner July 30, 2025 17:18
Copy link

github-actions bot commented Jul 30, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Jeelislive.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: Jeelislive.

Co-authored-by: oandregal <[email protected]>
Co-authored-by: chihsuan <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jul 30, 2025
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Jeelislive! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@Jeelislive Jeelislive closed this Jul 30, 2025
@Jeelislive Jeelislive reopened this Jul 30, 2025
@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews labels Jul 31, 2025
@@ -138,7 +147,7 @@ export default function FormRegularField< Item >( {
<fieldDefinition.Edit
data={ data }
field={ fieldDefinition }
onChange={ onChange }
onChange={ handleFieldChange }
Copy link
Member

@oandregal oandregal Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of handling this at the layout-level, it should be handled at the Edit (controls) level. For example, in this control. Fields can provide a custom Edit function (control) and when they do so it's their responsibility to implement this.

@@ -15,6 +15,10 @@ import type { useFocusOnMount } from '@wordpress/compose';

export type SortDirection = 'asc' | 'desc';

/**
Copy link
Member

@oandregal oandregal Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this comment for?

* Callback used to set the value of the field in the item.
* Defaults to `{ ...item, [field.id]: value }`.
*/
setValue?: ( args: { item: Item; value: any } ) => Item;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to rename value to newValue (same in all other lines).

Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Jeelislive thanks for the contribution. The direction sounds good, there are some things to follow-up on, would you be available to do so in the next days?

Some other comments:

  • There are a few spacing changes that shouldn't be there. It looks like you don't have the local git hooks set up. Take a look at this guide.
  • Can you add tests and/or storybook example for this code? It's an important aspect, and we want to make sure all cases are well covered and that future changes don't break this either.

return;
}
// Use setValue to extract the new value for this field
let nextValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, all fields are normalized, and so they'll have a proper setValue. Additionally, if we handle this at the controls-level (see comment below), updatedData will be fine already. The only thing we'd need to do is making sure nextValue is calculated from getValue.

@oandregal
Copy link
Member

@Jeelislive is sounds like you don't have your GitHub account associated to your WordPress.org profile. Take a look at this guide so you receive props when this lands.

@Jeelislive
Copy link
Author

@oandregal
I'll start by:
Moving the logic to the control-level as suggested,
Cleaning up any unintended spacing changes (I'll check my git hooks),
Renaming value to newValue,
And adding test coverage and/or Storybook examples to validate the changes.
Also, I’ll go ahead and link my GitHub and WordPress.org accounts so proper credit can be tracked.

Let me work on these updates, and I’ll circle back here once they’re ready!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] DataViews /packages/dataviews [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataViews: user-input filters don't work with fields that use a getValue function
3 participants