Repository navigation
Post slug: Derive the slug preview from the current title instead of generated_slug
#84893
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
568d21a
Post slug: Don't show `auto-draft` as the slug of a new post
youknowriad 96bd04c
Post slug: Only use the server-generated slug while it matches the title
youknowriad b35388b
Core Data: Revert dropping `generated_slug` after an autosave
youknowriad 5d60a85
Post slug: Derive the slug from the current title, not the server
youknowriad a317491
Post slug: Don't clean an untouched slug on blur, and update core-fields
youknowriad bd19499
E2E: Scope the Parent row's None to its row in the post summary spec
youknowriad e40e983
Fields: Revert the slug field changes
youknowriad 4bfc5b6
Merge branch 'trunk' into claude/auto-draft-slug-issue-0af125
youknowriad 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,18 +1,13 @@ | ||
| import { useState } from '@wordpress/element'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import type { PostWithSlug } from './types'; | ||
| import { getSlug } from './utils'; | ||
|
|
||
| /* | ||
| * The slug of a post. It keeps the first slug in state rather than in a ref read during render. | ||
| * The slug of a post. | ||
| */ | ||
| const SlugView = ( { item }: { item: PostWithSlug } ) => { | ||
| const slug = getSlug( item ); | ||
| // The slug the post had first, shown while the slug is emptied. | ||
| const [ originalSlug ] = useState( slug ); | ||
|
|
||
| const slugToDisplay = slug || originalSlug; | ||
|
|
||
| return `${ slugToDisplay }`; | ||
| // A draft without a slug or a title has no slug yet. | ||
| return getSlug( item ) || __( 'None' ); | ||
| }; | ||
|
|
||
| export default SlugView; |
This file contains hidden or 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,34 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { getSlug } from '../post_type_supports/slug/utils'; | ||
|
|
||
| describe( 'getSlug', () => { | ||
| it( 'returns the slug if one exists', () => { | ||
| expect( | ||
| getSlug( { | ||
| id: 123, | ||
| slug: 'custom-slug', | ||
| title: 'Edited Title', | ||
| } ) | ||
| ).toBe( 'custom-slug' ); | ||
| } ); | ||
|
|
||
| it( 'derives the slug from the current title, not the server-generated slug', () => { | ||
| expect( | ||
| getSlug( { | ||
| id: 123, | ||
| title: 'Hello Slug', | ||
| generated_slug: 'auto-draft', | ||
| } ) | ||
| ).toBe( 'hello-slug' ); | ||
| } ); | ||
|
|
||
| it( 'returns an empty string for a post without a slug or a title', () => { | ||
| expect( | ||
| getSlug( { | ||
| id: 123, | ||
| title: '', | ||
| generated_slug: 'auto-draft', | ||
| } ) | ||
| ).toBe( '' ); | ||
| } ); | ||
| } ); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Should this be under "Breaking changes"?
"Bug fix" is okay if it was never really meant to work that way.
Optional, just asking.