Skip to content

Commit

Permalink
imports lodash and reworks withSelect query
Browse files Browse the repository at this point in the history
  • Loading branch information
jomurgel committed Sep 21, 2018
1 parent c102e41 commit fa110b8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/search-edit-component/post-render.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* WordPress dependencies
*/
import { isUndefined, pickBy } from 'lodash';

const {
withSelect,
} = wp.data;
Expand Down Expand Up @@ -87,19 +89,24 @@ class PostRenderer extends Component {
}
}

export default withSelect( ( props ) => {
export default withSelect( ( select, props ) => {
const { posts } = props;
const { getEntityRecords } = select( 'core' );

if ( undefined !== posts && '[]' !== posts ) {
const selectedResultsQuery = JSON.parse( posts ).map( item => {
return `include[]=${ item.id }&orderby=include`;
return item.id;
} );

if ( 0 < selectedResultsQuery.length ) {
const selectedResultsFilter = selectedResultsQuery.join( '&' );
const postQuery = pickBy( {
_embed: 'embed',
orderby: 'include',
include: selectedResultsQuery,
} );

return {
selectedResultsJSONAlt: `/wp/v2/${ props.attributes.queryFor }?_embed&${ selectedResultsFilter }&orderby=include`,
selectedResults: getEntityRecords( 'postType', 'post', postQuery ),
};
}
}
Expand Down

0 comments on commit fa110b8

Please sign in to comment.