Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page List: Show empty placeholder if no items #35441

Merged
merged 4 commits into from Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/block-library/src/page-list/edit.js
Expand Up @@ -13,7 +13,7 @@ import {
getColorClassName,
} from '@wordpress/block-editor';
import ServerSideRender from '@wordpress/server-side-render';
import { ToolbarButton } from '@wordpress/components';
import { Placeholder, ToolbarButton } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useEffect, useState } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
Expand All @@ -29,6 +29,10 @@ import ConvertToLinksModal from './convert-to-links-modal';
// Performance of Navigation Links is not good past this value.
const MAX_PAGE_COUNT = 100;

const EmptyResponsePlaceholder = () => (
<Placeholder label={ __( 'No pages to show.' ) } />
);

export default function PageListEdit( {
context,
clientId,
Expand Down Expand Up @@ -154,6 +158,7 @@ export default function PageListEdit( {
<ServerSideRender
block="core/page-list"
attributes={ attributesWithParentStatus }
EmptyResponsePlaceholder={ EmptyResponsePlaceholder }
/>
</div>
</>
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/page-list/index.php
Expand Up @@ -281,6 +281,12 @@ function render_block_core_page_list( $attributes, $content, $block ) {
}
}

// If thare are no top level pages, there is nothing to show.
// Return early and empty to trigger EmptyResponsePlaceholder.
if ( empty( $top_level_pages ) ) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could return even earlier if we instead checked $all_pages above.


$colors = block_core_page_list_build_css_colors( $attributes, $block->context );
$font_sizes = block_core_page_list_build_css_font_sizes( $block->context );
$classes = array_merge(
Expand Down