-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Data View - Page view: Add slug field control #65196
base: trunk
Are you sure you want to change the base?
Conversation
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
This is a tricky one, and technically an existing issue (see video below) so perhaps not one we have to fix here? slug.mp4Some validation might help; maybe the field should error when empty, and revert to the current value on blur? The Save button would be disabled when the field is empty. Some validation to avoid duplicate slugs might be handy as well. We also need to think about the conditions in which the Link field is shown in the quick-edit panel. In the vast majority of cases it's not possible to apply the same slug to multiple items, so maybe we just hide it for now? |
Yeah, this is something that I noticed too.
I'm fine following this approach. I'm going to try to implement it!
Yeah good point. I would see this kind of validation on the backend side when the user clicks save. For now, I would skip this point because it impacts some work not specifically related to the scope of this project.
True! Let's hide it! Thanks for your precious feedback, @jameskoster! 🙇 |
…into add/link-control
…into add/link-control
@@ -369,6 +370,13 @@ function usePostFields( viewType ) { | |||
return <time>{ getFormattedDate( item.date ) }</time>; | |||
}, | |||
}, | |||
{ |
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.
This works because our APIs are already extensible. However, there's an alternative that @joshuatf mentioned somewhere. Instead of doing:
{
id: 'slug',
Edit: /* custom slug Edit */,
render: /* custom slug render */,
isValid: /* custom slug isValid */,
// etc.
}
we can do something along these lines:
registerFieldType( 'core/slug', FieldSlug );
const fields = [
{
id: 'slug',
type: 'core/slug',
}
];
This has a few advantages:
-
It gets us a bit closer to making the
type
field required. We're not there there yet because there are a couple of missing types we need (image, for example), but we should aim to do it. -
We offer higher semantics and gets us a bit closer to having no-code JSON-oriented fields. This may sound a bit abstract, but imagine the following scenario: in the future, there's a mechanism for users to create screens based on declaring which fields they want from a dataset. All via UI. In that scenario, that UI needs to be no-code, and users shouldn't have to provide a "custom render", "custom edit", "custom validation", etc. if they just want a field to be a "slug". Instead, they should work with types: the basic ones provided by DataViews (string, integer, date, etc.) but also any other one that is domain-specific (slug, cart-status, etc.).
Another aspect of this PR is what should be the API offered by the wordpress/field
package?
This suggest it should export individual field properties (render, edit, isValid, etc.). There are a few. What if it exported the whole field instead? An advantage of exporting the whole Field is that the wordpress/field
package can implement new APIs as they come without having to modify the consumers:
// The consumer doesn't have to modify any code when
// a new Field property is introduced, renamed it, etc.
// It's the FieldSlug responsibility to implement it.
const fields = [
{
id: 'slug',
type: 'core/slug'
}
];
What?
Part of #64519
Screen.Capture.on.2024-09-10.at.12-42-17.mp4
This PR adds the
slug
field control to the Page view. Most of the logic is copied from:getPermalinkParts
: https://github.com/WordPress/gutenberg/blob/5682b928356f624f6ed820d066689423d08d5d88/packages/editor/src/store/selectors.js/#L994-L1016isPermalinkEditable
: https://github.com/WordPress/gutenberg/blob/5682b928356f624f6ed820d066689423d08d5d88/packages/editor/src/store/selectors.js/#L937-L944Currently, these two functions are public selectors and rely on the editor state, so we can't refactor those. I think that for now, we can keep this duplicate code and when the post editor sidebar will be powered by the dataview, we can think to refactor those, but I'm open to feedback on this.
Similar to #64496, this code could be moved to the
@wordpress/core-fields-control
package if we agree to create it.Validation
There is an edge-case that I think that we should take care, but I will wait for your feedback before to proceed. When the input is empty, the save button is clickable:
This isn’t ideal because a page/post should always have a slug set. Currently, if the input is empty, the original slug is restored on the
onBlur
event, which is not the best UX.How?
Testing Instructions
Ensure that
Quick Edit in DataViews
andQuick Edit in DataViews
are enabled./wp-admin/options-permalink.php
.plain
setting.