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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Add video thumbnails to the Videos report, drop "report" from report headings, and label the export button "Download CSV".
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ describe( 'Stats video plays normalizer', () => {
} );
} );

it( 'keeps a complete-stats row poster and drops an empty one', () => {
const response = ( poster: unknown ) => ( {
date: '2026-06-22',
period: 'day',
days: {
'2026-06-22': { data: [ { post_id: 12, title: 'Launch video', views: 3, poster } ] },
},
} );
const query = { period: 'day', end_date: '2026-06-22', complete_stats: true } as const;

expect(
sanitizeStatsVideoPlaysResponse( response( 'https://i0.wp.com/v/launch.jpg' ), query )
.data[ 0 ].items[ 0 ].poster
).toBe( 'https://i0.wp.com/v/launch.jpg' );
for ( const poster of [ null, '' ] ) {
expect(
sanitizeStatsVideoPlaysResponse( response( poster ), query ).data[ 0 ].items[ 0 ]
).not.toHaveProperty( 'poster' );
}
} );

it( 'does not add link actions when video rows have no URL', () => {
const result = sanitizeStatsVideoPlaysResponse(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type StatsVideoPlaysItem = StatsNormalizedItemBase & {
watch_time: number;
retention_rate: number;
link: string | null;
/** Poster-frame URL, absent when the video has none or is private. */
poster?: string;
actions?: StatsItemAction[];
children: null;
};
Expand Down Expand Up @@ -65,6 +67,7 @@ export function sanitizeStatsVideoPlaysResponse(
watch_time: safeParseFloat( item.watch_time ),
retention_rate: safeParseFloat( item.retention_rate ),
link: typeof item.url === 'string' ? item.url : null,
...( typeof item.poster === 'string' && item.poster !== '' ? { poster: item.poster } : {} ),
actions: typeof item.url === 'string' ? [ { type: 'link', data: item.url } ] : [],
children: null,
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,4 @@ describe( 'defineReportTabs', () => {
expect( tabs.resolve( 'missing' ) ).toBe( 'one' );
expect( tabs.resolve( undefined ) ).toBe( 'one' );
} );

describe( 'the section heading', () => {
it( 'reads the declared title, distinct from the tab label', () => {
const tabs = defineReportTabs(
[ { id: 'one', getLabel: () => 'Posts & Pages', getTitle: () => 'Posts & pages report' } ],
'one'
);

expect( tabs.getTabTitle( 'one' ) ).toBe( 'Posts & pages report' );
expect( tabs.getTabLabel( 'one' ) ).toBe( 'Posts & Pages' );
} );

it( 'falls back to the tab label where no title is declared', () => {
expect( build().getTabTitle( 'two' ) ).toBe( 'Two' );
} );

it( 'falls back to the tab id when neither exists', () => {
expect( build().getTabTitle( 'missing' as 'one' ) ).toBe( 'missing' );
} );

it( 'resolves the title lazily on each call', () => {
let calls = 0;
const tabs = defineReportTabs(
[ { id: 'one', getLabel: () => 'One', getTitle: () => `Title ${ ++calls }` } ] as const,
'one'
);

expect( tabs.getTabTitle( 'one' ) ).toBe( 'Title 1' );
expect( tabs.getTabTitle( 'one' ) ).toBe( 'Title 2' );
} );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
export type ReportTabDefinition< TabId extends string > = {
id: TabId;
getLabel: () => string;

/**
* Heading for the section this tab opens, where it reads differently from
* the tab itself: `Posts & Pages` names the tab, `Posts & Pages report`
* heads the records under it.
*/
getTitle?: () => string;
};

export type ReportTab< TabId extends string > = {
Expand All @@ -43,9 +36,6 @@ export type ReportTabs< TabId extends string > = {
getTabs: () => ReportTab< TabId >[];

getTabLabel: ( id: TabId ) => string;

/** The heading for a tab's section, falling back to the tab's own label. */
getTabTitle: ( id: TabId ) => string;
};

/**
Expand All @@ -71,11 +61,5 @@ export function defineReportTabs< TabId extends string >(
const getTabLabel = ( id: TabId ): string =>
definitions.find( def => def.id === id )?.getLabel() ?? id;

const getTabTitle = ( id: TabId ): string => {
const definition = definitions.find( def => def.id === id );

return definition?.getTitle?.() ?? definition?.getLabel() ?? id;
};

return { ids, resolve, getTabs, getTabLabel, getTabTitle };
return { ids, resolve, getTabs, getTabLabel };
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export {
ReportPageTabs,
ReportPerformanceChart,
ReportRecordsTable,
ReportThumbnailTitle,
ReportCsvAction,
useReportRetry,
buildReportMetricSeries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const label = __( 'All pages' );
breadcrumbs={ <StatsBreadcrumbs items={ [ { label } ] } /> }
actions={ downloadButton }
>
<ReportPageLayout title={ getTabTitle( activeTab ) } dateFilters={ dateFilters }>
<ReportPageLayout title={ getTabLabel( activeTab ) } dateFilters={ dateFilters }>
<ReportPerformanceChart
primary={ visits.primary.data }
comparison={ visits.hasComparison ? visits.comparison.data : undefined }
Expand Down Expand Up @@ -57,6 +57,10 @@ const label = __( 'All pages' );
- **`ReportRecordsTable`** — a Core DataViews table over the module's
summarized rows; search, sorting, column config, and pagination run
client-side via `filterSortAndPaginate`.
- **`ReportThumbnailTitle`** — a records-table title led by the row's thumbnail,
falling back to `fallbackIcon` when there is none or it fails to load. Its
children are a function that receives the class names the title link needs
to truncate beside the thumbnail.
- **`ReportEmptyState`** — replaces the records table (and, on Locations, the
map) when the selected period returned no rows. Pages render it only when the
rows they pass to the table are empty and the table is not loading, so a
Expand Down Expand Up @@ -84,17 +88,9 @@ The picker offers the range alone — no interval control, no comparison. Both
stay on the URL untouched, so the dashboard keeps them. Declaring this per
report is WOOA7S-1952.

A report page carries three names:

| name | where it shows | example |
| ------------- | ----------------------- | --------------------------- |
| report label | the trailing breadcrumb | `All pages` |
| tab label | the tab strip | `Posts & Pages`, `Archives` |
| section title | the header's `h2` | `Posts & Pages report` |

The first two come from `routes/reports/registry.ts` (`getLabel`) and the tab
set. `title` is the third: `getTabTitle( activeTab )` on a tabbed report, which
falls back to the tab's label, and the report's `getTitle()` otherwise.
The header's `h2` reuses a name the page already shows: the open tab's label
on a tabbed report (`getTabLabel( activeTab )`, e.g. `Posts & Pages`), and the
report's own label from `routes/reports/registry.ts` otherwise (`All pages`).

Omit `dateFilters` on a report with no date window; the header is then the title
alone. It pins at the top of the layout's scroll area and condenses on scroll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe( 'ReportCsvAction', () => {
expect( rowsCsvDownloadButtonMock.mock.calls[ 0 ][ 0 ] ).toEqual(
expect.objectContaining( {
...props,
label: 'Download',
label: 'Download CSV',
variant: 'solid',
showIcon: false,
} )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* External dependencies
*/
import { fireEvent, render, screen } from '@testing-library/react';
import { video as videoIcon } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { ReportThumbnailTitle } from '../report-thumbnail-title';

const renderTitle = ( thumbnailUrl?: string ) => (
<ReportThumbnailTitle thumbnailUrl={ thumbnailUrl } fallbackIcon={ videoIcon }>
{ classNames => <span className={ classNames.text }>Launch video</span> }
</ReportThumbnailTitle>
);

describe( 'ReportThumbnailTitle', () => {
it( 'renders the thumbnail beside the title', () => {
render( renderTitle( 'https://example.com/a.jpg' ) );

expect( screen.getByRole( 'presentation' ) ).toHaveAttribute(
'src',
'https://example.com/a.jpg'
);
expect( screen.getByText( 'Launch video' ) ).toBeInTheDocument();
} );

it( 'renders the fallback icon without a thumbnail', () => {
render( renderTitle() );

expect( screen.queryByRole( 'presentation' ) ).not.toBeInTheDocument();
expect( screen.getByTestId( 'report-thumbnail-placeholder' ) ).toBeInTheDocument();
} );

it( 'falls back after a load failure and retries when the URL changes', () => {
const { rerender } = render( renderTitle( 'https://example.com/a.jpg' ) );

fireEvent.error( screen.getByRole( 'presentation' ) );
expect( screen.getByTestId( 'report-thumbnail-placeholder' ) ).toBeInTheDocument();

rerender( renderTitle( 'https://example.com/b.jpg' ) );
expect( screen.getByRole( 'presentation' ) ).toHaveAttribute(
'src',
'https://example.com/b.jpg'
);
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export {
} from './report-performance-chart';
export { ReportDrilldownTable, type ReportDrilldownTableProps } from './report-drilldown-table';
export { ReportRecordsTable, type ReportRecordsTableProps } from './report-records-table';
export { ReportThumbnailTitle } from './report-thumbnail-title';
export { useReportRetry } from './use-report-retry';
export {
ReportPageTabPanel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type ReportCsvActionProps< Row > = Pick<
export function ReportCsvAction< Row >( props: ReportCsvActionProps< Row > ) {
return (
<RowsCsvDownloadButton
label={ __( 'Download', 'jetpack-premium-analytics-pkg' ) }
label={ __( 'Download CSV', 'jetpack-premium-analytics-pkg' ) }
variant="solid"
showIcon={ false }
showLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { ReportDateFilters } from '@jetpack-premium-analytics/routing';
import type { ReactNode } from 'react';

export interface ReportPageLayoutProps {
/** Heading for the section on screen: `Posts & Pages report`. */
/** Heading for the section on screen: `Posts & Pages`. */
title: string;
/** Date-filter controller, from `useReportDateFilters`. Omit on a report with no date window. */
dateFilters?: ReportDateFilters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
}

.thumbnailSlot {
--post-thumbnail-size: 32px;
--report-thumbnail-size: 32px;

display: grid;
place-items: center;
flex-shrink: 0;
inline-size: var(--post-thumbnail-size);
block-size: var(--post-thumbnail-size);
inline-size: var(--report-thumbnail-size);
block-size: var(--report-thumbnail-size);
overflow: hidden;
background: var(--wpds-color-background-surface-neutral-weak);
color: var(--wpds-color-foreground-content-neutral-weak);
border-radius: var(--wpds-border-radius-md);
}

.thumbnail {
inline-size: var(--post-thumbnail-size);
block-size: var(--post-thumbnail-size);
inline-size: var(--report-thumbnail-size);
block-size: var(--report-thumbnail-size);
border-radius: var(--wpds-border-radius-md);
object-fit: cover;
}

/* DataViews adds these modifiers to its table from the selected density. */
:global(.dataviews-view-table.has-compact-density) .thumbnailSlot {
--post-thumbnail-size: 24px;
--report-thumbnail-size: 24px;
}

:global(.dataviews-view-table.has-comfortable-density) .thumbnailSlot {
--post-thumbnail-size: 40px;
--report-thumbnail-size: 40px;
}

.titleLink {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* External dependencies
*/
import { Icon, Stack } from '@jetpack-premium-analytics/externals';
import { useCallback, useState, type ComponentProps, type ReactNode } from 'react';
/**
* Internal dependencies
*/
import styles from './report-thumbnail-title.module.scss';
import type { PostTitleLinkProps } from '../post-title-link/post-title-link';
import type { VideoTitleLinkProps } from '../video-title-link/video-title-link';

const TITLE_LINK_CLASS_NAMES = {
internal: styles.titleLink,
external: styles.titleLink,
plain: styles.titleLink,
text: styles.titleText,
} satisfies NonNullable< PostTitleLinkProps[ 'classNames' ] > &
NonNullable< VideoTitleLinkProps[ 'classNames' ] >;

type ReportThumbnailTitleProps = {
thumbnailUrl?: string;
/** Shown when there is no thumbnail, or it fails to load. */
fallbackIcon: ComponentProps< typeof Icon >[ 'icon' ];
/** Renders the title link; pass it the class names so a long title truncates. */
children: ( linkClassNames: typeof TITLE_LINK_CLASS_NAMES ) => ReactNode;
};

/**
* A report row title led by the entity's thumbnail.
*
* @param props - Component props.
* @param props.thumbnailUrl - Thumbnail URL.
* @param props.fallbackIcon - Icon shown without a loadable thumbnail.
* @param props.children - Renders the title.
* @return The thumbnail and title.
*/
export function ReportThumbnailTitle( {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DataViews table layout already renders a thumbnail beside the title through view.mediaField (column-primary.tsx, and in the table story), and ReportRecordsTable already keeps mediaField out of the column list. A custom render on that field could keep the icon fallback, so the one difference I can find is the density sizing: the core box stays 32px in every density. Could Posts & Pages and Videos use mediaField instead of a second thumbnail slot in the toolkit, with density-aware sizing proposed upstream if the team wants it? Fine as a follow-up if you want to keep this one small.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, opened WOOA7S-2237 for it since titleField would bold the titles and needs a design call.

thumbnailUrl,
fallbackIcon,
children,
}: ReportThumbnailTitleProps ): JSX.Element {
const [ failedUrl, setFailedUrl ] = useState< string >();
const handleError = useCallback( () => setFailedUrl( thumbnailUrl ), [ thumbnailUrl ] );

return (
<Stack render={ <span /> } direction="row" gap="sm" align="center" className={ styles.title }>
<span className={ styles.thumbnailSlot }>
{ thumbnailUrl && failedUrl !== thumbnailUrl ? (
<img
src={ thumbnailUrl }
alt=""
width={ 32 }
height={ 32 }
loading="lazy"
className={ styles.thumbnail }
onError={ handleError }
/>
) : (
<span data-testid="report-thumbnail-placeholder">
<Icon icon={ fallbackIcon } size={ 16 } />
</span>
) }
</span>
{ children( TITLE_LINK_CLASS_NAMES ) }
</Stack>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export {
ReportPageTabs,
ReportPerformanceChart,
ReportRecordsTable,
ReportThumbnailTitle,
useReportRetry,
buildReportMetricSeries,
type ReportChartMetric,
Expand Down
Loading
Loading