Skip to content

Commit

Permalink
Latest Comments block: use align supports flag + code cleanup (#11411)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill authored and gziolo committed Mar 11, 2019
1 parent 23ffc00 commit 6d81e2a
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 41 deletions.
22 changes: 3 additions & 19 deletions packages/block-library/src/latest-comments/edit.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
/**
* WordPress dependencies
*/
import { Component, Fragment } from '@wordpress/element';
import { InspectorControls } from '@wordpress/block-editor';
import {
Disabled,
PanelBody,
RangeControl,
ToggleControl,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import {
InspectorControls,
BlockAlignmentToolbar,
BlockControls,
} from '@wordpress/block-editor';
import { ServerSideRender } from '@wordpress/editor';
import { Component, Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
* Minimum number of comments a user can show using this block.
Expand All @@ -33,7 +29,6 @@ class LatestComments extends Component {
constructor() {
super( ...arguments );

this.setAlignment = this.setAlignment.bind( this );
this.setCommentsToShow = this.setCommentsToShow.bind( this );

// Create toggles for each attribute; we create them here rather than
Expand All @@ -53,17 +48,12 @@ class LatestComments extends Component {
};
}

setAlignment( align ) {
this.props.setAttributes( { align } );
}

setCommentsToShow( commentsToShow ) {
this.props.setAttributes( { commentsToShow } );
}

render() {
const {
align,
commentsToShow,
displayAvatar,
displayDate,
Expand All @@ -72,12 +62,6 @@ class LatestComments extends Component {

return (
<Fragment>
<BlockControls>
<BlockAlignmentToolbar
value={ align }
onChange={ this.setAlignment }
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Latest Comments Settings' ) }>
<ToggleControl
Expand Down
13 changes: 2 additions & 11 deletions packages/block-library/src/latest-comments/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { G, Path, SVG } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -23,19 +23,10 @@ export const settings = {
keywords: [ __( 'recent comments' ) ],

supports: {
align: true,
html: false,
},

getEditWrapperProps( attributes ) {
const { align } = attributes;

// TODO: Use consistent values across the app;
// see: https://github.com/WordPress/gutenberg/issues/7908.
if ( [ 'left', 'center', 'right', 'wide', 'full' ].includes( align ) ) {
return { 'data-align': align };
}
},

edit,

save() {
Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/latest-comments/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ function render_block_core_latest_comments( $attributes = array() ) {
'core/latest-comments',
array(
'attributes' => array(
'align' => array(
'type' => 'string',
'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
),
'className' => array(
'type' => 'string',
),
Expand All @@ -175,10 +179,6 @@ function render_block_core_latest_comments( $attributes = array() ) {
'type' => 'boolean',
'default' => true,
),
'align' => array(
'type' => 'string',
'enum' => array( 'center', 'left', 'right', 'wide', 'full', '' ),
),
),
'render_callback' => 'render_block_core_latest_comments',
)
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/fixtures/blocks/core__rss.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:rss {"blockLayout":"grid","feedURL":"https://wordpress.org/news/","itemsToShow":4,"displayExcerpt":true,"displayAuthor":true,"displayDate":true,"excerptLength":20} /-->
<!-- wp:rss {"blockLayout":"grid","displayDate":true,"displayExcerpt":true,"displayAuthor":true,"excerptLength":20,"feedURL":"https://wordpress.org/news/","itemsToShow":4} /-->
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:rss {"blockLayout":"grid","feedURL":"https://wordpress.org/news/","itemsToShow":4,"displayExcerpt":true,"displayAuthor":true,"displayDate":true,"excerptLength":20} /-->
<!-- wp:rss {"blockLayout":"grid","displayAuthor":true,"displayDate":true,"displayExcerpt":true,"excerptLength":20,"feedURL":"https://wordpress.org/news/","itemsToShow":4} /-->
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:search {"label":"Custom label","placeholder":"Custom placeholder","buttonText":"Custom button text"} /-->
<!-- wp:search {"buttonText":"Custom button text","label":"Custom label","placeholder":"Custom placeholder"} /-->
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:search {"label":"Custom label","placeholder":"Custom placeholder","buttonText":"Custom button text"} /-->
<!-- wp:search {"buttonText":"Custom button text","label":"Custom label","placeholder":"Custom placeholder"} /-->
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:tag-cloud {"taxonomy":"category","showTagCounts":true} /-->
<!-- wp:tag-cloud {"showTagCounts":true,"taxonomy":"category"} /-->
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:tag-cloud {"taxonomy":"category","showTagCounts":true} /-->
<!-- wp:tag-cloud {"showTagCounts":true,"taxonomy":"category"} /-->
2 changes: 1 addition & 1 deletion test/integration/full-content/server-registered.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/calendar":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"month":{"type":"integer"},"year":{"type":"integer"}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/rss":{"attributes":{"columns":{"type":"number","default":2},"blockLayout":{"type":"string","default":"list"},"feedURL":{"type":"string","default":""},"itemsToShow":{"type":"number","default":5},"displayExcerpt":{"type":"boolean","default":false},"displayAuthor":{"type":"boolean","default":false},"displayDate":{"type":"boolean","default":false},"excerptLength":{"type":"number","default":55}}},"core\/search":{"attributes":{"label":{"type":"string","default":"Search"},"placeholder":{"type":"string","default":""},"buttonText":{"type":"string","default":"Search"}}},"core\/tag-cloud":{"attributes":{"taxonomy":{"type":"string","default":"post_tag"},"className":{"type":"string"},"showTagCounts":{"type":"boolean","default":false},"align":{"type":"string"}}}}
{"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/calendar":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"month":{"type":"integer"},"year":{"type":"integer"}}},"core\/latest-comments":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/rss":{"attributes":{"blockLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":2},"displayAuthor":{"type":"boolean","default":false},"displayDate":{"type":"boolean","default":false},"displayExcerpt":{"type":"boolean","default":false},"excerptLength":{"type":"number","default":55},"feedURL":{"type":"string","default":""},"itemsToShow":{"type":"number","default":5}}},"core\/search":{"attributes":{"buttonText":{"type":"string","default":"Search"},"label":{"type":"string","default":"Search"},"placeholder":{"type":"string","default":""}}},"core\/tag-cloud":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"showTagCounts":{"type":"boolean","default":false},"taxonomy":{"type":"string","default":"post_tag"}}}}

0 comments on commit 6d81e2a

Please sign in to comment.