Skip to content

Commit

Permalink
Allow direct selection of nested Page List block by avoiding dual ren…
Browse files Browse the repository at this point in the history
…dering within block (#45143)

* Fix dual rendering within Page List

* refactor the content of the block to a function

Co-authored-by: Ben Dwyer <ben@scruffian.com>
  • Loading branch information
2 people authored and ockham committed Oct 25, 2022
1 parent 0151e3d commit 7061258
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions packages/block-library/src/page-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,50 +52,64 @@ export default function PageListEdit( { context, clientId } ) {
style: { ...context.style?.color },
} );

return (
<>
{ allowConvertToLinks && (
<BlockControls group="other">
<ToolbarButton title={ __( 'Edit' ) } onClick={ openModal }>
{ __( 'Edit' ) }
</ToolbarButton>
</BlockControls>
) }
{ allowConvertToLinks && isOpen && (
<ConvertToLinksModal
onClose={ closeModal }
clientId={ clientId }
/>
) }
{ ! hasResolvedPages && (
const getBlockContent = () => {
if ( ! hasResolvedPages ) {
return (
<div { ...blockProps }>
<Spinner />
</div>
) }
);
}

{ hasResolvedPages && totalPages === null && (
if ( totalPages === null ) {
return (
<div { ...blockProps }>
<Notice status={ 'warning' } isDismissible={ false }>
{ __( 'Page List: Cannot retrieve Pages.' ) }
</Notice>
</div>
) }
);
}

{ totalPages === 0 && (
if ( totalPages === 0 ) {
return (
<div { ...blockProps }>
<Notice status={ 'info' } isDismissible={ false }>
{ __( 'Page List: Cannot retrieve Pages.' ) }
</Notice>
</div>
) }
{ totalPages > 0 && (
);
}

if ( totalPages > 0 ) {
return (
<ul { ...blockProps }>
<PageItems
context={ context }
pagesByParentId={ pagesByParentId }
/>
</ul>
);
}
};

return (
<>
{ allowConvertToLinks && (
<BlockControls group="other">
<ToolbarButton title={ __( 'Edit' ) } onClick={ openModal }>
{ __( 'Edit' ) }
</ToolbarButton>
</BlockControls>
) }
{ allowConvertToLinks && isOpen && (
<ConvertToLinksModal
onClose={ closeModal }
clientId={ clientId }
/>
) }

{ getBlockContent() }
</>
);
}
Expand Down

0 comments on commit 7061258

Please sign in to comment.