Skip to content
Merged
Show file tree
Hide file tree
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
198 changes: 105 additions & 93 deletions packages/block-library/src/navigation-link/shared/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@ function getEntityTypeName( type, kind ) {
* This component provides the inspector controls (ToolsPanel) that are identical
* between both navigation blocks.
*
* @param {Object} props - Component props
* @param {Object} props.attributes - Block attributes
* @param {Function} props.setAttributes - Function to update block attributes
* @param {string} props.clientId - Block client ID
* @param {Object} props - Component props
* @param {Object} props.attributes - Block attributes
* @param {Function} props.setAttributes - Function to update block attributes
* @param {string} props.clientId - Block client ID
* @param {boolean} props.isLinkEditable - Whether link editing should be allowed
*/
export function Controls( { attributes, setAttributes, clientId } ) {
export function Controls( {
attributes,
setAttributes,
clientId,
isLinkEditable = true,
} ) {
const { label, url, description, rel, opensInNewTab } = attributes;
const dropdownMenuProps = useToolsPanelDropdownMenuProps();

Expand Down Expand Up @@ -188,99 +194,105 @@ export function Controls( { attributes, setAttributes, clientId } ) {
/>
</ToolsPanelItem>

<ToolsPanelItem
hasValue={ () => !! url }
label={ __( 'Link to' ) }
onDeselect={ () =>
setAttributes( {
url: undefined,
id: undefined,
kind: undefined,
type: undefined,
} )
}
isShownByDefault
>
<LinkPicker
preview={ preview }
onSelect={ handleLinkChange }
suggestionsQuery={ getSuggestionsQuery(
attributes.type,
attributes.kind
) }
label={ __( 'Link to' ) }
help={ helpText ? helpText : undefined }
/>
</ToolsPanelItem>
{ isLinkEditable && (
Comment thread
jeryj marked this conversation as resolved.
<>
<ToolsPanelItem
hasValue={ () => !! url }
label={ __( 'Link to' ) }
onDeselect={ () =>
setAttributes( {
url: undefined,
id: undefined,
kind: undefined,
type: undefined,
} )
}
isShownByDefault
>
<LinkPicker
preview={ preview }
onSelect={ handleLinkChange }
suggestionsQuery={ getSuggestionsQuery(
attributes.type,
attributes.kind
) }
label={ __( 'Link to' ) }
help={ helpText ? helpText : undefined }
/>
</ToolsPanelItem>

{ url && (
<HStack
className="navigation-link-to__actions"
alignment="left"
justify="left"
style={ { gridColumn: '1 / -1' } }
>
{ hasUrlBinding &&
isBoundEntityAvailable &&
entityRecord?.id &&
attributes.kind === 'post-type' &&
onNavigateToEntityRecord && (
<Button
size="compact"
variant="secondary"
onClick={ () => {
onNavigateToEntityRecord( {
postId: entityRecord.id,
postType: attributes.type,
} );
} }
__next40pxDefaultSize
>
{ sprintf(
/* translators: %s: entity type (e.g., "page", "post", "category") */
__( 'Edit %s' ),
entityTypeName
) }
</Button>
) }
{ isViewableUrl && (
<Button
size="compact"
variant="secondary"
href={ viewUrl }
target="_blank"
icon={ external }
iconPosition="right"
__next40pxDefaultSize
{ url && (
<HStack
className="navigation-link-to__actions"
alignment="left"
justify="left"
style={ { gridColumn: '1 / -1' } }
>
{ sprintf(
/* translators: %s: entity type (e.g., "page", "post", "category") or "link" for external links */
__( 'View %s' ),
attributes.kind &&
attributes.type &&
attributes.kind !== 'custom'
? entityTypeName
: __( 'link' )
{ hasUrlBinding &&
isBoundEntityAvailable &&
entityRecord?.id &&
attributes.kind === 'post-type' &&
onNavigateToEntityRecord && (
<Button
size="compact"
variant="secondary"
onClick={ () => {
onNavigateToEntityRecord( {
postId: entityRecord.id,
postType: attributes.type,
} );
} }
__next40pxDefaultSize
>
{ sprintf(
/* translators: %s: entity type (e.g., "page", "post", "category") */
__( 'Edit %s' ),
entityTypeName
) }
</Button>
) }
{ isViewableUrl && (
<Button
size="compact"
variant="secondary"
href={ viewUrl }
target="_blank"
icon={ external }
iconPosition="right"
__next40pxDefaultSize
>
{ sprintf(
/* translators: %s: entity type (e.g., "page", "post", "category") or "link" for external links */
__( 'View %s' ),
attributes.kind &&
attributes.type &&
attributes.kind !== 'custom'
? entityTypeName
: __( 'link' )
) }
</Button>
) }
</Button>
</HStack>
) }
</HStack>
) }

<ToolsPanelItem
hasValue={ () => !! opensInNewTab }
label={ __( 'Open in new tab' ) }
onDeselect={ () => setAttributes( { opensInNewTab: false } ) }
isShownByDefault
>
<CheckboxControl
label={ __( 'Open in new tab' ) }
checked={ opensInNewTab }
onChange={ ( value ) =>
setAttributes( { opensInNewTab: value } )
}
/>
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () => !! opensInNewTab }
label={ __( 'Open in new tab' ) }
onDeselect={ () =>
setAttributes( { opensInNewTab: false } )
}
isShownByDefault
>
<CheckboxControl
label={ __( 'Open in new tab' ) }
checked={ opensInNewTab }
onChange={ ( value ) =>
setAttributes( { opensInNewTab: value } )
}
/>
</ToolsPanelItem>
</>
) }

<ToolsPanelItem
hasValue={ () => !! description }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/navigation-submenu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export default function NavigationSubmenuEdit( {
attributes={ attributes }
setAttributes={ setAttributes }
clientId={ clientId }
isLinkEditable={ ! openSubmenusOnClick }
/>
</InspectorControls>
<div { ...blockProps }>
Expand Down
Loading