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

Add Latest Comments block. #7369

Closed
wants to merge 20 commits into from

Conversation

miina
Copy link
Contributor

@miina miina commented Jun 19, 2018

Description

Fixes #1792. Note that this PR is based on #1931.

Adds Latest Comments block v1 using ServerSideRender component.
Allows configuring the following:

  • Number of comments displayed;
  • Comment excerpt to be shown;
  • Permit avatar to be shown;
  • Permit timestamps to be shown.

Screenshots

Editor view:
screen shot 2018-06-19 at 3 36 03 pm
Frontend view:
screen shot 2018-06-19 at 3 36 26 pm

Checklist:

  • My code is tested functionally.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.

@miina
Copy link
Contributor Author

miina commented Jun 19, 2018

@melchoyce Here is a video of the Latest Comments block, let me know if you have any concerns about the design:
https://www.dropbox.com/s/dfqt2ixcd8w0oga/latest-comments.mov?dl=0

/>
</BlockControls>
<InspectorControls key="inspector">
<h3>{ __( 'Latest Comments Settings' ) }</h3>
Copy link
Member

Choose a reason for hiding this comment

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

<PanelBody title={ __( 'Latest Comments Settings' ) }> like in latest-posts looks a little bit nicer.

@karmatosed
Copy link
Member

@miina there seems to be some issue running this. I can't find it in the block library for example. Totally may be something to do with me though. That said, thanks for the video and looking at it there are a few visual issues when the formatting for example right aligns.

2018-06-20 at 12 28

Could you please ensure visually it looks a little more like the mocks here? For example spacing and font sizes.

2018-06-20 at 12 38

@miina
Copy link
Contributor Author

miina commented Jun 21, 2018

@karmatosed Thanks for checking the video and for the comments.

I can't find it in the block library for example.

Do you mean that it doesn't show up in the editor blocks? It should be under widgets, let me know if that's not what you meant.
screen shot 2018-06-21 at 3 32 24 pm

Adjusted the style, here are screenshots with different configuration, let me know if we should make more adjustments:

  • Comments with just the excerpt:
    screen shot 2018-06-21 at 3 31 01 pm

  • Comments with date, avatar:
    screen shot 2018-06-21 at 3 31 21 pm

  • Comments with date, avatar, time:
    screen shot 2018-06-21 at 3 31 29 pm

  • Right aligned comments:
    screen shot 2018-06-21 at 3 36 47 pm

@karmatosed
Copy link
Member

Thanks @miina. I have a little design review and once that's done we can look to get this in.

First, when a data isn't show would it be possible to centre the text over have the gap underneath?

2018-06-22 at 21 01

Where there is an excerpt there seems too much padding on name but too small line height when the line wraps:

2018-06-22 at 21 02

Possibly could we have more space below each comment?

2018-06-22 at 21 03

Can the 'number of comments' be a smaller input and on the same line as the label?

2018-06-22 at 21 04

@miina
Copy link
Contributor Author

miina commented Jun 23, 2018

@karmatosed Thanks for the additional feedback. Made some adjustments and also replaced the text control with range control, the same way as Latest Posts block is using the number of items to display:
screen shot 2018-06-23 at 12 06 34 pm

@karmatosed
Copy link
Member

This is looking really close to being done @miina. Just one thing I noticed:

2018-07-01 at 16 15

Should the date clear?

@miina
Copy link
Contributor Author

miina commented Jul 2, 2018

@karmatosed Made some changes, hopefully it works as expected now.

Copy link
Member

@karmatosed karmatosed left a comment

Choose a reason for hiding this comment

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

Thanks for all the changes and your hard work on this @miina. It was a pleasure working through the process with you.

@karmatosed karmatosed requested a review from gziolo July 3, 2018 21:28
@miina
Copy link
Contributor Author

miina commented Jul 5, 2018

For information that I'm going to be mostly offline from the 6th until the end of July -- if any changes would be necessary meanwhile to have the PR merged anyone is welcome to pick it up.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

I left my feedback. I didn't find any bigger issues, mostly regular feedback to ensure code consistency. Let me know if you have any questions.

const MIN_COMMENTS = 1;
const MAX_COMMENTS = 100;

class latestComments extends Component {
Copy link
Member

Choose a reason for hiding this comment

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

It should start with the upper-case. We are adding missing docs for this to make it more formal. See #7670.


return (
<Fragment>
<BlockControls key="controls">
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to add key prop when you use Fragment component wrapper.

controls={ [ 'left', 'center', 'right', 'wide', 'full' ] }
/>
</BlockControls>
<InspectorControls key="inspector">
Copy link
Member

Choose a reason for hiding this comment

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

key should be removed. See above.

/>
</BlockControls>
<InspectorControls key="inspector">
<PanelBody title={ __( 'Latest Comments Settings' ) } />
Copy link
Member

Choose a reason for hiding this comment

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

I guess that in this case PanelBody should wrap all controls like it happens in other blocks.

/>

</InspectorControls>
<ServerSideRender key="latest-comments" block="core/latest-comments" attributes={ this.props.attributes } />
Copy link
Member

Choose a reason for hiding this comment

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

key should be removed. See above.


register_block_type( 'core/latest-comments', array(
'attributes' => array(
'className' => array(
Copy link
Member

Choose a reason for hiding this comment

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

I see some differences between default values here and those specified in defaultAttributes which I commented about before. Those values get propagated from the server to the client, so should be treated as a source of truth.

.wp-block-latest-comments {
padding-left: 2.5em;

&__comment-timestamp {
Copy link
Member

Choose a reason for hiding this comment

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

wp-block-latest-comments __comment-timestamp should be moved to top level as its own definition. It should be also consolidated with rules from lines 23-26.

}
}

.wp-block-latest-comments > li {
Copy link
Member

Choose a reason for hiding this comment

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

We have styles for the same element in line 10, they should be consolidated there.

padding-top: 8px;
}

.wp-block-latest-comments__comment-excerpt p {
Copy link
Member

Choose a reason for hiding this comment

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

Those styles should be also moved to top level. In general, there is no need to nest classes which use the same pattern.

margin: 5px 0 20px;
}

.recentcomments {
Copy link
Member

Choose a reason for hiding this comment

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

Is recentcomments something that is named for backward compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing to latestcomments, was not intentional.

@gziolo gziolo added this to the 3.3 milestone Jul 5, 2018
@gziolo gziolo added [Feature] Blocks Overall functionality of blocks [Type] Task Issues or PRs that have been broken down into an individual action to take labels Jul 5, 2018
@tofumatt tofumatt self-assigned this Jul 10, 2018
Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

I just checked this out and took it for a spin locally: the UX seems good and I think I just have a few tweaks to make before we get this merged.

The only thing to note here is that if a large number of comments are enabled, the block grows extremely large in size, eg:

2018-07-11 03 08 17

Even with just six comments, it's a pretty big block:

screenshot 2018-07-11 03 08 38

I think the appropriate behaviour here should be to show maybe 3-5 comments in full, and then a footer on the element in the editor with a "30 more…" or whatever. It could even be clickable to expand all of the comments, but it shouldn't show them by default.

Gutenberg isn't WYSIWYG, and showing a huge list of comments in the editor window isn't useful.

I'm gonna head to bed but I'll push changes in the morning–assuming it's nothing major (eg just style stuff or little tweaks) I'll get this merged and file a follow-up to the issue of a large number of comments in the editor.

@gziolo
Copy link
Member

gziolo commented Jul 11, 2018

The only thing to note here is that if a large number of comments are enabled, the block grows extremely large in size, eg:

I think the appropriate behaviour here should be to show maybe 3-5 comments in full, and then a footer on the element in the editor with a "30 more…" or whatever. It could even be clickable to expand all of the comments, but it shouldn't show them by default.

@karmatosed, any recommendations on how to tackle it?

onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
controls={ [ 'left', 'center', 'right', 'wide', 'full' ] }
Copy link
Member

Choose a reason for hiding this comment

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

I think those are default values and can be omitted in here.

Copy link
Member

Choose a reason for hiding this comment

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

yes, confirmed:

const DEFAULT_CONTROLS = [ 'left', 'center', 'right', 'wide', 'full' ];

}

toggleHandler( propName ) {
return () => {
Copy link
Member

@gziolo gziolo Jul 11, 2018

Choose a reason for hiding this comment

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

Ideally, this arrow function should be promoted to a class method and bind to this instead of toggleHandler to avoid unnecessary rerenders.

I'd have to think how to code it differently :)

Copy link
Member

Choose a reason for hiding this comment

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

In this case the whole element re-renders from server-side data though, right? 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

Wait, scratch that, I see. I think for now it's okay as we use this pattern elsewhere in the codebase, but if it's a performance issue we could see about fixing it everywhere. I'm afraid I've recommended this in the past, not realising the potential for unneeded re-renders...

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I saw it in other places, too. I don't think this is a big issue for leaf components. However, it's something we should try to avoid whenever it doesn't cause too much work.

),
'align' => array(
'type' => 'string',
'default' => 'center',
Copy link
Member

Choose a reason for hiding this comment

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

This was causing blocks with unset alignment to look centre aligned on a new page load. I'll remove it and the default assignment to centre-alignment above.


getEditWrapperProps( attributes ) {
const { align } = attributes;
if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't actually include "center", which caused a bug:

screenshot 2018-07-12 12 26 51

I have a fix incoming which actually DRYs this up a bit too:

screenshot 2018-07-12 12 27 25

@tofumatt tofumatt mentioned this pull request Jul 12, 2018
3 tasks
@aduth
Copy link
Member

aduth commented Jul 18, 2018

Can this be closed in favor of #7941 ?

@tofumatt
Copy link
Member

Yes.

@tofumatt tofumatt closed this Jul 18, 2018
tofumatt added a commit that referenced this pull request Jul 19, 2018
Add a block that shows a range of the latest comments.

Fixes #1792
See: #7369, #1931
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants