-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ import { useEffect, useRef } from '@wordpress/element'; | |
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
import { getSlug } from './utils'; | ||
|
||
const SlugView = ( { item }: { item: BasePost } ) => { | ||
const slug = item.slug; | ||
const slug = item ? getSlug( item ) : ''; | ||
const originalSlugRef = useRef( slug ); | ||
|
||
useEffect( () => { | ||
|
@@ -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 commentThe 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? |
||
}; | ||
|
||
export default SlugView; |
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,15 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { cleanForSlug } from '@wordpress/url'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
import { getItemTitle } from '../../actions/utils'; | ||
|
||
export const getSlug = ( item: BasePost ) => { | ||
return ( | ||
item.slug || cleanForSlug( getItemTitle( item ) ) || item.id.toString() | ||
); | ||
}; |
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.
getSlug
will always return something, even if it's theitem.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 printdata
here:gutenberg/packages/dataviews/src/dataforms-layouts/panel/index.tsx
Lines 59 to 68 in d871796
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 withingetSlug
, whatever you think it's best.A follow-up is that we need a better management of loading states for
DataForm
, like we have forDataViews
. The issue is that the data is not yet loaded. ForDataViews
we haveisLoading
prop, it sounds like we need the same forDataForm
. 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 thegetSlug
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.
Improved with 51e08fe.
Sure! I created an issue #66599.
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:
item
in both places.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