import { Popover } from '@automattic/components'; import { Button } from '@wordpress/components'; import { Icon, mobile, desktop, share } from '@wordpress/icons'; import { useTranslate } from 'i18n-calypso'; import moment from 'moment'; import { useState, useRef } from 'react'; import WPcomBadge from 'calypso/assets/images/performance-profiler/wpcom-badge.svg'; import SectionNav from 'calypso/components/section-nav'; import NavItem from 'calypso/components/section-nav/item'; import NavTabs from 'calypso/components/section-nav/tabs'; import ShareButton from 'calypso/components/share-button'; import { Badge } from 'calypso/performance-profiler/components/badge'; import './style.scss'; type HeaderProps = { url: string; activeTab: string; onTabChange: ( tab: TabType ) => void; showNavigationTabs?: boolean; timestamp?: string; showWPcomBadge?: boolean; shareLink: string; }; export const TabTypes = { mobile: 'mobile', desktop: 'desktop', }; export type TabType = ( typeof TabTypes )[ keyof typeof TabTypes ]; const SocialServices = [ { service: 'x', }, { service: 'linkedin', }, { service: 'facebook', }, { service: 'tumblr', }, ]; export const PerformanceProfilerHeader = ( props: HeaderProps ) => { const translate = useTranslate(); const [ showPopoverMenu, setPopoverMenu ] = useState( false ); const popoverButtonRef = useRef( null ); const { url, activeTab, onTabChange, showNavigationTabs, timestamp, showWPcomBadge, shareLink } = props; const urlParts = new URL( url ); const renderTimestampAndBadge = () => ( <> { timestamp && ( { translate( 'Tested on %(date)s', { args: { date: moment( timestamp ).format( 'MMMM Do, YYYY h:mm:ss A' ) }, } ) } ) } { showWPcomBadge && ( { { translate( 'Hosted on WordPress.com' ) } ) } ); return (

{ urlParts.hostname ?? '' }

{ renderTimestampAndBadge() }
{ showNavigationTabs && ( onTabChange( TabTypes.mobile ) } selected={ activeTab === TabTypes.mobile } > { translate( 'Mobile' ) } onTabChange( TabTypes.desktop ) } selected={ activeTab === TabTypes.desktop } > { translate( 'Desktop' ) }
{ renderTimestampAndBadge() }
{ timestamp && ( <>
e.key === 'Enter' && setPopoverMenu( true ) } onClick={ () => setPopoverMenu( true ) } > { translate( 'Share' ) }
setPopoverMenu( false ) } > { SocialServices.map( ( item ) => ( ) ) } ) }
) }
); }; const PATHNAME_MAX_LENGTH = 50; function PathName( props: { pathName?: string } ) { let { pathName } = props; if ( ! pathName || pathName === '/' ) { return; } if ( pathName.endsWith( '/' ) ) { pathName = pathName.slice( 0, -1 ); } if ( pathName.length > PATHNAME_MAX_LENGTH ) { if ( pathName.startsWith( '/' ) ) { pathName = pathName.slice( 1 ); } const parts = pathName.split( '/' ); const hasHiddenParts = parts.length > 1; pathName = `${ hasHiddenParts ? '/...' : '' }/${ parts[ parts.length - 1 ] }`; } return

{ pathName }

; }