Skip to content

Commit

Permalink
Edit Site: Remove templateIds prop from NavigateToLink
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Apr 28, 2020
1 parent d89385f commit 4e46c18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
7 changes: 1 addition & 6 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,11 @@ export default function BlockEditor() {
( fillProps ) => (
<NavigateToLink
{ ...fillProps }
templateIds={ settings.templateIds }
activeId={ settings.templateId }
onActiveIdChange={ setActiveTemplateId }
/>
),
[
settings.templateIds,
settings.templateId,
setActiveTemplateId,
]
[ settings.templateId, setActiveTemplateId ]
) }
</__experimentalLinkControl.ViewerFill>
<Sidebar.InspectorFill>
Expand Down
25 changes: 10 additions & 15 deletions packages/edit-site/src/components/navigate-to-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import { __ } from '@wordpress/i18n';
*/
const { fetch } = window;

export default function NavigateToLink( {
url,
templateIds,
activeId,
onActiveIdChange,
} ) {
export default function NavigateToLink( { url, activeId, onActiveIdChange } ) {
const [ templateId, setTemplateId ] = useState();
useEffect( () => {
const effect = async () => {
Expand All @@ -28,14 +23,14 @@ export default function NavigateToLink( {
if ( success ) {
let newTemplateId = data.ID;
if ( newTemplateId === null ) {
const { getEntityRecord } = select( 'core' );
newTemplateId = templateIds
.map( ( id ) =>
getEntityRecord( 'postType', 'wp_template', id )
)
.find(
( template ) => template.slug === data.post_name
).id;
const { getEntityRecords } = select( 'core' );
newTemplateId = getEntityRecords(
'postType',
'wp_template',
{
slug: data.post_name,
}
)[ 0 ].id;
}
setTemplateId( newTemplateId );
} else {
Expand All @@ -46,7 +41,7 @@ export default function NavigateToLink( {
}
};
effect();
}, [ url, templateIds ] );
}, [ url ] );
const onClick = useMemo( () => {
if ( ! templateId || templateId === activeId ) {
return null;
Expand Down

0 comments on commit 4e46c18

Please sign in to comment.