Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats: Show 'sending email' notice #97726

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client/my-sites/stats/stats-email-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ class StatsEmailDetail extends Component {
<div className="stats__email-wrapper">
<h3 className="highlight-cards-heading">{ this.getTitle( statType ) }</h3>

<StatsEmailTopRow siteId={ siteId } postId={ postId } statType={ statType } />
<StatsEmailTopRow
siteId={ siteId }
postId={ postId }
statType={ statType }
post={ post }
/>

<StatsPeriodHeader>
<StatsPeriodNavigation
Expand Down
13 changes: 11 additions & 2 deletions client/my-sites/stats/stats-email-top-row/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { eye } from '@automattic/components/src/icons';
import { Icon } from '@wordpress/icons';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import moment from 'moment';
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { PERIOD_ALL_TIME } from 'calypso/state/stats/emails/constants';
Expand All @@ -13,7 +14,7 @@ import {
import TopCard from './top-card';
import './style.scss';

export default function StatsEmailTopRow( { siteId, postId, statType, className } ) {
export default function StatsEmailTopRow( { siteId, postId, statType, className, post } ) {
const translate = useTranslate();

const counts = useSelector( ( state ) =>
Expand All @@ -23,6 +24,12 @@ export default function StatsEmailTopRow( { siteId, postId, statType, className
isRequestingEmailStats( state, siteId, postId, PERIOD_ALL_TIME, statType )
);

/**
* Only show email stats if post was published more than 5 minutes ago.
*/
const now = moment();
const emailIsSending = post?.date ? now.diff( moment( post?.date ), 'minutes' ) < 5 : false;

const boxes = useMemo( () => {
switch ( statType ) {
case 'opens':
Expand All @@ -33,6 +40,7 @@ export default function StatsEmailTopRow( { siteId, postId, statType, className
value={ counts?.total_sends ?? 0 }
isLoading={ isRequesting && ! counts?.hasOwnProperty( 'total_sends' ) }
icon={ <Gridicon icon="mail" /> }
emailIsSending={ emailIsSending }
/>
{ counts?.unique_opens ? (
<TopCard
Expand All @@ -53,6 +61,7 @@ export default function StatsEmailTopRow( { siteId, postId, statType, className
value={ counts?.opens_rate ? `${ Math.round( counts?.opens_rate * 100 ) }%` : null }
isLoading={ isRequesting && ! counts?.hasOwnProperty( 'opens_rate' ) }
icon={ <Gridicon icon="trending" /> }
emailIsSending={ emailIsSending }
/>
</>
);
Expand Down Expand Up @@ -82,7 +91,7 @@ export default function StatsEmailTopRow( { siteId, postId, statType, className
default:
return null;
}
}, [ statType, counts, translate, isRequesting ] );
}, [ statType, counts, translate, isRequesting, emailIsSending ] );

return (
<div className={ clsx( 'stats-email-open-top-row', className ?? null ) }>
Expand Down
6 changes: 6 additions & 0 deletions client/my-sites/stats/stats-email-top-row/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ $vertical-margin: 32px;
color: var(--studio-gray-100);
font-size: $font-body-small;
margin-bottom: $vertical-margin;
.sending-email .highlight-card-count-value {
font-size: $font-body-small;
font-style: italic;
font-family: $sans;
padding-top: 10px;
}
}

.stats__email-detail {
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,4 +1,5 @@
import { Card, ShortenedNumber, Spinner } from '@automattic/components';
import { useTranslate } from 'i18n-calypso';

/* This is a very stripped down version of HighlightCard
* HighlightCard doesn't support non-numeric values
Expand Down Expand Up @@ -29,13 +30,17 @@ const TopCardValue = ( { value, isLoading } ) => {
);
};

const TopCard = ( { heading, icon, value, isLoading } ) => {
const TopCard = ( { heading, icon, value, isLoading, emailIsSending = false } ) => {
const translate = useTranslate();
return (
<Card className="highlight-card">
<div className="highlight-card-icon">{ icon }</div>
<div className="highlight-card-heading">{ heading }</div>
<div className="highlight-card-count">
<TopCardValue value={ value } isLoading={ isLoading } />
<div className={ `highlight-card-count ${ emailIsSending ? 'sending-email' : '' }` }>
edanzer marked this conversation as resolved.
Show resolved Hide resolved
<TopCardValue
value={ emailIsSending ? translate( 'Still sending emails.' ) : value }
isLoading={ isLoading }
/>
</div>
</Card>
);
Expand Down
Loading