/** * WordPress dependencies */ import { CheckboxControl, PanelBody, PanelRow, TextControl, } from '@wordpress/components'; import { useEffect, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import { HydratedPost } from '../../../../../common/providers/base-wordpress-provider'; import { TrafficBoostLink } from '../../provider'; /** * Props structure for LinkOptionsPanel. * * @since 3.19.0 */ interface LinkOptionsPanelProps { post: HydratedPost; activeLink: TrafficBoostLink | null; onTextChange: ( value: string ) => void; onNewTabChange: ( value: boolean ) => void; onNofollowChange: ( value: boolean ) => void; linkText: string | null; } /** * Defines the state structure for LinkOptionsPanel. * * @since 3.19.0 */ interface OptionsState { linkText: string; openInNewTab: boolean; nofollow: boolean; isOpen: boolean; } /** * Link options panel component for the Traffic Boost feature. * Displays link options for a selected post. * * Note: not in use currently. * * @since 3.19.0 * * @param {LinkOptionsPanelProps} props The component's props. */ export const LinkOptionsPanel = ( { post, activeLink, onTextChange, onNewTabChange, onNofollowChange, linkText, }: LinkOptionsPanelProps ): React.JSX.Element => { const [ options, setOptions ] = useState( { linkText: linkText ?? activeLink?.smartLink?.text ?? '', openInNewTab: false, nofollow: false, isOpen: false, } ); /** * Updates the link text when the linkText prop changes. * * @since 3.19.0 */ useEffect( () => { setOptions( ( prevOptions: OptionsState ) => ( { ...prevOptions, linkText: linkText ?? '', } ) ); }, [ linkText ] ); /** * Updates the link options when the active link changes. * * @since 3.19.0 */ useEffect( () => { setOptions( ( prevOptions ) => ( { ...prevOptions, linkText: activeLink?.smartLink?.text ?? '', isOpen: false, } ) ); }, [ activeLink ] ); return ( setOptions( { ...options, isOpen } ) } opened={ options.isOpen } > { setOptions( { ...options, linkText: value } ); onTextChange( value ); } } help={ __( 'Select text in the post preview to change the link text', 'wp-parsely' ) } /> {} } // Disabled, so no need for implementation />
{ __( 'Advanced', 'wp-parsely' ) }
{ setOptions( { ...options, openInNewTab: value } ); onNewTabChange( value ); } } /> { setOptions( { ...options, nofollow: value } ); onNofollowChange( value ); } } />
); };