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

Off Canvas Navigation Editor: Add Convert To Links Modal #45984

Closed
wants to merge 27 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Hide edit button from non-automenus
  • Loading branch information
George Hotelling committed Nov 22, 2022
commit 430fe3e265284838caea7df1a98a08c14f183289
Original file line number Diff line number Diff line change
@@ -11,13 +11,39 @@ import { useDispatch } from '@wordpress/data';
import { store as blockEditorStore } from '../../store';

const BlockEditButton = ( { label, clientId } ) => {
const { selectBlock } = useDispatch( blockEditorStore );
const { toggleBlockHighlight } = useDispatch( blockEditorStore );
const [ convertModalOpen, setConvertModalOpen ] = useState( false );
const { totalPages } = usePageData();
const MAX_PAGE_COUNT = 100;

const block = useSelect(
( select ) => {
return select( blockEditorStore ).getBlock( clientId );
},
[ clientId ]
);

const onClick = () => {
selectBlock( clientId );
georgeh marked this conversation as resolved.
Show resolved Hide resolved
toggleBlockHighlight( clientId, true );
setConvertModalOpen( ! convertModalOpen );
};

return <Button icon={ edit } label={ label } onClick={ onClick } />;
const allowConvertToLinks =
'core/page-list' === block.name && totalPages <= MAX_PAGE_COUNT;

return (
<>
{ convertModalOpen && (
<ConvertToLinksModal
onClose={ () => setConvertModalOpen( false ) }
clientId={ clientId }
/>
) }
{ allowConvertToLinks && (
<Button icon={ edit } label={ label } onClick={ onClick } />
) }
</>
);
};

export default BlockEditButton;