-
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
Block editor settings: delay selecting pageOnFront, pageForPosts #57290
base: trunk
Are you sure you want to change the base?
Changes from 2 commits
99f955b
8d05001
a9813b6
3991a70
ac45b44
80a3e54
cc80345
15f78d9
17857cd
91dc709
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,21 @@ const BLOCK_EDITOR_SETTINGS = [ | |
'__experimentalArchiveTitleNameLabel', | ||
]; | ||
|
||
function usePageSettings() { | ||
return useSelect( ( select ) => { | ||
const { canUser, getEntityRecord } = select( coreStore ); | ||
|
||
const siteSettings = canUser( 'read', 'settings' ) | ||
? getEntityRecord( 'root', 'site' ) | ||
: undefined; | ||
|
||
return { | ||
pageOnFront: siteSettings?.page_on_front, | ||
pageForPosts: siteSettings?.page_for_posts, | ||
}; | ||
}, [] ); | ||
} | ||
|
||
/** | ||
* React hook used to compute the block editor settings to use for the post editor. | ||
* | ||
|
@@ -93,8 +108,6 @@ function useBlockEditorSettings( settings, postType, postId ) { | |
hasUploadPermissions, | ||
canUseUnfilteredHTML, | ||
userCanCreatePages, | ||
pageOnFront, | ||
pageForPosts, | ||
userPatternCategories, | ||
restBlockPatterns, | ||
restBlockPatternCategories, | ||
|
@@ -104,17 +117,12 @@ function useBlockEditorSettings( settings, postType, postId ) { | |
const { | ||
canUser, | ||
getRawEntityRecord, | ||
getEntityRecord, | ||
getUserPatternCategories, | ||
getEntityRecords, | ||
getBlockPatterns, | ||
getBlockPatternCategories, | ||
} = select( coreStore ); | ||
|
||
const siteSettings = canUser( 'read', 'settings' ) | ||
? getEntityRecord( 'root', 'site' ) | ||
: undefined; | ||
|
||
return { | ||
canUseUnfilteredHTML: getRawEntityRecord( | ||
'postType', | ||
|
@@ -128,8 +136,6 @@ function useBlockEditorSettings( settings, postType, postId ) { | |
: EMPTY_BLOCKS_LIST, // Reusable blocks are fetched in the native version of this hook. | ||
hasUploadPermissions: canUser( 'create', 'media' ) ?? true, | ||
userCanCreatePages: canUser( 'create', 'pages' ), | ||
pageOnFront: siteSettings?.page_on_front, | ||
pageForPosts: siteSettings?.page_for_posts, | ||
userPatternCategories: getUserPatternCategories(), | ||
restBlockPatterns: getBlockPatterns(), | ||
restBlockPatternCategories: getBlockPatternCategories(), | ||
|
@@ -229,8 +235,7 @@ function useBlockEditorSettings( settings, postType, postId ) { | |
// Check these two properties: they were not present in the site editor. | ||
__experimentalCreatePageEntity: createPageEntity, | ||
__experimentalUserCanCreatePages: userCanCreatePages, | ||
pageOnFront, | ||
pageForPosts, | ||
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 think these settings were meant to be experimental. I think we should be ok with removing it, thinks will just keep working fine with 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 think you are right 🤞 |
||
__experimentalUsePageSettings: usePageSettings, | ||
__experimentalPreferPatternsOnRoot: postType === 'wp_template', | ||
templateLock: | ||
postType === 'wp_navigation' ? 'insert' : settings.templateLock, | ||
|
@@ -251,8 +256,6 @@ function useBlockEditorSettings( settings, postType, postId ) { | |
undo, | ||
createPageEntity, | ||
userCanCreatePages, | ||
pageOnFront, | ||
pageForPosts, | ||
postType, | ||
setIsInserterOpened, | ||
] | ||
|
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.
Is this the only place where we need these settings? It seems we only use them in a callback, so maybe a better settings would be a callback
getSiteSettings
or something like that no?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.
Also something else, I've noted, it seems that the "link control" component relies on a lot of settings (
__experimentalFetchLinkSuggestions
) for instance and all these settings are not used elsewhere (unless I'm wrong). So maybe it's the way we're implementing the link control that is wrong, maybe we should just have a "default link control" and make it a filterable component like "mediaUpload". (Just thinking of alternatives, I'm not sure which is best)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.
Yes, I think we should consider that too. I'm however not familiar enough with it to want to attempt a complete rewrite 😄
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'm trying to make things better step by step and make sure are the dependencies are completely private so it's easier to rewrite in the future
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.
No, because it's used for rendered UI, not a callback. The selector is a resolver, so the component should re-render when the settings come in.
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 seems like
useSearchHandler
could entirely be a setting, but I'd prefer to attempt this separately because it would mean duplicating all this code toedit-widgets
.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.
@youknowriad I'd be grateful to hear more about how you'd like
LinkControl
to change. Now is the time because a lot of demands are being placed on it.I'd like to understand more about this.