-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Data Views: Add action for pages to set site homepage #65426
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
Changes from 47 commits
c7101cf
585ef01
41474da
921d0f4
23cefbd
fb35be0
5de983c
0f3a986
1bdf2e0
937ad00
7df97a8
91a8275
44feed5
768f9cb
a04fb70
7462ce7
2d2c856
8bbd86d
6fc3490
341a068
b27305f
b387c34
2429d77
57eceb1
49be2ab
40568dc
489f4d6
c36e3ac
3cb07e9
9a5f4d7
c4bd9ae
46071d7
42e0791
3434c3f
e84a33e
baea572
c413a17
ba8becb
7687e3c
81b76f8
0ca96b0
17754bd
e722ceb
91de6c0
3c71533
6b2f6b9
6a1f468
b81eb1c
6d36c1b
8b40105
3caa096
d20b87b
29a1f72
0c5883a
24dcf8f
095bbe3
991ac5c
f2acc94
969ed4a
259a476
efbf96c
9de4488
5cbe7b4
7a2960a
4d45eaf
fb2ea4c
1a1f682
c10846b
5e5cf0c
2b37368
43dd85f
4cd6988
b2e88eb
953e999
f01d347
d96e90e
9685c3a
b029794
a9ea268
e438496
04a7ba4
c97a17d
0b8c27e
f8df3b9
a175adc
86af09a
10d97b7
c23c35b
b1707e4
d6a7059
a696688
6d01e34
18aeaf6
d486bac
8bacdbb
e1a7aa9
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 |
|---|---|---|
|
|
@@ -22,17 +22,39 @@ const { Menu, kebabCase } = unlock( componentsPrivateApis ); | |
|
|
||
| export default function PostActions( { postType, postId, onActionPerformed } ) { | ||
| const [ isActionsMenuOpen, setIsActionsMenuOpen ] = useState( false ); | ||
| const { item, permissions } = useSelect( | ||
| const { item, permissions, additionalContext } = useSelect( | ||
|
||
| ( select ) => { | ||
| const { getEditedEntityRecord, getEntityRecordPermissions } = | ||
| unlock( select( coreStore ) ); | ||
| const { | ||
| getEditedEntityRecord, | ||
| getEntityRecordPermissions, | ||
| getEntityRecord, | ||
| getEntityRecords, | ||
| } = unlock( select( coreStore ) ); | ||
| const site = getEntityRecord( 'root', 'site' ); | ||
| const pageOnFront = site?.page_on_front; | ||
| const pageForPosts = site?.page_for_posts; | ||
| const themeTemplates = getEntityRecords( | ||
| 'postType', | ||
| 'wp_template', | ||
| { | ||
| per_page: -1, | ||
| } | ||
| ); | ||
| const hasFrontPageTemplate = !! themeTemplates?.find( | ||
| ( template ) => | ||
| 'slug' in template && template.slug === 'front-page' | ||
| ); | ||
| return { | ||
| item: getEditedEntityRecord( 'postType', postType, postId ), | ||
| permissions: getEntityRecordPermissions( | ||
| 'postType', | ||
| postType, | ||
| postId | ||
| ), | ||
| additionalContext: { | ||
| siteSettings: { pageOnFront, pageForPosts }, | ||
| themeInfo: { hasFrontPageTemplate }, | ||
| }, | ||
| }; | ||
| }, | ||
| [ postId, postType ] | ||
|
|
@@ -41,8 +63,9 @@ export default function PostActions( { postType, postId, onActionPerformed } ) { | |
| return { | ||
| ...item, | ||
| permissions, | ||
| additionalContext, | ||
| }; | ||
| }, [ item, permissions ] ); | ||
| }, [ item, permissions, additionalContext ] ); | ||
| const allActions = usePostActions( { postType, onActionPerformed } ); | ||
|
|
||
| const actions = useMemo( () => { | ||
|
|
@@ -123,7 +146,7 @@ function ActionWithModal( { action, item, ActionTrigger, onClose } ) { | |
| action.id | ||
| ) }` } | ||
| focusOnMount="firstContentElement" | ||
| size="small" | ||
| size="medium" | ||
| > | ||
| <RenderModal | ||
| items={ [ item ] } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ import { | |||||
| exportPattern, | ||||||
| permanentlyDeletePost, | ||||||
| restorePost, | ||||||
| setAsHomepage, | ||||||
| trashPost, | ||||||
| renamePost, | ||||||
| resetPost, | ||||||
|
|
@@ -87,6 +88,14 @@ export const registerPostTypeActions = | |||||
| kind: 'postType', | ||||||
| name: postType, | ||||||
| } ); | ||||||
|
|
||||||
| const canManageOptions = await registry | ||||||
| .resolveSelect( coreStore ) | ||||||
| .canUser( 'update', { | ||||||
| kind: 'root', | ||||||
| name: 'site', | ||||||
| } ); | ||||||
|
|
||||||
| const currentTheme = await registry | ||||||
| .resolveSelect( coreStore ) | ||||||
| .getCurrentTheme(); | ||||||
|
|
@@ -113,6 +122,9 @@ export const registerPostTypeActions = | |||||
| ? duplicatePattern | ||||||
| : undefined, | ||||||
| postTypeConfig.supports?.title ? renamePost : undefined, | ||||||
| canManageOptions && postTypeConfig.slug === 'page' | ||||||
|
||||||
| Site editor | Posts editor |
|---|---|
![]() |
![]() |
It turns out to be that the canManageOptions check is undefined for the post editor. Would you know why is that?
Checked a few things and:
- the
canCreatecheck works fine in the post editor - the
canManageOptionsis actually resolved when using the post editor to edit apost(not apage)
🤔
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.
While duplicating the action for the post editor, I've managed to get the new homepage action to show so hopefully that gets around the canManageOptions check being undefined, but getEntityRecord( 'postType', 'page', [pageId] ) doesn't seem to work in this editor. I'm not sure why, it's like the editor only has access to the current page that's being edited.
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 think I've figured out a way to handle getting the current homepage in every context (page list, site editor and post editor). I'm not sure if it's the best way, but it seems to be working. I think the record was being checked too soon, so I've wrapped it in a useEffect in 5e5cf0c.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| type PostStatus = | ||
| | 'published' | ||
|
Member
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 just realized we had this in the editor that we also have in the |
||
| | 'publish' | ||
| | 'draft' | ||
| | 'pending' | ||
| | 'private' | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.