diff --git a/apps/posts/parts/cells/basic.ts b/apps/posts/parts/cells/basic.ts index 878b90c10..ecea9e7a9 100644 --- a/apps/posts/parts/cells/basic.ts +++ b/apps/posts/parts/cells/basic.ts @@ -1,6 +1,6 @@ /** * Posts app — the cells both modes render: the title (with its lock, - * status and reading-page badges and the Pages "View" link), the + * status and reading-page badges and the "View" link), the * author, the date, and the expanded sub-row. * * @public @@ -105,9 +105,9 @@ export function buildTitleCell( row: PostListItem, env: CellEnv ): HTMLElement { titleRow.appendChild( pill( STATUS_LABELS[ row.status ] ?? row.status, statusBadgeColor( row.status ), { uppercase: true } ) ); } - // Pages: a "View" link to the public URL, in a new tab so the user + // A "View" link to the public URL, in a new tab so the user // keeps the table state. - if ( isPages && typeof row.link === 'string' && row.link && row.status === 'publish' ) { + if ( typeof row.link === 'string' && row.link && row.status === 'publish' ) { const view = document.createElement( 'a' ); view.href = row.link; view.target = '_blank'; diff --git a/apps/posts/parts/query.php b/apps/posts/parts/query.php index 2bd528d40..8623fa5fc 100644 --- a/apps/posts/parts/query.php +++ b/apps/posts/parts/query.php @@ -44,7 +44,7 @@ function openstation_posts_window_default_query_args() { // another user is currently editing the row, so the title cell // can paint a small lock icon without an extra fetch. '_fields' => - 'id,title,status,date,date_gmt,modified,modified_gmt,author,categories,tags,comment_status,excerpt,openstation_lock,_links,_embedded', + 'id,title,status,date,date_gmt,modified,modified_gmt,author,categories,tags,comment_status,excerpt,openstation_lock,link,_links,_embedded', ); /** diff --git a/apps/posts/posts.test.ts b/apps/posts/posts.test.ts index 9a595f62d..3400b97ce 100644 --- a/apps/posts/posts.test.ts +++ b/apps/posts/posts.test.ts @@ -725,6 +725,18 @@ describe( 'the cells', () => { const draft = buildTitleCell( row( 6, { status: 'draft', link: 'http://x.test/d' } ), env ); expect( pills( draft ) ).toEqual( [ 'Posts page', 'Draft' ] ); expect( draft.querySelector( 'a[target="_blank"]' ) ).toBeNull(); + + const postEnv = cellEnv( { extra: { mode: 'posts', editPostUrlBase: 'http://x.test/wp-admin/post.php' } } ); + const publishedPost = buildTitleCell( + row( 7, { + title: { rendered: 'Published Story' }, + link: 'http://x.test/published-story', + status: 'publish', + } ), + postEnv, + ); + expect( publishedPost.querySelector( 'a[target="_blank"]' )?.textContent ).toBe( 'View' ); + expect( publishedPost.querySelector( 'a[target="_blank"]' )?.getAttribute( 'href' ) ).toBe( 'http://x.test/published-story' ); } ); it( 'the author cell paints the name as text, and nothing for an author core could not embed', () => { diff --git a/docs/hooks-reference.md b/docs/hooks-reference.md index 365581667..4b8006a8e 100644 --- a/docs/hooks-reference.md +++ b/docs/hooks-reference.md @@ -3403,7 +3403,7 @@ Default args: ```php [ '_embed' => 'author,wp:term,wp:featuredmedia', - '_fields' => 'id,title,status,date,date_gmt,modified,modified_gmt,author,categories,tags,comment_status,excerpt,openstation_lock,_links,_embedded', + '_fields' => 'id,title,status,date,date_gmt,modified,modified_gmt,author,categories,tags,comment_status,excerpt,openstation_lock,link,_links,_embedded', ] ``` diff --git a/tests/phpunit/tests/postsApp.php b/tests/phpunit/tests/postsApp.php index 3d7c55baf..c760ebbe7 100644 --- a/tests/phpunit/tests/postsApp.php +++ b/tests/phpunit/tests/postsApp.php @@ -200,7 +200,7 @@ public function test_default_query_args_include_embed_and_fields() { $this->assertStringContainsString( 'author', $args['_embed'] ); $this->assertStringContainsString( 'wp:term', $args['_embed'] ); $this->assertStringContainsString( 'wp:featuredmedia', $args['_embed'] ); - foreach ( array( 'title', 'status', 'date', 'openstation_lock', '_embedded' ) as $field ) { + foreach ( array( 'title', 'status', 'date', 'openstation_lock', 'link', '_embedded' ) as $field ) { $this->assertStringContainsString( $field, $args['_fields'] ); } }