import { SegmentedControl } from '@automattic/components'; import { formatNumber } from '@automattic/number-formatters'; import { Icon, external } from '@wordpress/icons'; import clsx from 'clsx'; import { useTranslate } from 'i18n-calypso'; import moment from 'moment'; import { useState, FunctionComponent } from 'react'; import useReferrersQuery from '../hooks/use-referrers-query'; import useTopPostsQuery from '../hooks/use-top-posts-query'; import { HighLightItem } from '../typings'; import './highlights.scss'; interface ItemWrapperProps { siteId: number; statsBaseUrl: string; isItemLink: boolean; item: HighLightItem; isItemLinkExternal: boolean; } interface TopColumnProps { items: Array< HighLightItem >; viewAllUrl: string; viewAllText: string; title: string; isLoading: boolean; statsBaseUrl: string; siteId: number; isItemLinkExternal?: boolean; isItemLink?: boolean; className?: null | string; } interface HighlightsProps { siteId: number; gmtOffset: number; statsBaseUrl: string; } const HIGHLIGHT_ITEMS_LIMIT = 5; const HIGHLIGHT_TAB_TOP_POSTS_PAGES = 'topPostsAndPages'; const HIGHLIGHT_TAB_TOP_REFERRERS = 'topReferrers'; const postAndPageLink = ( baseUrl: string, siteId: number, postId: number ) => { return `${ baseUrl }/stats/post/${ postId }/${ siteId }`; }; const externalLink = ( item: HighLightItem ) => { // Url is for referrers and href is for top posts and pages. return item.url || item.href; }; const ItemWrapper: FunctionComponent< ItemWrapperProps > = ( { statsBaseUrl, siteId, isItemLink, item, isItemLinkExternal, } ) => { const translate = useTranslate(); const renderedItem = (
{ item.title }
{ translate( '%(views)s Views', { args: { views: formatNumber( item.views ), }, } ) }{ isLoading ? `${ translate( 'Loading' ) }...` : translate( 'No data to show' ) }
) } { items.length > 0 && (