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 - Slug Field: improve slug preview #66559

Merged
merged 2 commits into from
Oct 30, 2024
Merged

Conversation

gigitux
Copy link
Contributor

@gigitux gigitux commented Oct 29, 2024

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.

Before After
image image

Why?

How?

Testing Instructions

Ensure that Quick Edit in DataViews and Quick Edit in DataViews are enabled.
Ensure that you have a draft page without any title set.

  1. Visit the Site Editor.
  2. Click on pages.
  3. Toggle to the table view.
  4. Select the draft page that you created.
  5. Click on the settings.
  6. Click on details panel icon.
  7. Ensure that the link field is visible
  8. Click on it.
  9. Ensure that the slug preview is right. You should see the page ID.
  10. Update the slug.
  11. Save.
  12. Ensure that the page is visible to the new link.

Testing Instructions for Keyboard

Screenshots or screencast

Copy link

github-actions bot commented Oct 29, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: gigitux <[email protected]>
Co-authored-by: oandregal <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@gigitux gigitux self-assigned this Oct 29, 2024
@gigitux gigitux added [Type] Experimental Experimental feature or API. [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews labels Oct 29, 2024
@oandregal
Copy link
Member

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 ) : '';
Copy link
Member

@oandregal oandregal Oct 29, 2024

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?

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 didn't have time to investigate why, but during the loading of the page, item is a boolean. You can add print data here:

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

Copy link
Member

@oandregal oandregal Oct 30, 2024

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?

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved with 51e08fe.

Is this something you'd be able to follow-up on?

Sure! I created an issue #66599.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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:

  1. The data prop should be called item in both places.
  2. The field should be passed down as a prop in both places.

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 created a dedicated issue: #66616

Copy link
Member

Choose a reason for hiding this comment

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

related #67577

@gigitux
Copy link
Contributor Author

gigitux commented Oct 30, 2024

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

Sorry for the oversight in the testing instructions. They are now updated. The issue occurs when you have a draft page without a title.

@gigitux gigitux requested a review from oandregal October 30, 2024 09:47
@oandregal
Copy link
Member

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 ?? '' }`;
Copy link
Member

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?

@gigitux gigitux requested a review from oandregal October 30, 2024 13:23
Copy link

Flaky tests detected in 51e08fe.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11594107744
📝 Reported issues:

@gigitux gigitux merged commit 8a11ce4 into trunk Oct 30, 2024
68 of 70 checks passed
@gigitux gigitux deleted the fix/slug-draft-post branch October 30, 2024 18:18
@github-actions github-actions bot added this to the Gutenberg 19.7 milestone Oct 30, 2024
karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 2024
* Quick Edit - Slug Field: improve slug preview

* improve type

Co-authored-by: gigitux <[email protected]>
Co-authored-by: oandregal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews [Type] Experimental Experimental feature or API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants