Refactor DataFormLayout: Introduce getWrapper function for improved l…#74978
Closed
Refactor DataFormLayout: Introduce getWrapper function for improved l…#74978
Conversation
…ayout handling (#74999) * Added getWrapper function to determine the appropriate wrapper component based on layout and form. * Simplified the logic for selecting the wrapper, enhancing code readability and maintainability.
|
Flaky tests detected in 4736b3b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/21405199806
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What?
Closes #74999
Refactor wrapper selection in
DataFormLayoutby extracting it into agetWrapperhelper and clarifying fallback behavior whenform.layout.typeis missing or not resolvable.Why?
The wrapper selection logic had become harder to follow and reason about. This change centralizes the decision in one place.
How?
Wrapper resolution now follows this order:
aswhen provided.form.layout.typeis defined, use its registered wrapper, falling back toDEFAULT_WRAPPER.form.layout.typeis not picked (for example, it is undefined), use the first field’s layout wrapper, falling back toDEFAULT_WRAPPER.This mirrors the existing layout defaulting during normalization: fields without an explicit layout inherit the form layout, and when the form layout is not picked, the first field effectively drives the layout. The wrapper fallback now follows the same approach.
Field layout components are unchanged and still selected per-field via
getFormFieldLayout( formField.layout.type )?.component.Testing Instructions
layout: "card"from form object (gutenberg/packages/dataviews/src/dataform/stories/layout-card.tsx
Lines 176 to 177 in 18573f2