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

Edit Site: Update template navigation to use new link control. #20366

Merged
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
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ExternalLink,
Spinner,
VisuallyHidden,
createSlotFill,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import {
Expand All @@ -21,6 +22,7 @@ import {
Fragment,
useEffect,
createElement,
useMemo,
} from '@wordpress/element';
import {
safeDecodeURI,
Expand All @@ -41,6 +43,10 @@ import LinkControlSearchItem from './search-item';
import LinkControlSearchInput from './search-input';
import LinkControlSearchCreate from './search-create-button';

const { Slot: ViewerSlot, Fill: ViewerFill } = createSlotFill(
'BlockEditorLinkControlViewer'
);

// Used as a unique identifier for the "Create" option within search results.
// Used to help distinguish the "Create" suggestion within the search results in
// order to handle it as a unique case.
Expand Down Expand Up @@ -510,6 +516,10 @@ function LinkControl( {
);
};

const viewerSlotFillProps = useMemo(
() => ( { url: value && value.url } ),
[ value && value.url ]
);
return (
<div
tabIndex={ -1 }
Expand Down Expand Up @@ -574,6 +584,7 @@ function LinkControl( {
>
{ __( 'Edit' ) }
</Button>
<ViewerSlot fillProps={ viewerSlotFillProps } />
</div>
</Fragment>
) }
Expand All @@ -586,4 +597,6 @@ function LinkControl( {
);
}

LinkControl.ViewerFill = ViewerFill;

export default LinkControl;
14 changes: 3 additions & 11 deletions packages/block-editor/src/components/url-popover/link-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { pencil } from '@wordpress/icons';
import { createSlotFill, ExternalLink, Button } from '@wordpress/components';
import { ExternalLink, Button } from '@wordpress/components';
import { safeDecodeURI, filterURLForDisplay } from '@wordpress/url';
import { useMemo } from '@wordpress/element';

const { Slot, Fill } = createSlotFill( 'BlockEditorURLPopoverLinkViewer' );
Comment on lines -10 to -15
Copy link
Contributor

Choose a reason for hiding this comment

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

If the URLPopover has been replaced, why do we need to make changes to this file?

Could there be any cases where this is still used where removing this slot may cause issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was only added for this, so I am reverting it here before anyone gets a chance to use it.

import { pencil } from '@wordpress/icons';

function LinkViewerUrl( { url, urlLabel, className } ) {
const linkClassName = classnames(
Expand All @@ -31,7 +28,7 @@ function LinkViewerUrl( { url, urlLabel, className } ) {
);
}

function LinkViewer( {
export default function LinkViewer( {
className,
linkClassName,
onEditLinkClick,
Expand Down Expand Up @@ -59,11 +56,6 @@ function LinkViewer( {
onClick={ onEditLinkClick }
/>
) }
<Slot fillProps={ useMemo( () => ( { url } ), [ url ] ) } />
</div>
);
}

LinkViewer.Fill = Fill;

export default LinkViewer;
1 change: 1 addition & 0 deletions packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@wordpress/i18n": "file:../i18n",
"@wordpress/media-utils": "file:../media-utils",
"@wordpress/notices": "file:../notices",
"@wordpress/url": "file:../url",
"file-saver": "^2.0.2",
"jszip": "^3.2.2"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useEntityBlockEditor } from '@wordpress/core-data';
import {
BlockEditorProvider,
BlockEditorKeyboardShortcuts,
URLPopover,
__experimentalLinkControl,
BlockInspector,
WritingFlow,
ObserveTyping,
Expand Down Expand Up @@ -69,7 +69,7 @@ export default function BlockEditor() {
useSubRegistry={ false }
>
<BlockEditorKeyboardShortcuts />
<URLPopover.LinkViewer.Fill>
<__experimentalLinkControl.ViewerFill>
{ useCallback(
( fillProps ) => (
<NavigateToLink
Expand All @@ -85,7 +85,7 @@ export default function BlockEditor() {
setActiveTemplateId,
]
) }
</URLPopover.LinkViewer.Fill>
</__experimentalLinkControl.ViewerFill>
<Sidebar.InspectorFill>
<BlockInspector />
</Sidebar.InspectorFill>
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-site/src/components/navigate-to-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { useState, useEffect, useMemo } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';
import { select } from '@wordpress/data';
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
Expand All @@ -22,7 +23,7 @@ export default function NavigateToLink( {
const effect = async () => {
try {
const { success, data } = await fetch(
`${ url }?_wp-find-template`
addQueryArgs( url, { '_wp-find-template': true } )
).then( ( res ) => res.json() );
if ( success ) {
let newTemplateId = data.ID;
Expand Down