/** * External dependencies */ import { isUndefined, pickBy } from 'lodash'; /** * WordPress dependencies */ import { registerBlockType } from '@wordpress/blocks'; import getEditComponent from './getEditComponent'; import { withSelect } from '@wordpress/data'; import { Path, SVG } from '@wordpress/components'; const name = 'advanced-posts-blocks/post'; const edit = getEditComponent( name ); registerBlockType( name, { title: ' Single Post (Advanced Posts Blocks)', icon: ( //https://material.io/tools/icons/?icon=description&style=outline ), category: 'widgets', supports: { html: false, }, edit: withSelect( ( select, props ) => { const { attributes } = props; const { postType: postTypeName } = attributes; const { getEntityRecords, getPostType, getPostTypes } = select( 'core' ); const postTypes = getPostTypes( { per_page: -1 } ) || []; const selectedPostType = getPostType( postTypeName ) || {}; const PostsQuery = pickBy( { per_page: -1, advanced_posts_blocks: true, }, ( value ) => ! isUndefined( value ) ); return { posts: getEntityRecords( 'postType', selectedPostType.slug, PostsQuery ) || [], selectedPostType, postTypes: postTypes .filter( postType => postType.viewable ) .filter( postType => postType.rest_base !== 'media' ), }; } )( edit ), save() { return null; }, } );