Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
43 changes: 24 additions & 19 deletions client/my-sites/stats/videopress-stats-module/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import config from '@automattic/calypso-config';
import page from '@automattic/calypso-router';
import { Card } from '@automattic/components';
import { formatNumber } from '@automattic/number-formatters';
Expand All @@ -12,7 +11,6 @@ import SectionHeader from 'calypso/components/section-header';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import StatsInfotip from 'calypso/my-sites/stats/components/stats-infotip';
import { getSiteSlug } from 'calypso/state/sites/selectors';
import getSiteAdminUrl from 'calypso/state/sites/selectors/get-site-admin-url';
import {
isRequestingSiteStatsForQuery,
getVideoPressPlaysComplete,
Expand Down Expand Up @@ -86,7 +84,7 @@ class VideoPressStatsModule extends Component {
return Math.max( ...data.map( ( item ) => item[ field ] || 0 ) );
}

renderTitleCell( title, views, maxViews, onClick, onKeyUp ) {
renderTitleCell( { title, views, maxViews, onClick, href } ) {
const fillPercentage = maxViews > 0 ? ( views / maxViews ) * 100 : 0;
return (
<div className="videopress-stats-module__grid-cell videopress-stats-module__grid-link">
Expand All @@ -95,9 +93,9 @@ class VideoPressStatsModule extends Component {
className="videopress-stats-module__bar"
style={ { '--bar-fill-percentage': `${ fillPercentage }%` } }
>
<span onClick={ onClick } onKeyUp={ onKeyUp } tabIndex="0" role="button">
<a href={ href } onClick={ onClick }>
{ title }
</span>
</a>
</div>
</div>
</div>
Expand All @@ -117,7 +115,6 @@ class VideoPressStatsModule extends Component {
period,
siteSlug,
translate,
siteAdminUrl,
siteId,
} = this.props;

Expand Down Expand Up @@ -148,14 +145,23 @@ class VideoPressStatsModule extends Component {
'is-refreshing': requesting && ! isLoading,
} );

const editVideo = ( postId ) => {
const isOdysseyStats = config.isEnabled( 'is_running_in_jetpack_site' );
if ( ! isOdysseyStats ) {
page( `/media/${ siteSlug }/${ postId }` );
const videoDetailsHref = ( postId ) =>
`/stats/${ data.period }/videodetails/${ siteSlug }?post=${ postId }`;

const showVideoDetails = ( event, postId ) => {
recordTracksEvent( 'calypso_video_stats_details_clicked', {
blog_id: this.props.siteId,
post_id: postId,
period: data.period,
} );

// Let the browser handle modified clicks (open in a new tab, etc.).
if ( event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button > 0 ) {
return;
}
// If it's Odyssey, redirect user to media lib page.
location.href = `${ siteAdminUrl }upload.php?item=${ postId }`;

event.preventDefault();
page( videoDetailsHref( postId ) );
};

const showStat = ( queryStatType, row ) => {
Expand Down Expand Up @@ -233,13 +239,13 @@ class VideoPressStatsModule extends Component {
key={ 'videopress-stats-row-' + index }
className="videopress-stats-module__row-wrapper"
>
{ this.renderTitleCell(
row.title,
row.views,
{ this.renderTitleCell( {
title: row.title,
views: row.views,
maxViews,
() => editVideo( row.post_id ),
() => editVideo( row.post_id )
) }
href: videoDetailsHref( row.post_id ),
onClick: ( event ) => showVideoDetails( event, row.post_id ),
} ) }
<div className="videopress-stats-module__grid-cell videopress-stats-module__grid-metric">
<span
onClick={ () => showStat( 'impressions', row ) }
Expand Down Expand Up @@ -308,7 +314,6 @@ export default connect( ( state, ownProps ) => {
return {
requesting: isRequestingSiteStatsForQuery( state, siteId, statType, query ),
data: getVideoPressPlaysComplete( state, siteId, statType, query ),
siteAdminUrl: getSiteAdminUrl( state, siteId ),
siteId,
siteSlug,
};
Expand Down
9 changes: 7 additions & 2 deletions client/my-sites/stats/videopress-stats-module/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
align-items: center;
padding-left: 10px;

span {
a {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
Expand All @@ -100,6 +100,11 @@
color: var(--color-text);
font-size: $font-body-small;
font-weight: 500;
text-decoration: none;

&:visited {
color: var(--color-text);
}
}

&::before {
Expand Down Expand Up @@ -133,7 +138,7 @@
}

.videopress-stats-module__grid-metric span,
.videopress-stats-module__bar span {
.videopress-stats-module__bar a {
color: var(--color-text-inverted);
}
}
Expand Down
Loading