Skip to content
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

DataForm: move validation logic to the field type definition #64164

Merged
merged 2 commits into from
Aug 1, 2024

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Aug 1, 2024

Part of #59745
Follow-up to #64064

What?

This PR is a refactor, it doesn't modify any behavior. It moves the DataForm's validation logic into the corresponding field type definition.

Why?

With the introduction of field type definitions at #64064 we are now able to centralize more parts of the logic there.

How?

Extracts logic from validation.ts into the corresponding field type definition.

Testing Instructions

Verify the order modal still works as before:

Gravacao.do.ecra.2024-08-01.as.11.03.06.mov

Copy link

github-actions bot commented Aug 1, 2024

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 <oandregal@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>

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 Aug 1, 2024
@oandregal oandregal changed the title DataForm: moves validation logic to field type definition DataForm: move validation logic to the field type definition Aug 1, 2024
return {
sort: () => 0,
isValid: ( value: any, elements?: Option[] ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering about the elements argument here. I'm not sure it makes sense for all types and some types might have their own specific config (min, max for integer for instance...), so how can we make this more generic and that works for all types.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can pass the field as an argument instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, agree. I made a mental note about this but forgot to implement it, this is what I had in mind d13edc0

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.

Not sure I like the "context" name but I think it's is good for now.

@oandregal oandregal enabled auto-merge (squash) August 1, 2024 10:20
@oandregal oandregal merged commit a47a25d into trunk Aug 1, 2024
62 checks passed
@oandregal oandregal deleted the update/move-validation-to-type-definition branch August 1, 2024 10:24
@github-actions github-actions bot added this to the Gutenberg 19.0 milestone Aug 1, 2024
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.

2 participants