-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Data Views: Add action for pages to set site homepage #65426
base: trunk
Are you sure you want to change the base?
Conversation
ab1c828
to
0f3a986
Compare
Size Change: +946 B (+0.05%) Total Size: 1.82 MB
ℹ️ View Unchanged
|
@creativecoder is this one ready for review? :) |
@jameskoster A few things that still need doing
I'm not sure when I'll be able to get back to this, so if anyone wants to pick this up--feel free! |
Thanks @creativecoder! I'm going to have a go at picking this up. I'll start by addressing the items you listed above, and then I'll mark as ready for review. |
Yeah, I see your angle. I agree that we need a better mechanism, we cannot augment the item with every piece of global data we need.
That'd work for me as well. We have some actions defined in the edit-site package. |
Thanks for the discussion here 🙏
This sounds like a good path forward, I'll work on that next. |
return decodeEntities( item.title.raw ); | ||
} | ||
return ''; | ||
} |
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 needed to duplicate the getItemTitle
function to avoid importing it from the fields package into edit-site.
Yes, I think this could be handled soon after in a follow-up PR. There's also a separate issue for it here: #63667.
I think this is because the action is being called on a page that isn't being previewed. Should selecting an action on a page that isn't the selected/previewed page cause the preview to update to the item the action has been called on? I think I've addressed most of the feedback here, thank you again! After moving the action to edit-site, I'm not sure how best to add the action to the post editor in the post-actions component. I'm not able to import the new action as it lives in a separate package. Would the action need to be duplicated? Edit: It looks like the action only needs to exist in the post editor (done in 7a2960a), so I've removed it from edit-site (it was duplicated otherwise). |
@@ -20,7 +20,7 @@ const TitleView = ( { item }: { item: BasePost } ) => { | |||
const siteSettings: Settings | undefined = getEntityRecord( | |||
'root', | |||
'site', | |||
'' |
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.
For reference, this is fixing #66940 (comment)
Ideally, this parameter should be optional. I think maybe we can make the key: EntityRecordKey
above optional?
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.
Ah yes, I think I've handled that now, in 2b37368.
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.
Nice, so does that mean we can omit the undefined
here?
}; | ||
} ); | ||
const [ currentHomePageTitle, setCurrentHomePageTitle ] = useState( null ); |
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.
Not sure I understand entirely why this local state is needed? Also, wanted to share that we now have a getHomePage
selector that returns { postType, postId }
of the current home page. If a static page is set postType will be page
otherwise it will be wp_template
// Don't show the action if the user can't manage site options. | ||
if ( ! canManageOptions ) { | ||
return false; | ||
} | ||
|
||
// A front-page template overrides homepage settings, | ||
// so don't show the setAsHomepage action if it's present. | ||
if ( hasFrontPageTemplate ) { | ||
return false; | ||
} |
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.
These two checks don't use the item. Instead of running them for every item, we can check these when registering the action.
@@ -321,7 +321,7 @@ export interface GetEntityRecord { | |||
>( | |||
kind: string, | |||
name: string, | |||
key: EntityRecordKey, | |||
key: EntityRecordKey | undefined, |
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 seems to work, and I'm not a TypeScript expert so others may want to chime in. However, I'd expect the GetEntityRecord
interface to declare the key as optional as well (as opposed to allow undefined
as a value).
What?
Adds an action to set the home page from the site editor.
Fixes #63666
Why?
Currently there is no way to change the home setting (Settings > Reading) from the site editor. This PR adds a way to do that.
How?
Adds a dataview action for pages to set the page as the site homepage that can be triggered from the pages data view.
Testing Instructions
Screenshots or screencast