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,3 @@
Significance: patch
Type: changed
Comment: Make the post-detail View post action a real link.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export { DateRangeCalendar } from '@automattic/ui';
export {
Button,
EmptyState,
LinkButton,
Field as FormField,
Fieldset,
Icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,3 @@
flex: 0 0 auto;
margin-inline-start: auto;
}

// The header action is a Button rendered as an anchor, so it can carry a real
// href to the live post. @wordpress/ui styles the button inside `@layer wp-ui`,
// and wp-admin colours bare anchors outside any cascade layer — unlayered wins
// over layered whatever the specificity, so admin's link blue overrode the
// button foreground. Re-apply the button's own colour from here (unlayered).
.viewPost:any-link {
color: var(--wp-ui-button-foreground-color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,38 +188,40 @@ describe( 'post detail stage', () => {

render( stage() );

const action = screen.getByRole( 'link', { name: 'View post' } );
// `openInNewTab` appends a screen-reader hint to the accessible name.
const action = screen.getByRole( 'link', { name: 'View post(opens in a new tab)' } );

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.

Since the accessible name now ends in "(opens in a new tab)", the /^View (post|page)$/ regex in the two "omits the action" tests below (lines 216 and 224) can no longer match a rendered link, so they pass even if safeHttpUrl is removed. Dropping the $ anchor keeps both tests meaningful.

expect( action ).toHaveAttribute( 'href', 'https://example.com/hello-world/' );
expect( action ).toHaveAttribute( 'target', '_blank' );
expect( action ).toHaveAttribute( 'rel', 'noopener noreferrer' );
} );

it( 'labels the action View page for a page', () => {
mockSummary( { type: 'page', url: 'https://example.com/about/' } );

render( stage() );

expect( screen.getByRole( 'link', { name: 'View page' } ) ).toHaveAttribute(
expect( screen.getByRole( 'link', { name: 'View page(opens in a new tab)' } ) ).toHaveAttribute(
'href',
'https://example.com/about/'
);
expect( screen.queryByRole( 'link', { name: 'View post' } ) ).not.toBeInTheDocument();
expect(
screen.queryByRole( 'link', { name: 'View post(opens in a new tab)' } )
).not.toBeInTheDocument();
} );

it( 'omits the action while the post URL is unresolved', () => {
mockSummary( { url: undefined } );

render( stage() );

expect( screen.queryByRole( 'link', { name: /^View (post|page)$/ } ) ).not.toBeInTheDocument();
expect( screen.queryByRole( 'link', { name: /^View (post|page)/ } ) ).not.toBeInTheDocument();
} );

it( 'omits the action when the post URL carries an unsupported scheme', () => {
mockSummary( { url: 'javascript:alert(1)' } );

render( stage() );

expect( screen.queryByRole( 'link', { name: /^View (post|page)$/ } ) ).not.toBeInTheDocument();
expect( screen.queryByRole( 'link', { name: /^View (post|page)/ } ) ).not.toBeInTheDocument();
} );

// One declaration drives both halves: the panel reads it to drop the Compare
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
GlobalErrorProvider,
ReportScopeProvider,
} from '@jetpack-premium-analytics/data';
import { Button } from '@jetpack-premium-analytics/externals';
import { LinkButton } from '@jetpack-premium-analytics/externals';
import { useReportDateFilters } from '@jetpack-premium-analytics/routing';
import {
DateFiltersPanel,
Expand Down Expand Up @@ -142,19 +142,17 @@ function PostDetail(): JSX.Element {
breadcrumbs={ <StatsBreadcrumbs items={ breadcrumbs } /> }
actions={
publicUrl ? (
<Button
<LinkButton
variant="solid"
tone="neutral"
size="compact"
nativeButton={ false }
role="link"
className={ styles.viewPost }
render={ <a href={ publicUrl } target="_blank" rel="noopener noreferrer" /> }
href={ publicUrl }
openInNewTab
>
{ summary.type === 'page'
? __( 'View page', 'jetpack-premium-analytics-pkg' )
: __( 'View post', 'jetpack-premium-analytics-pkg' ) }
</Button>
</LinkButton>
) : undefined
}
className={ styles.page }
Expand Down
Loading