-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 - Add combined fields support #65399
Merged
youknowriad
merged 9 commits into
WordPress:trunk
from
louwie17:add/dataforms_combined_fields
Oct 2, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
55684e6
Add combined fields option to DataForms
louwie17 0435b82
Add storybook example
louwie17 5b47ed7
Add support for combined fields in the regular dataform view as well
louwie17 3d76b08
Replace any usage with generic for getVisibleFields function
louwie17 53492d1
Remove individual field header
louwie17 dd2a4d2
Remove 'layout' key from DataForms
louwie17 d36935d
Added fieldset and updated styling
louwie17 be84f79
Always show field labels
louwie17 0893046
Removed the border between fields in panel view
louwie17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
packages/dataviews/src/components/dataform-combined-edit/index.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalHStack as HStack, | ||
__experimentalVStack as VStack, | ||
__experimentalHeading as Heading, | ||
__experimentalSpacer as Spacer, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { DataFormCombinedEditProps, NormalizedField } from '../../types'; | ||
|
||
function Header( { title }: { title: string } ) { | ||
return ( | ||
<VStack className="dataforms-layouts__dropdown-header" spacing={ 4 }> | ||
<HStack alignment="center"> | ||
<Heading level={ 2 } size={ 13 }> | ||
{ title } | ||
</Heading> | ||
<Spacer /> | ||
</HStack> | ||
</VStack> | ||
); | ||
} | ||
|
||
function DataFormCombinedEdit< Item >( { | ||
field, | ||
data, | ||
onChange, | ||
hideLabelFromVision, | ||
}: DataFormCombinedEditProps< Item > ) { | ||
const className = 'dataforms-combined-edit'; | ||
const visibleChildren = ( field.children ?? [] ) | ||
.map( ( fieldId ) => field.fields.find( ( { id } ) => id === fieldId ) ) | ||
.filter( | ||
( childField ): childField is NormalizedField< Item > => | ||
!! childField | ||
); | ||
const children = visibleChildren.map( ( child ) => { | ||
return ( | ||
<div className="dataforms-combined-edit__field" key={ child.id }> | ||
<child.Edit | ||
data={ data } | ||
field={ child } | ||
onChange={ onChange } | ||
/> | ||
</div> | ||
); | ||
} ); | ||
|
||
const Stack = field.direction === 'horizontal' ? HStack : VStack; | ||
|
||
return ( | ||
<> | ||
{ ! hideLabelFromVision && <Header title={ field.label } /> } | ||
<Stack spacing={ 4 } className={ className } as="fieldset"> | ||
{ children } | ||
</Stack> | ||
</> | ||
); | ||
} | ||
|
||
export default DataFormCombinedEdit; |
12 changes: 12 additions & 0 deletions
12
packages/dataviews/src/components/dataform-combined-edit/style.scss
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.dataforms-layouts-panel__field-dropdown { | ||
.dataforms-combined-edit { | ||
border: none; | ||
padding: 0; | ||
} | ||
} | ||
|
||
.dataforms-combined-edit { | ||
&__field { | ||
flex: 1 1 auto; | ||
} | ||
} |
This file contains 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
29 changes: 29 additions & 0 deletions
29
packages/dataviews/src/dataforms-layouts/get-visible-fields.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { normalizeCombinedFields } from '../normalize-fields'; | ||
import type { | ||
Field, | ||
CombinedFormField, | ||
NormalizedCombinedFormField, | ||
} from '../types'; | ||
|
||
export function getVisibleFields< Item >( | ||
fields: Field< Item >[], | ||
formFields: string[] = [], | ||
combinedFields?: CombinedFormField< Item >[] | ||
): Field< Item >[] { | ||
const visibleFields: Array< | ||
Field< Item > | NormalizedCombinedFormField< Item > | ||
> = [ ...fields ]; | ||
if ( combinedFields ) { | ||
visibleFields.push( | ||
...normalizeCombinedFields( combinedFields, fields ) | ||
); | ||
} | ||
return formFields | ||
.map( ( fieldId ) => | ||
visibleFields.find( ( { id } ) => id === fieldId ) | ||
) | ||
.filter( ( field ): field is Field< Item > => !! field ); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a minor, but I noticed that the panel to customize props doesn't appear on the new story:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only notice that on the
Docs
page correct? I think that is normal, at-least I see the same in other stories.If you select the combined fields specific story from the navigation on the left the props should show up: