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

Quick Edit: add Template field #66591

Merged
merged 50 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
da0b766
Add DataFormProvider for fields
louwie17 Oct 4, 2024
538ef3e
Add dataform layout component and inline layout
louwie17 Oct 28, 2024
9cb2b26
Fix label in panel view
louwie17 Oct 28, 2024
c641723
Remove unneeded line
louwie17 Oct 28, 2024
a707275
Update `field` to FormField as well
louwie17 Oct 28, 2024
111e9f1
Merge branch 'update/dataform_combined_fields_api' of github.com:Word…
gigitux Oct 29, 2024
93b8e53
QuickEdit: implement Template field
gigitux Oct 30, 2024
9806534
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/templ…
gigitux Oct 30, 2024
ca3b59b
improve style
gigitux Oct 30, 2024
61f9655
implement logic to reset to default template
gigitux Oct 30, 2024
5a623fb
ensure that setting object is defined
gigitux Oct 30, 2024
f9b1eef
Add DataFormProvider for fields
louwie17 Oct 4, 2024
db4cbd6
Add dataform layout component and inline layout
louwie17 Oct 28, 2024
2d7ee1b
Fix label in panel view
louwie17 Oct 28, 2024
2ba1ffb
Remove unneeded line
louwie17 Oct 28, 2024
4384814
Update `field` to FormField as well
louwie17 Oct 28, 2024
8e4b0ef
Remove combinedFields usage
louwie17 Oct 31, 2024
152c875
Remove old use of View
louwie17 Oct 31, 2024
7cfb87d
Add label and move field type check to 'getFieldDefinition'
louwie17 Oct 31, 2024
a3768d8
Create types of each view
louwie17 Oct 31, 2024
3e5a584
Add sticky example
louwie17 Oct 31, 2024
58150ef
Update combined fields story
louwie17 Oct 31, 2024
b523f7f
Merge branch 'update/dataform_combined_fields_api' of github.com:Word…
gigitux Oct 31, 2024
8698f0f
Add DataFormProvider for fields
louwie17 Oct 4, 2024
6a0598d
Add dataform layout component and inline layout
louwie17 Oct 28, 2024
bbae788
Fix label in panel view
louwie17 Oct 28, 2024
e17c228
Remove unneeded line
louwie17 Oct 28, 2024
05d7506
Update `field` to FormField as well
louwie17 Oct 28, 2024
15b0f11
Remove combinedFields usage
louwie17 Oct 31, 2024
a8d2462
Remove old use of View
louwie17 Oct 31, 2024
5967797
Add label and move field type check to 'getFieldDefinition'
louwie17 Oct 31, 2024
7eac0ab
Create types of each view
louwie17 Oct 31, 2024
a8f9e82
Add sticky example
louwie17 Oct 31, 2024
f9e86cb
Update combined fields story
louwie17 Oct 31, 2024
b05dbef
Fix change I missed during rebase
louwie17 Oct 31, 2024
8c15a9b
Remove old status_and_visibility field
louwie17 Nov 4, 2024
8ea852c
Rename fields to children for clarity
louwie17 Nov 4, 2024
0c67f64
Add children support to regular layout
louwie17 Nov 4, 2024
4cd314b
Replace inline with labelPosition
louwie17 Nov 5, 2024
ddf996a
Remove field type checking within dataform layouts
louwie17 Nov 5, 2024
f31a91c
Merge branch 'update/dataform_combined_fields_api' of github.com:Word…
gigitux Nov 6, 2024
9021f79
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/templ…
gigitux Nov 25, 2024
d698e14
fix template field registration
gigitux Nov 25, 2024
69396c0
restore not necessary changes
gigitux Nov 25, 2024
7864b00
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/templ…
gigitux Dec 2, 2024
704ebe5
wrap DataForm component
gigitux Dec 2, 2024
7cf2843
not use hook
gigitux Dec 2, 2024
cbb8bda
improve dependency
gigitux Dec 3, 2024
f891475
improve code style
gigitux Dec 3, 2024
32e1b31
add issue
gigitux Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve dependency
gigitux committed Dec 3, 2024
commit cbb8bda871392548d2595f40568cc95eaf6854e4
44 changes: 31 additions & 13 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
@@ -136,20 +136,38 @@ function PostEditForm( { postType, postId } ) {
);
const settings = usePatternSettings();

/**
* The template field depends on the block editor settings.
* This is a workaround to ensure that the block editor settings are available.
*/
const fieldsWithDependency = useMemo( () => {
return fields.map( ( field ) => {
if ( field.id === 'template' ) {
return {
...field,
Edit: ( data ) => (
<ExperimentalBlockEditorProvider settings={ settings }>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this here and not directly in the template field edit?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not asking to change it, just curious why

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to pass settings to this provider and usePatternSettings depends on the edit site store:

export default function usePatternSettings() {
const storedSettings = useSelect( ( select ) => {
const { getSettings } = unlock( select( editSiteStore ) );
return getSettings();
}, [] );

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, here are my thoughts on this. Not necessarily something to be done here though

We need to check what settings exactly are needed for these previews. It seems mostly about the list of available patterns (maybe there's other stuff but I'm not sure). IMO, these could be provided directly from core-data package selectors... without the "settings" object. This is a cleanup that needs to be done at some point. I mention some of this here https://make.wordpress.org/core/2024/09/12/gutenberg-development-practices-and-common-pitfalls/ (It's also kind of a similar change to what we did for defaultTemplates and template parts)

I'm ok shipping this as is now but I feel like if someone uses the "template" field, it should just work without any hidden requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I agree with you! I'm happy to:

  • open an issue.
  • add the issue link on this comment.
  • dedicate some time in the upcoming weeks to fix this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome ❤️

<field.Edit { ...data } />
</ExperimentalBlockEditorProvider>
),
};
}
return field;
} );
}, [ fields, settings ] );

return (
<ExperimentalBlockEditorProvider settings={ settings }>
<VStack spacing={ 4 }>
{ ids.length === 1 && (
<PostCardPanel postType={ postType } postId={ ids[ 0 ] } />
) }
<DataForm
data={ ids.length === 1 ? record : multiEdits }
fields={ fields }
form={ form }
onChange={ onChange }
/>
</VStack>
</ExperimentalBlockEditorProvider>
<VStack spacing={ 4 }>
{ ids.length === 1 && (
<PostCardPanel postType={ postType } postId={ ids[ 0 ] } />
) }
<DataForm
data={ ids.length === 1 ? record : multiEdits }
fields={ fieldsWithDependency }
form={ form }
onChange={ onChange }
/>
</VStack>
);
}