Skip to content

Commit

Permalink
Block Editor: Remove redundant callback memoization from 'ImageURLInp…
Browse files Browse the repository at this point in the history
…utUI' (#51658)
  • Loading branch information
Mamaduka committed Jun 20, 2023
1 parent 0cda9c1 commit 7688c16
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useRef, useState, useCallback } from '@wordpress/element';
import { useRef, useState } from '@wordpress/element';
import {
ToolbarButton,
Button,
Expand Down Expand Up @@ -50,34 +50,34 @@ const ImageURLInputUI = ( {
// Use internal state instead of a ref to make sure that the component
// re-renders when the popover's anchor updates.
const [ popoverAnchor, setPopoverAnchor ] = useState( null );
const openLinkUI = useCallback( () => {
const openLinkUI = () => {
setIsOpen( true );
} );
};

const [ isEditingLink, setIsEditingLink ] = useState( false );
const [ urlInput, setUrlInput ] = useState( null );

const autocompleteRef = useRef( null );

const startEditLink = useCallback( () => {
const startEditLink = () => {
if (
linkDestination === LINK_DESTINATION_MEDIA ||
linkDestination === LINK_DESTINATION_ATTACHMENT
) {
setUrlInput( '' );
}
setIsEditingLink( true );
} );
};

const stopEditLink = useCallback( () => {
const stopEditLink = () => {
setIsEditingLink( false );
} );
};

const closeLinkUI = useCallback( () => {
const closeLinkUI = () => {
setUrlInput( null );
stopEditLink();
setIsOpen( false );
} );
};

const getUpdatedLinkTargetSettings = ( value ) => {
const newLinkTarget = value ? '_blank' : undefined;
Expand Down Expand Up @@ -106,7 +106,7 @@ const ImageURLInputUI = ( {
};
};

const onFocusOutside = useCallback( () => {
const onFocusOutside = () => {
return ( event ) => {
// The autocomplete suggestions list renders in a separate popover (in a portal),
// so onFocusOutside fails to detect that a click on a suggestion occurred in the
Expand All @@ -123,9 +123,9 @@ const ImageURLInputUI = ( {
setUrlInput( null );
stopEditLink();
};
} );
};

const onSubmitLinkChange = useCallback( () => {
const onSubmitLinkChange = () => {
return ( event ) => {
if ( urlInput ) {
// It is possible the entered URL actually matches a named link destination.
Expand All @@ -144,14 +144,14 @@ const ImageURLInputUI = ( {
setUrlInput( null );
event.preventDefault();
};
} );
};

const onLinkRemove = useCallback( () => {
const onLinkRemove = () => {
onChangeUrl( {
linkDestination: LINK_DESTINATION_NONE,
href: '',
} );
} );
};

const getLinkDestinations = () => {
const linkDestinations = [
Expand Down

1 comment on commit 7688c16

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 7688c16.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5319775589
📝 Reported issues:

Please sign in to comment.