-
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
Site Editor (Experiment): Automatically open the sidebar to the appropriate template sub-menu #30098
Merged
Merged
Site Editor (Experiment): Automatically open the sidebar to the appropriate template sub-menu #30098
Changes from all commits
Commits
Show all changes
3 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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { get } from 'lodash'; | ||
import { get, map } from 'lodash'; | ||
import createSelector from 'rememo'; | ||
|
||
/** | ||
|
@@ -15,10 +15,15 @@ import { uploadMedia } from '@wordpress/media-utils'; | |
* Internal dependencies | ||
*/ | ||
import { | ||
MENU_ROOT, | ||
MENU_TEMPLATE_PARTS, | ||
MENU_TEMPLATES_UNUSED, | ||
TEMPLATE_PARTS_SUB_MENUS, | ||
MENU_TEMPLATES, | ||
} from '../components/navigation-sidebar/navigation-panel/constants'; | ||
import { | ||
getTemplateLocation, | ||
isTemplateSuperseded, | ||
} from '../components/navigation-sidebar/navigation-panel/template-hierarchy'; | ||
|
||
/** | ||
* Returns whether the given feature is enabled or not. | ||
|
@@ -153,20 +158,13 @@ export function getNavigationPanelActiveMenu( state ) { | |
* Returns the current template or template part's corresponding | ||
* navigation panel's sub menu, to be used with `openNavigationPanelToMenu`. | ||
* | ||
* Currently, while template parts return their sub menu, | ||
* templates always return their main menu. | ||
* | ||
* @param {Object} state Global application state. | ||
* | ||
* @return {string} The current template or template part's sub menu. | ||
*/ | ||
export const getCurrentTemplateNavigationPanelSubMenu = createRegistrySelector( | ||
( select ) => ( state ) => { | ||
const templateType = getEditedPostType( state ); | ||
if ( 'wp_template' === templateType ) { | ||
return MENU_TEMPLATES; | ||
} | ||
|
||
const templateId = getEditedPostId( state ); | ||
const template = templateId | ||
? select( coreDataStore ).getEntityRecord( | ||
|
@@ -176,11 +174,41 @@ export const getCurrentTemplateNavigationPanelSubMenu = createRegistrySelector( | |
) | ||
: null; | ||
|
||
return ( | ||
TEMPLATE_PARTS_SUB_MENUS.find( | ||
( submenu ) => submenu.area === template?.area | ||
)?.menu || MENU_TEMPLATE_PARTS | ||
if ( ! template ) { | ||
return MENU_ROOT; | ||
} | ||
|
||
if ( 'wp_template_part' === templateType ) { | ||
return ( | ||
TEMPLATE_PARTS_SUB_MENUS.find( | ||
( submenu ) => submenu.area === template?.area | ||
)?.menu || MENU_TEMPLATE_PARTS | ||
); | ||
} | ||
|
||
const templates = select( coreDataStore ).getEntityRecords( | ||
'postType', | ||
'wp_template', | ||
{ | ||
per_page: -1, | ||
} | ||
); | ||
const showOnFront = select( coreDataStore ).getEditedEntityRecord( | ||
'root', | ||
'site' | ||
).show_on_front; | ||
|
||
if ( | ||
isTemplateSuperseded( | ||
template.slug, | ||
map( templates, 'slug' ), | ||
showOnFront | ||
) | ||
) { | ||
return MENU_TEMPLATES_UNUSED; | ||
} | ||
|
||
return getTemplateLocation( template.slug ); | ||
Comment on lines
+189
to
+211
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. I really love this 😄 Great use of existing functions! |
||
} | ||
); | ||
|
||
|
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.
Thanks for extracting these!