-
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
Created author block. #3250
Created author block. #3250
Conversation
a9e4cc2
to
24ceba1
Compare
Codecov Report
@@ Coverage Diff @@
## master #3250 +/- ##
==========================================
- Coverage 38.49% 31.01% -7.48%
==========================================
Files 286 235 -51
Lines 6942 6545 -397
Branches 1273 1164 -109
==========================================
- Hits 2672 2030 -642
- Misses 3590 3788 +198
- Partials 680 727 +47
Continue to review full report at Codecov.
|
7dd8f34
to
fa32f34
Compare
As you came so far with this, want to fix up the issues and we can review @jorgefilipecosta ? |
fa32f34
to
ec7be13
Compare
Hi @karmatosed, I rebased this, the automated tests were failing because of a change in our mechanism. I think this is ready for a review/testing. |
blocks/library/author/index.js
Outdated
|
||
category: 'widgets', | ||
|
||
keywords: [ __( 'author' ) ], |
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.
You shouldn't need to define this keyword, since inserter search already uses the "title" field for search, and it's unlikely "Author" would be translated differently than "author".
blocks/library/author/block.js
Outdated
} ) | ||
), | ||
withAPIData( ( props ) => ( { | ||
author: `/wp/v2/users/${ props.postAuthorId }`, |
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.
We're going to have permissions issues here for non-administrator users:
I'm not sure how we'd address this.
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 is a complex problem, that probably will be faced in other blocks.
I'm seeing two possible paths:
We conclude that this information should be available in the API and we create a patch for that. To me author name, description and avatar look like information that can be public.
We conclude that this information should not be public. In this case, we need to have a mechanism to only allow the author of the post to add this block. And we need a state that shows some message like "No permissions to display this block in the editor, please use the preview to visualize this block content" when the post is being edited by a user that is not admin or post author.
blocks/library/author/index.php
Outdated
*/ | ||
function gutenberg_render_block_core_author( $attributes ) { | ||
$align = 'center'; | ||
if ( isset( $attributes['align'] ) && in_array( $attributes['align'], array( 'left', 'right', 'full' ), true ) ) { |
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.
The isset
here may be unnecessary, since we'd always assume it to be set.
blocks/single-author/style.scss
Outdated
text-align: center; | ||
} | ||
p:after { | ||
content: ""; |
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.
Tabbed too far here.
"name": "core/author", | ||
"isValid": true, | ||
"attributes": { | ||
"hideBio": 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.
Wonder why tabbing is off here, since this is generated. 🤷♂️
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.
Here in github it looks like it has wrong tabbing but I checked in the editor the tabs were right, looks like this is related with github visualization.
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's a difference of tabs and spaces. Depending on how your editor is configured, it might be showing tabs as 4 spaces, appearing aligned.
@@ -0,0 +1 @@ | |||
<!-- wp:core/author {"hideBio":true,"hideAvatar":true,"hideName":true} /--> |
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.
The wp:core/
is no longer necessary, and can be seen as stripped in the serialized version.
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 changed wp:core/author to wp:author, but unfortunately, some of our PHP tests started failing (possible to see in our CI). I probably misunderstood the change :(
editor/selectors.js
Outdated
* @param {Object} state Global application state | ||
* @return {Number} ID of post author | ||
*/ | ||
export function getCurrentPostAuthor( state ) { |
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.
Opens a question as to whether we want granular selectors for every single property of a post, or if it's reasonable to expect a developer to use getCurrentPost( state ).author
directory (or alternatively, a getCurrentPostAttribute( state, key )
selector?).
blocks/library/author/index.js
Outdated
|
||
keywords: [ __( 'author' ) ], | ||
|
||
supportHTML: 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.
This will need to be rebased per #4014
cd9423a
to
61f6d36
Compare
61f6d36
to
0466055
Compare
Can we rebase this? Just so we can review. |
export default compose( | ||
connect( | ||
( state ) => ( { | ||
postAuthorId: getEditedPostAttribute( state, 'author' ), |
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.
See also https://github.com/WordPress/gutenberg/pull/5602/files#r175522235 for a proposal where I think we could formalize the dependence on this post context via a new attribute source type.
Do we still want this open or close? |
Sorry, @karmatosed missed your ping. I think this PR is not relevant I will close. During next phases, we can reopen it. |
Description
This PR aims to add an author block, as specified in issue #1844..
Screenshots
To test
Add an author block, try to hide each of three options see the hiding attribute works as expected in the editor and when saving the post.
Try each of the alignment options verify the alignment looks ok.
Notes
The single-author component is going to be reused in author blocks.
A max-width of 50% was added when align is not center, because without the post after published does not look as in the editor and in fact, no difference is noticeable when compared to center alignment.