-
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
Quick Edit - Slug Field: improve slug preview #66559
Conversation
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
How do I trigger the situation this PR fixes? I tried the steps in the description but couldn't. Tried with draft pages (even a new one I just created) but cannot run into the issue. I see the slug everywhere: Screen.Recording.2024-10-29.at.17.54.57.mov |
|
||
const SlugView = ( { item }: { item: BasePost } ) => { | ||
const slug = item.slug; | ||
const slug = item ? getSlug( item ) : ''; |
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.
getSlug
will always return something, even if it's the item.id
? Do we need to cover against not returning anything (empty string)? Or perhaps I'm just unable to run into the issue you found?
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.
I didn't have time to investigate why, but during the loading of the page, item
is a boolean. You can add print data
here:
gutenberg/packages/dataviews/src/dataforms-layouts/panel/index.tsx
Lines 59 to 68 in d871796
function FormField< Item >( { | |
data, | |
field, | |
onChange, | |
}: FormFieldProps< Item > ) { | |
// Use internal state instead of a ref to make sure that the component | |
// re-renders when the popover's anchor updates. | |
const [ popoverAnchor, setPopoverAnchor ] = useState< HTMLElement | null >( | |
null | |
); |
Screen.Capture.on.2024-10-30.at.10-44-03.mp4
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.
I see. Can you instead check if item is an object? It just happens to be a boolean, but that check would pass if it's a string only to break later in getSlug
. Or integrate that check within getSlug
, whatever you think it's best.
A follow-up is that we need a better management of loading states for DataForm
, like we have for DataViews
. The issue is that the data is not yet loaded. For DataViews
we have isLoading
prop, it sounds like we need the same for DataForm
. Is this something you'd be able to follow-up on?
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.
Actually, wouldn't this logic be best placed in getValue
instead of the getSlug
utility? That way edit & view components would have access to it.
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.
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 good idea, but currently we are not passing to the render component, the field
prop. I would create a dedicated issue and craft a dedicated PR for this. If you think that it is not necessary, I'm happy to implement it in this PR too.
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.
Oh, you're right. I thought we did at some point? 🤔 Let's ship and move on.
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.
I just looked this up and it's confusing why the Edit function receives data (Item), field, onChange, hideLabelFromVision but the View function only receives the item (Item). There's also different names (data vs item) for the same prop across functions. I think we need to consolidate and:
- The data prop should be called
item
in both places. - The
field
should be passed down as a prop in both places.
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.
I created a dedicated issue: #66616
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.
related #67577
Sorry for the oversight in the testing instructions. They are now updated. The issue occurs when you have a draft page without a title. |
I was able to reproduce this by adding a new Page from the wp-admin flow. If I create one from the site editor, it appears to be created with "no title" as title. |
@@ -20,7 +21,7 @@ const SlugView = ( { item }: { item: BasePost } ) => { | |||
|
|||
const slugToDisplay = slug || originalSlugRef.current; | |||
|
|||
return `/${ slugToDisplay ?? '' }`; | |||
return `${ slugToDisplay ?? '' }`; |
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.
We probably no longer need the empty string if we already manage that above?
Flaky tests detected in 51e08fe. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11594107744
|
* Quick Edit - Slug Field: improve slug preview * improve type Co-authored-by: gigitux <[email protected]> Co-authored-by: oandregal <[email protected]>
What?
I noticed that the fallback logic for undefined slugs was missing, for instance draft pages. This PR implements a mechanism to provide a fallback slug when the slug is not defined.
Why?
How?
Testing Instructions
Ensure that
Quick Edit in DataViews
andQuick Edit in DataViews
are enabled.Ensure that you have a draft page without any title set.
Testing Instructions for Keyboard
Screenshots or screencast