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

Added ability to filter latest posts by author #16169

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
32835c0
Added ability to filter latest posts by author
Jun 13, 2019
7a82c73
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
Jul 15, 2019
3d523b3
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
pstonier Oct 22, 2019
f928d9e
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
pstonier Nov 12, 2019
9a21f51
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
pstonier Apr 1, 2020
a2cf201
Updates to catch up to changes in Gutenberg
pstonier Apr 2, 2020
9e46c53
Fixes error of: Notice: Undefined index: items in /wp-includes/rest-a…
pstonier Apr 2, 2020
4218a56
Removed unused variables and fixed linting issues
pstonier Apr 2, 2020
9b6521e
Removed Whitespace from index.php
pstonier Apr 6, 2020
de5b002
adding new line to index.php
pstonier Apr 6, 2020
c3d4248
applied changes suggested by @draganescu to LatestPosts block
pstonier Apr 29, 2020
72cd7b8
linting edit
pstonier Apr 29, 2020
2f2c2c1
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
pstonier Apr 29, 2020
5dc4a4a
Updated from users to author on LatestPosts block
pstonier Apr 30, 2020
270881f
Added display author option
pstonier May 5, 2020
873c8da
Updated edit.js on LatestPosts to match front end on author label
pstonier May 5, 2020
29cdc7e
Attempt to fix tests on LatestPosts
pstonier May 6, 2020
c36a40c
Update e2e tests for LatestPostsa
pstonier May 6, 2020
da4dd59
Fix for PHP Unit tests
pstonier May 6, 2020
7449834
Updated rendering of author name on editor view
pstonier May 6, 2020
080b917
Changed 'posted by' to 'by' on the byline
pstonier May 6, 2020
916855c
Fixed linting issue in index.php for LatestPost
pstonier May 6, 2020
8ce915e
Fixed formatting issues in index.php for LatestPosts
pstonier May 6, 2020
49e87dc
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
pstonier May 28, 2020
78f742a
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
pstonier Jun 1, 2020
ead1488
fix to undefined author_info
pstonier Jun 1, 2020
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
Prev Previous commit
Next Next commit
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
…update/latest-posts-author-filter
  • Loading branch information
pstonier committed Apr 1, 2020
commit 9a21f51c4c1206b1ac654dd2df472a3101f5c1bb
102 changes: 85 additions & 17 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,70 @@ class LatestPostsEdit extends Component {
}

render() {
const { attributes, setAttributes, latestPosts } = this.props;
const { categoriesList, authorList } = this.state;
const { displayPostContentRadio, displayPostContent, displayPostDate, postLayout, columns, order, orderBy, categories, users, postsToShow, excerptLength } = attributes;

const {
attributes,
setAttributes,
imageSizeOptions,
latestPosts,
defaultImageWidth,
defaultImageHeight,
} = this.props;
const {
categoriesList,
authorList,
} = this.state;
const {
displayFeaturedImage,
displayPostContentRadio,
displayPostContent,
displayPostDate,
postLayout,
columns,
order,
orderBy,
categories,
users,
pstonier marked this conversation as resolved.
Show resolved Hide resolved
postsToShow,
excerptLength,
featuredImageAlign,
featuredImageSizeSlug,
featuredImageSizeWidth,
featuredImageSizeHeight,
} = attributes;
const suggestions = categoriesList.reduce(
( accumulator, category ) => ( {
...accumulator,
[ category.name ]: category,
} ),
{}
);
const categorySuggestions = categoriesList.reduce(
( accumulator, category ) => ( {
...accumulator,
[ category.name ]: category,
} ),
{}
);
const selectCategories = ( tokens ) => {
const hasNoSuggestion = tokens.some(
( token ) => typeof token === 'string' && ! suggestions[ token ]
);
if ( hasNoSuggestion ) {
return;
}
// Categories that are already will be objects, while new additions will be strings (the name).
// allCategories nomalizes the array so that they are all objects.
const allCategories = tokens.map( ( token ) => {
return typeof token === 'string' ? suggestions[ token ] : token;
} );
// We do nothing if the category is not selected
// from suggestions.
if ( includes( allCategories, null ) ) {
return false;
}
setAttributes( { categories: allCategories } );
};

const inspectorControls = (
<InspectorControls>
Expand Down Expand Up @@ -215,15 +276,21 @@ class LatestPostsEdit extends Component {
<QueryControls
{ ...{ order, orderBy } }
numberOfItems={ postsToShow }
categoriesList={ categoriesList }
onOrderChange={ ( value ) =>
setAttributes( { order: value } )
}
onOrderByChange={ ( value ) =>
setAttributes( { orderBy: value } )
}
onNumberOfItemsChange={ ( value ) =>
setAttributes( { postsToShow: value } )
}
authorList={ authorList }
selectedAuthorId={ users }
selectedCategoryId={ categories }
onOrderChange={ ( value ) => setAttributes( { order: value } ) }
onOrderByChange={ ( value ) => setAttributes( { orderBy: value } ) }
onAuthorChange={ ( value ) => setAttributes( { users: '' !== value ? value : undefined } ) }
onCategoryChange={ ( value ) => setAttributes( { categories: '' !== value ? value : undefined } ) }
onNumberOfItemsChange={ ( value ) => setAttributes( { postsToShow: value } ) }
categoriesList={ categoriesList }
categorySuggestions={ categorySuggestions }
onCategoryChange={ selectCategories }
selectedCategories={ categories }
/>

{ postLayout === 'grid' && (
Expand All @@ -240,7 +307,7 @@ class LatestPostsEdit extends Component {
: Math.min(
MAX_POSTS_COLUMNS,
latestPosts.length
)
)
}
required
/>
Expand Down Expand Up @@ -415,14 +482,14 @@ class LatestPostsEdit extends Component {
}

export default withSelect( ( select, props ) => {
const { postsToShow, order, orderBy, categories, users } = props.attributes;
const { getEntityRecords } = select( 'core' );
const latestPostsQuery = pickBy( {
categories,
author: users,

const {
featuredImageSizeSlug,
postsToShow,
order,
orderBy,
categories,
users,
pstonier marked this conversation as resolved.
Show resolved Hide resolved
} = props.attributes;
const { getEntityRecords, getMedia } = select( 'core' );
const { getSettings } = select( 'core/block-editor' );
Expand All @@ -434,6 +501,7 @@ export default withSelect( ( select, props ) => {
const latestPostsQuery = pickBy(
{
categories: catIds,
author: users,
pstonier marked this conversation as resolved.
Show resolved Hide resolved
order,
orderby: orderBy,
per_page: postsToShow,
Expand Down Expand Up @@ -471,6 +539,6 @@ export default withSelect( ( select, props ) => {
return { ...post, featuredImageSourceUrl: url };
}
return post;
} ),
} ),
};
} )( LatestPostsEdit );
60 changes: 6 additions & 54 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,60 +166,12 @@ function register_block_core_latest_posts() {
$metadata = json_decode( file_get_contents( $path ), true );

register_block_type(
'core/latest-posts',
array(
'attributes' => array(
'align' => array(
'type' => 'string',
'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
),
'className' => array(
'type' => 'string',
),
'categories' => array(
'type' => 'string',
),
'postsToShow' => array(
'type' => 'number',
'default' => 5,
),
'displayPostContent' => array(
'type' => 'boolean',
'default' => false,
),
'displayPostContentRadio' => array(
'type' => 'string',
'default' => 'excerpt',
),
'excerptLength' => array(
'type' => 'number',
'default' => 55,
),
'displayPostDate' => array(
'type' => 'boolean',
'default' => false,
),
'postLayout' => array(
'type' => 'string',
'default' => 'list',
),
'columns' => array(
'type' => 'number',
'default' => 3,
),
'order' => array(
'type' => 'string',
'default' => 'desc',
),
'orderBy' => array(
'type' => 'string',
'default' => 'date',
),
'users' => array(
'type' => 'string',
),
),
'render_callback' => 'render_block_core_latest_posts',
$metadata['name'],
array_merge(
$metadata,
array(
'render_callback' => 'render_block_core_latest_posts',
)
)
);
}
Expand Down
11 changes: 8 additions & 3 deletions packages/components/src/query-controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { RangeControl, SelectControl } from '../';
import { RangeControl, SelectControl, FormTokenField } from '../';
import CategorySelect from './category-select';
import AuthorSelect from './author-select';

Expand All @@ -19,6 +19,8 @@ export default function QueryControls( {
authorList,
selectedCategoryId,
selectedAuthorId,
categorySuggestions,
selectedCategories,
numberOfItems,
order,
orderBy,
Expand Down Expand Up @@ -79,7 +81,9 @@ export default function QueryControls( {
}
suggestions={ Object.keys( categorySuggestions ) }
onChange={ onCategoryChange }
/> ),
maxSuggestions={ MAX_CATEGORIES_SUGGESTIONS }
/>
),
onAuthorChange && (
<AuthorSelect
key="query-controls-author-select"
Expand All @@ -88,7 +92,8 @@ export default function QueryControls( {
noOptionLabel={ __( 'All' ) }
selectedAuthorId={ selectedAuthorId }
onChange={ onAuthorChange }
/> ),
/>
),
onNumberOfItemsChange && (
<RangeControl
key="query-controls-range-control"
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.