Skip to content

Commit

Permalink
i18n: Update several cases of ShortenedNumber component with numberFo…
Browse files Browse the repository at this point in the history
…rmat
  • Loading branch information
chriskmnds committed Feb 6, 2025
1 parent 0421207 commit 29d66d9
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 30 deletions.
13 changes: 10 additions & 3 deletions apps/odyssey-stats/src/widget/modules.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ShortenedNumber, Button } from '@automattic/components';
import { Button } from '@automattic/components';
import { protect, akismet } from '@automattic/components/src/icons';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import { useTranslate, numberFormat } from 'i18n-calypso';
import { useState, FunctionComponent } from 'react';
import wpcom from 'calypso/lib/wp';
import useModuleDataQuery from '../hooks/use-module-data-query';
Expand Down Expand Up @@ -64,7 +64,14 @@ const ModuleCard: FunctionComponent< ModuleCardProps > = ( {
<>
{ ( ! isError || ! canManageModule ) && (
<div className="stats-widget-module__value">
<ShortenedNumber value={ value } />
<span>
{ numberFormat( value, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} ) }
</span>
</div>
) }
{ isError && canManageModule && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, ShortenedNumber } from '@automattic/components';
import { Button } from '@automattic/components';
import { Icon, arrowUp, arrowDown, external } from '@wordpress/icons';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import { useTranslate, numberFormat } from 'i18n-calypso';
import ExpandedCard from './expanded-card';
import type { SiteStats } from '../types';

Expand Down Expand Up @@ -62,7 +62,14 @@ export default function InsightsStats( { stats, siteUrlWithScheme, trackEvent }:
<div className="site-expanded-content__card-content">
<div className="site-expanded-content__card-content-column">
<div className="site-expanded-content__card-content-score">
<ShortenedNumber value={ data.visitors } />
<span>
{ numberFormat( data.visitors, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} ) }
</span>
{ getTrendContent( data.visitorsTrend, data.visitorsChange ) }
</div>
<div className="site-expanded-content__card-content-score-title">
Expand All @@ -71,7 +78,14 @@ export default function InsightsStats( { stats, siteUrlWithScheme, trackEvent }:
</div>
<div className="site-expanded-content__card-content-column">
<div className="site-expanded-content__card-content-score">
<ShortenedNumber value={ data.views } />
<span>
{ numberFormat( data.views, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} ) }
</span>
{ getTrendContent( data.viewsTrend, data.viewsChange ) }
</div>
<div className="site-expanded-content__card-content-score-title">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Gridicon, ShortenedNumber } from '@automattic/components';
import { Gridicon } from '@automattic/components';
import { Icon, arrowUp, arrowDown } from '@wordpress/icons';
import clsx from 'clsx';
import { translate, numberFormat } from 'i18n-calypso';
Expand Down Expand Up @@ -109,7 +109,14 @@ export default function SiteStatsColumn( { site, stats, siteError }: Props ) {
{ trendIcon }

<div className="sites-overview__stats">
<ShortenedNumber value={ totalViews } />
<span>
{ numberFormat( totalViews, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} ) }
</span>
</div>
</span>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import {
Card,
ComponentSwapper,
formattedNumber,
ShortenedNumber,
DotPager,
} from '@automattic/components';
import { Card, ComponentSwapper, formattedNumber, DotPager } from '@automattic/components';
import {
formatPercentage,
percentCalculator,
} from '@automattic/components/src/highlight-cards/lib/numbers';
import { eye } from '@automattic/components/src/icons';
import { Icon, people, postContent, starEmpty, commentContent } from '@wordpress/icons';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import { useTranslate, numberFormat } from 'i18n-calypso';
import React, { useMemo } from 'react';
import QueryPosts from 'calypso/components/data/query-posts';
import QuerySiteStats from 'calypso/components/data/query-site-stats';
Expand Down Expand Up @@ -154,7 +148,16 @@ export default function AllTimeHighlightsSection( {
{
id: 'views',
header: translate( 'Views' ),
content: <ShortenedNumber value={ viewsBestDayTotal } />,
content: (
<span>
{ numberFormat( viewsBestDayTotal, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} ) }
</span>
),
footer: translate( '%(percent)s of views', {
args: { percent: formatPercentage( bestViewsEverPercent, true ) },
context: 'Stats: Percentage of views',
Expand Down
11 changes: 8 additions & 3 deletions client/my-sites/stats/stats-email-top-row/top-card.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Card, ShortenedNumber, Spinner } from '@automattic/components';
import { useTranslate } from 'i18n-calypso';
import { Card, Spinner } from '@automattic/components';
import { useTranslate, numberFormat } from 'i18n-calypso';

/* This is a very stripped down version of HighlightCard
* HighlightCard doesn't support non-numeric values
Expand All @@ -25,7 +25,12 @@ const TopCardValue = ( { value, isLoading } ) => {

return (
<span className="highlight-card-count-value" title={ String( value ) }>
<ShortenedNumber value={ value } />
{ numberFormat( value, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} ) }
</span>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Card, ShortenedNumber, Spinner } from '@automattic/components';
import { Card, Spinner } from '@automattic/components';
import { numberFormat } from 'i18n-calypso';
import { ReactNode } from 'react';
import InfoPopover from 'calypso/components/info-popover';
import '@automattic/components/src/highlight-cards/style.scss';
Expand Down Expand Up @@ -41,7 +42,14 @@ const SubscriberStatsCardValue = ( {
className="highlight-card-count-value subscriber-stats-card__value"
title={ String( value ) }
>
<ShortenedNumber value={ value as number } />
{ typeof value === 'number'
? numberFormat( value, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} )
: '-' }
</span>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Icon, chevronDown, chevronUp, tag, file } from '@wordpress/icons';
import clsx from 'clsx';
import { numberFormat } from 'i18n-calypso';
import React, { Fragment, useState } from 'react';
import ShortenedNumber from '../number-formatters';
import type { HorizontalBarListItemProps } from './types';

import './style.scss';
Expand Down Expand Up @@ -106,8 +105,18 @@ const HorizontalBarListItem = ( {

const renderValue = () => {
if ( useShortNumber ) {
return <ShortenedNumber value={ value } />;
return (
<span>
{ numberFormat( value, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} ) }
</span>
);
}

if ( formatValue ) {
return formatValue( value, data );
}
Expand Down
37 changes: 32 additions & 5 deletions packages/components/src/post-stats-card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { recordTracksEvent } from '@automattic/calypso-analytics';
import { Icon, commentContent, starEmpty } from '@wordpress/icons';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import { useTranslate, numberFormat } from 'i18n-calypso';
import { useMemo } from 'react';
import { Card, ShortenedNumber, Button } from '../';
import { Card, Button } from '../';
import { eye } from '../icons';
import './style.scss';

Expand Down Expand Up @@ -78,21 +78,48 @@ export default function PostStatsCard( {
<Icon className="gridicon" icon={ eye } />
<div className="post-stats-card__count-header">{ translate( 'Views' ) }</div>
<div className="post-stats-card__count-value">
<ShortenedNumber value={ isLoading ? null : viewCount } />
<span>
{ ! isLoading && viewCount !== null
? numberFormat( viewCount, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} )
: '-' }
</span>
</div>
</div>
<div className="post-stats-card__count post-stats-card__count--like">
<Icon className="gridicon" icon={ starEmpty } />
<div className="post-stats-card__count-header">{ translate( 'Likes' ) }</div>
<div className="post-stats-card__count-value">
<ShortenedNumber value={ isLoading ? null : likeCount } />
<span>
{ ! isLoading && likeCount !== null
? numberFormat( likeCount, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} )
: '-' }
</span>
</div>
</div>
<div className="post-stats-card__count post-stats-card__count--comment">
<Icon className="gridicon" icon={ commentContent } />
<div className="post-stats-card__count-header">{ translate( 'Comments' ) }</div>
<div className="post-stats-card__count-value">
<ShortenedNumber value={ isLoading ? null : commentCount } />
<span>
{ ! isLoading && commentCount !== null
? numberFormat( commentCount, {
numberFormatOptions: {
notation: 'compact',
maximumFractionDigits: 1,
},
} )
: '-' }
</span>
</div>
</div>
</div>
Expand Down

0 comments on commit 29d66d9

Please sign in to comment.