Skip to content

Commit

Permalink
Issue WordPress#13618 - only request three fields: id, title and pare…
Browse files Browse the repository at this point in the history
…nt to populate the Parent page select list (WordPress#23637)

Co-authored-by: Riad Benguella <benguella@gmail.com>
  • Loading branch information
bobbingwide and youknowriad authored Aug 26, 2020
1 parent e7b42e4 commit a36b3dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,24 @@ export function* getEntityRecords( kind, name, query = {} ) {
...query,
context: 'edit',
} );
const records = yield apiFetch( { path } );
yield receiveEntityRecords( kind, name, Object.values( records ), query );

let records = Object.values( yield apiFetch( { path } ) );
// If we request fields but the result doesn't contain the fields,
// explicitely set these fields as "undefined"
// that way we consider the query "fullfilled".
if ( query._fields ) {
records = records.map( ( record ) => {
query._fields.split( ',' ).forEach( ( field ) => {
if ( ! record.hasOwnProperty( field ) ) {
record[ field ] = undefined;
}
} );

return record;
} );
}

yield receiveEntityRecords( kind, name, records, query );
}

getEntityRecords.shouldInvalidate = ( action, kind, name ) => {
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/page-attributes/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const applyWithSelect = withSelect( ( select ) => {
parent_exclude: postId,
orderby: 'menu_order',
order: 'asc',
_fields: 'id,title,parent',
};

return {
Expand Down

0 comments on commit a36b3dd

Please sign in to comment.