Skip to content

Commit

Permalink
Parent page: used exclude and parent_exclude in API requests instead …
Browse files Browse the repository at this point in the history
…of client side filtering.

This avoids requesting unnecessary posts in the request.
  • Loading branch information
jorgefilipecosta committed Jan 5, 2018
1 parent 91a1a3b commit c6cdbb8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions editor/components/page-attributes/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import { TermTreeSelect } from '@wordpress/blocks';
import { getCurrentPostId, getEditedPostAttribute, getCurrentPostType } from '../../store/selectors';
import { editPost } from '../../store/actions';

export function PageAttributesParent( { parent, postId, postType, items, onUpdateParent } ) {
export function PageAttributesParent( { parent, postType, items, onUpdateParent } ) {
const isHierarchical = get( postType, 'data.hierarchical', false );
const parentPageLabel = get( postType, 'data.labels.parent_item_colon' );
const pageItems = get( items, 'data', [] );
if ( ! isHierarchical || ! parentPageLabel || ! pageItems.length ) {
return null;
}

const pagesTree = buildTermsTree( pageItems.filter( item => item.id !== postId ).map( ( item ) => ( {
const pagesTree = buildTermsTree( pageItems.map( ( item ) => ( {
id: item.id,
parent: item.parent,
name: item.title.raw ? item.title.raw : `#${ item.id } (${ __( 'no title' ) })`,
Expand Down Expand Up @@ -67,11 +67,13 @@ const applyWithAPIDataPostType = withAPIData( ( props ) => {
} );

const applyWithAPIDataItems = withAPIData( ( props, { type } ) => {
const { postTypeSlug } = props;
const { postTypeSlug, postId } = props;
const isHierarchical = get( props, 'postType.data.hierarchical', false );
const queryString = stringify( {
context: 'edit',
per_page: 100,
exclude: postId,
parent_exclude: postId,
_fields: [ 'id', 'parent', 'title' ],
} );
return isHierarchical ? { items: `/wp/v2/${ type( postTypeSlug ) }?${ queryString }` } : {};
Expand Down

0 comments on commit c6cdbb8

Please sign in to comment.