Skip to content

Commit f596d2e

Browse files
committed
open convert to links modal on select of a page item
1 parent dbe47a5 commit f596d2e

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

packages/block-library/src/page-list-item/edit.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* External dependencies
33
*/
44
import classnames from 'classnames';
5-
65
/**
76
* WordPress dependencies
87
*/
8+
import { useEffect } from '@wordpress/element';
99
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
1010
import { useSelect } from '@wordpress/data';
1111
import { store as coreStore } from '@wordpress/core-data';
@@ -35,7 +35,12 @@ function useFrontPageId() {
3535
}, [] );
3636
}
3737

38-
export default function PageListItemEdit( { context, attributes } ) {
38+
export default function PageListItemEdit( {
39+
context,
40+
attributes,
41+
isSelected,
42+
setAttributes,
43+
} ) {
3944
const { id, label, link, hasChildren } = attributes;
4045
const isNavigationChild = 'showSubmenuIcon' in context;
4146
const frontPageId = useFrontPageId();
@@ -50,6 +55,12 @@ export default function PageListItemEdit( { context, attributes } ) {
5055

5156
const innerBlocksProps = useInnerBlocksProps( blockProps );
5257

58+
useEffect( () => {
59+
if ( isSelected ) {
60+
setAttributes( { isSelected: true } );
61+
}
62+
}, [ isSelected ] );
63+
5364
return (
5465
<li
5566
key={ id }

packages/block-library/src/page-list/edit.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -113,36 +113,16 @@ function BlockContent( {
113113
}
114114
}
115115

116-
function ConvertToLinks( { onClick, disabled } ) {
117-
const [ isOpen, setOpen ] = useState( false );
118-
const openModal = () => setOpen( true );
119-
const closeModal = () => setOpen( false );
120-
121-
return (
122-
<>
123-
<BlockControls group="other">
124-
<ToolbarButton title={ __( 'Edit' ) } onClick={ openModal }>
125-
{ __( 'Edit' ) }
126-
</ToolbarButton>
127-
</BlockControls>
128-
{ isOpen && (
129-
<ConvertToLinksModal
130-
onClick={ onClick }
131-
onClose={ closeModal }
132-
disabled={ disabled }
133-
/>
134-
) }
135-
</>
136-
);
137-
}
138-
139116
export default function PageListEdit( {
140117
context,
141118
clientId,
142119
attributes,
143120
setAttributes,
144121
} ) {
145122
const { parentPageID } = attributes;
123+
const [ isOpen, setOpen ] = useState( false );
124+
const openModal = () => setOpen( true );
125+
const closeModal = () => setOpen( false );
146126

147127
const { records: pages, hasResolved: hasResolvedPages } = useEntityRecords(
148128
'postType',
@@ -269,7 +249,11 @@ export default function PageListEdit( {
269249
__unstableDisableDropZone: true,
270250
templateLock: 'all',
271251
onInput: NOOP,
272-
onChange: NOOP,
252+
onChange: () => {
253+
if ( hasResolvedPages ) {
254+
openModal();
255+
}
256+
},
273257
value: blockList,
274258
} );
275259

@@ -325,10 +309,23 @@ export default function PageListEdit( {
325309
) }
326310
</InspectorControls>
327311
{ allowConvertToLinks && (
328-
<ConvertToLinks
329-
disabled={ ! hasResolvedPages }
330-
onClick={ convertToNavigationLinks }
331-
/>
312+
<>
313+
<BlockControls group="other">
314+
<ToolbarButton
315+
title={ __( 'Edit' ) }
316+
onClick={ openModal }
317+
>
318+
{ __( 'Edit' ) }
319+
</ToolbarButton>
320+
</BlockControls>
321+
{ isOpen && (
322+
<ConvertToLinksModal
323+
onClick={ convertToNavigationLinks }
324+
onClose={ closeModal }
325+
disabled={ ! hasResolvedPages }
326+
/>
327+
) }
328+
</>
332329
) }
333330
<BlockContent
334331
blockProps={ blockProps }

0 commit comments

Comments
 (0)