Skip to content

Conversation

@oandregal
Copy link
Member

@oandregal oandregal commented Nov 25, 2025

Follow-up to #73387
Related #73548

What?

After #73387 each field type provided a normalize function that effectively acted as a factory for the given field type. This changes it back to return an object with the default properties.

Why?

See feedback #73387

Testing Instructions

Smoke test DataViews storybook and the Site Editor (Pages, Templates, Patterns screens).

@oandregal oandregal self-assigned this Nov 25, 2025
@github-actions
Copy link

github-actions bot commented Nov 25, 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.

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

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

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

@oandregal oandregal added [Type] Code Quality Issues or PRs that relate to code quality [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels Nov 25, 2025
@oandregal oandregal force-pushed the simplify/field-api-normalization branch from fd9364a to 47f458c Compare November 25, 2025 12:45
* @return A field type definition.
*/
export default function getNormalizeFieldFunction< Item >(
function getDefaultProperties< Item >(
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what this function is about?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess your question is why not to inline this within normalizeFields, right?

I thought it'd be best that it stays as a separate function because this acts like the public registry we don't have. So when we have the registry, it'd be a simple call switch.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I'm actually not sure what this function is about. Is it some kind of getFieldTypeByName or something? If that's the case, I kind of expected this to loop through the fields and compare "id" or something. The if/else or switch feels a bit weird.

Copy link
Member Author

Choose a reason for hiding this comment

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

This function just loads the defaults defined by each type in the corresponding file. I guess getFieldTypeByName could work as a name as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be something like

[ string, number ... ].find( fieldType => fieldType.type === type )

Copy link
Member Author

Choose a reason for hiding this comment

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

That's neat, I pushed it at eeb173c

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

I find this a lot clearer. Thanks for the follow-up

@oandregal oandregal force-pushed the simplify/field-api-normalization branch from eeb173c to d472229 Compare November 25, 2025 14:20
@oandregal oandregal enabled auto-merge (squash) November 25, 2025 14:22
@oandregal oandregal disabled auto-merge November 25, 2025 14:39
| 'over';

export type FieldType =
export type FieldTypeName =
Copy link
Member Author

Choose a reason for hiding this comment

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

@youknowriad I lost the comment attached to the commit, so continuing here: perhaps FieldTypeName is a good fit for this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me, although "string" would have worked for me assuming we'll allow registration at some point.

@oandregal oandregal enabled auto-merge (squash) November 25, 2025 16:00
@oandregal oandregal merged commit 36bcc49 into trunk Nov 25, 2025
42 of 43 checks passed
@oandregal oandregal deleted the simplify/field-api-normalization branch November 25, 2025 16:39
@github-actions github-actions bot added this to the Gutenberg 22.2 milestone Nov 25, 2025
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 [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants