Repository navigation
Premium Analytics: Add video thumbnails and drop "report" from report headings #52908
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c1753a1
Premium Analytics: Add video thumbnails and tidy report titles and th…
chihsuan 335a767
Premium Analytics: Cover the empty video poster case
chihsuan ab878d0
Premium Analytics: Drop getTitle and resize video poster thumbnails
chihsuan 77dc65e
Premium Analytics: Drop the deleted report-names test from its test g…
chihsuan 3cf572e
Premium Analytics: Trim duplicated thumbnail fallback tests
chihsuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/premium-analytics/changelog/update-report-titles-video-thumbnails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ages/widgets-toolkit/src/components/report-page/__tests__/report-thumbnail-title.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | ||
| ); | ||
| } ); | ||
| } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...-analytics/packages/widgets-toolkit/src/components/report-page/report-thumbnail-title.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( { | ||
| 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> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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), andReportRecordsTablealready keepsmediaFieldout of the column list. A customrenderon 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 usemediaFieldinstead 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.There was a problem hiding this comment.
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
titleFieldwould bold the titles and needs a design call.