Skip to content
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

Post Author block: Hide select author controle if there is no postId #40910

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions packages/block-library/src/post-author/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,30 @@ function PostAuthorEdit( {
<>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
{ ! isDescendentOfQueryLoop && !! authors?.length && (
<SelectControl
label={ __( 'Author' ) }
value={ authorId }
options={ authors.map( ( { id, name } ) => {
return {
value: id,
label: name,
};
} ) }
onChange={ ( nextAuthorId ) => {
editEntityRecord(
'postType',
postType,
postId,
{
author: nextAuthorId,
}
);
} }
/>
) }
{ !! postId &&
! isDescendentOfQueryLoop &&
!! authors?.length && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do both !! postId and ! isDescendentOfQueryLoop need to be checked?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the ! isDescendentOfQueryLoop and run some tests and everything seems to be fine. But are we sure that _ isDescendentOfQueryLoop_ will be false each time when _ postId_ will be defined? is there a way to confirm that? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does postId get passed via context to author blocks in query loops when the query loop is in a post? if it does then we need to keep ! isDescendentOfQueryLoop otherwise no.

<SelectControl
label={ __( 'Author' ) }
value={ authorId }
options={ authors.map( ( { id, name } ) => {
return {
value: id,
label: name,
};
} ) }
onChange={ ( nextAuthorId ) => {
editEntityRecord(
'postType',
postType,
postId,
{
author: nextAuthorId,
}
);
} }
/>
) }
<ToggleControl
label={ __( 'Show avatar' ) }
checked={ showAvatar }
Expand Down