-
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
Site Editor: Do not display 'trashed' navigation menus in Sidebar #55072
Merged
Merged
Changes from all commits
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
9 changes: 2 additions & 7 deletions
9
...c/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js
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
32 changes: 32 additions & 0 deletions
32
...s/edit-site/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-title.js
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,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { NAVIGATION_POST_TYPE } from '../../utils/constants'; | ||
|
||
export default function useNavigationMenuTitle( id ) { | ||
return useSelect( | ||
( select ) => { | ||
if ( ! id ) { | ||
return undefined; | ||
} | ||
|
||
const editedRecord = select( coreStore ).getEditedEntityRecord( | ||
'postType', | ||
NAVIGATION_POST_TYPE, | ||
id | ||
); | ||
|
||
// Do not display a 'trashed' navigation menu. | ||
return editedRecord.status === 'trash' | ||
? undefined | ||
: editedRecord.title; | ||
}, | ||
[ id ] | ||
); | ||
} |
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.
The hook is called
useNavigationMenuTitle
so I expect it to return the title and not return "empty" even if the record is "trashed". It feels like the logic to show or not something that is "trashed" doesn't really belong to auseNavigationMenuTitle
hook. And we may just want to filter some request or something.Anyway, not that important since it's just internal API but I thought I'd mention.
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 started as inline
useSelect
; conditions are more "visible" in that case, and I don't see any issue returningundefined
based on record status.I guess we can return
{ title, viewable }
from the hook to make it more explicit.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.
To be honest it's not important and I'm fine if leave it but I can clarify my reasoning:
useNavigationMenuTitle
nothing in the title of the hook suggests anything about the status of the navigation menu. I also think a trashed navigation menu should keep its title.{ title, viewable }
: yeah that's better but than the name of the hook is not adequate anymore. It feels like this needs two hooks or just leave inline useSelect (what's wrong with that :P).I know I'm getting into weeds, so don't waste time on this.
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 always appreciate your feedback, @youknowriad!