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 Block: Refactor settings panel to use ToolsPanel #67903

Merged
merged 2 commits into from
Dec 13, 2024
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
85 changes: 54 additions & 31 deletions packages/block-library/src/page-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import {
Warning,
} from '@wordpress/block-editor';
import {
PanelBody,
ToolbarButton,
Spinner,
Notice,
ComboboxControl,
Button,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { useMemo, useState, useEffect, useCallback } from '@wordpress/element';
Expand Down Expand Up @@ -320,38 +321,60 @@ export default function PageListEdit( {
return (
<>
<InspectorControls>
{ pagesTree.length > 0 && (
<PanelBody>
<ComboboxControl
__nextHasNoMarginBottom
__next40pxDefaultSize
className="editor-page-attributes__parent"
label={ __( 'Parent' ) }
value={ parentPageID }
options={ pagesTree }
onChange={ ( value ) =>
setAttributes( { parentPageID: value ?? 0 } )
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( { parentPageID: 0 } );
} }
>
{ pagesTree.length > 0 && (
<ToolsPanelItem
label={ __( 'Parent Page' ) }
hasValue={ () => parentPageID !== 0 }
onDeselect={ () =>
setAttributes( { parentPageID: 0 } )
}
help={ __(
'Choose a page to show only its subpages.'
) }
/>
</PanelBody>
) }
{ allowConvertToLinks && (
<PanelBody title={ __( 'Edit this menu' ) }>
<p>{ convertDescription }</p>
<Button
__next40pxDefaultSize
variant="primary"
accessibleWhenDisabled
disabled={ ! hasResolvedPages }
onClick={ convertToNavigationLinks }
isShownByDefault
>
{ __( 'Edit' ) }
</Button>
</PanelBody>
) }
<ComboboxControl
__nextHasNoMarginBottom
__next40pxDefaultSize
className="editor-page-attributes__parent"
label={ __( 'Parent' ) }
value={ parentPageID }
options={ pagesTree }
onChange={ ( value ) =>
setAttributes( {
parentPageID: value ?? 0,
} )
}
help={ __(
'Choose a page to show only its subpages.'
) }
/>
</ToolsPanelItem>
) }

{ allowConvertToLinks && (
<ToolsPanelItem
label={ __( 'Edit Menu' ) }
isShownByDefault
>
<div>
<p>{ convertDescription }</p>
<Button
__next40pxDefaultSize
variant="primary"
accessibleWhenDisabled
disabled={ ! hasResolvedPages }
onClick={ convertToNavigationLinks }
>
{ __( 'Edit' ) }
</Button>
</div>
</ToolsPanelItem>
) }
</ToolsPanel>
</InspectorControls>
{ allowConvertToLinks && (
<>
Expand Down
Loading