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: add convert panel to Inspector Controls when within Nav block #46352

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions packages/block-library/src/page-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ import {
Spinner,
Notice,
ComboboxControl,
Button,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { useMemo, useState, useEffect } from '@wordpress/element';
import { useEntityRecords } from '@wordpress/core-data';
import { useDispatch } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import ConvertToLinksModal from './convert-to-links-modal';
import ConvertToLinksModal, {
convertSelectedBlockToNavigationLinks,
} from './convert-to-links-modal';

// We only show the edit option when page count is <= MAX_PAGE_COUNT
// Performance of Navigation Links is not good past this value.
Expand Down Expand Up @@ -173,9 +176,50 @@ export default function PageListEdit( {
}
}, [ clientId, blockList ] );

const { replaceBlock, selectBlock } = useDispatch( blockEditorStore );

const { parentNavBlockClientId } = useSelect( ( select ) => {
const { getSelectedBlockClientId, getBlockParentsByBlockName } =
select( blockEditorStore );

const _selectedBlockClientId = getSelectedBlockClientId();

return {
parentNavBlockClientId: getBlockParentsByBlockName(
_selectedBlockClientId,
'core/navigation',
true
)[ 0 ],
};
}, [] );

return (
<>
<InspectorControls>
{ isNavigationChild && (
<PanelBody title={ __( 'Customize this menu' ) }>
<p id={ 'wp-block-page-list-modal__description' }>
{ __(
'This menu is automatically kept in sync with pages on your site. You can manage the menu yourself by clicking customize below.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth extracting this paragraph to a shared component, so that we only have one copy?

) }
</p>
<Button
variant="primary"
disabled={ ! hasResolvedPages }
onClick={ () => {
convertSelectedBlockToNavigationLinks( {
pages,
replaceBlock,
clientId,
createBlock,
} )();
selectBlock( parentNavBlockClientId );
} }
>
{ __( 'Customize' ) }
</Button>
</PanelBody>
) }
<PanelBody>
{ parentOptions && (
<ComboboxControl
Expand Down