diff --git a/src/js/_enqueues/admin/tags.js b/src/js/_enqueues/admin/tags.js index 8d449ca986863..f410a51b1cda0 100644 --- a/src/js/_enqueues/admin/tags.js +++ b/src/js/_enqueues/admin/tags.js @@ -135,17 +135,20 @@ jQuery( function($) { ); if ( itemCount < 1 ) { - // No tags remain: show the empty-state row and hide the navigation. + // No terms remain: show the empty-state row and hide the navigation. var $list = $( '#the-list' ); - if ( ! $list.find( 'tr.no-items' ).length ) { - var colspan = $list.closest( 'table' ).find( 'thead > tr' ).first().children( ':not(.hidden)' ).length; - $list.append( - '' + - wp.i18n.__( 'No tags found.' ) + - '' - ); - } + if ( ! $list.find( 'tr.no-items' ).length ) { + var colspan = $list.closest( 'table' ).find( 'thead > tr' ).first().children( ':not(.hidden)' ).length; + + $( '' ) + .find( 'td' ) + .attr( 'colspan', colspan ) + // The label is filterable and may contain markup, so insert it as text. + .text( window.tagsL10n && window.tagsL10n.notFound || wp.i18n.__( 'No items found.' ) ) + .end() + .appendTo( $list ); + } $( '.tablenav > *' ).hide(); $( 'p.search-box' ).hide(); } else { diff --git a/src/wp-admin/edit-tags.php b/src/wp-admin/edit-tags.php index 6efdeb9b0527d..8e2cc70d2c00e 100644 --- a/src/wp-admin/edit-tags.php +++ b/src/wp-admin/edit-tags.php @@ -241,6 +241,14 @@ } wp_enqueue_script( 'admin-tags' ); +wp_localize_script( + 'admin-tags', + 'tagsL10n', + array( + // The taxonomy's "not found" label, used when the last term is removed via AJAX. + 'notFound' => $tax->labels->not_found, + ) +); if ( current_user_can( $tax->cap->edit_terms ) ) { wp_enqueue_script( 'inline-edit-tax' ); } diff --git a/tests/e2e/specs/taxonomies.test.js b/tests/e2e/specs/taxonomies.test.js index 2849e086e01b5..63d7a904bebdc 100644 --- a/tests/e2e/specs/taxonomies.test.js +++ b/tests/e2e/specs/taxonomies.test.js @@ -164,6 +164,49 @@ for ( const { taxonomy, endpoint, label } of [ expect( terms ).toEqual( [] ); } ); + test( 'shows the taxonomy label when the last matching term is deleted', async ( { + admin, + page, + requestUtils, + } ) => { + const term = await createTerm( requestUtils, 'delete-last' ); + await admin.visitAdminPage( + '/edit-tags.php', + `taxonomy=${ taxonomy }&s=${ prefix }` + ); + const row = page.locator( `#tag-${ term.id }` ); + await expect( row ).toBeVisible(); + await row.hover(); + await Promise.all( [ + page + .waitForEvent( 'dialog' ) + .then( ( dialog ) => dialog.accept() ), + row + .getByRole( 'button', { + name: `Delete “${ term.name }”`, + exact: true, + } ) + .click(), + ] ); + + // The row inserted by JavaScript must match the server-rendered message. + await expect( + page.getByRole( 'cell', { + name: + taxonomy === 'category' + ? 'No categories found.' + : 'No tags found.', + exact: true, + } ) + ).toBeVisible(); + await expect( + page.getByRole( 'cell', { + name: 'No tags found.', + exact: true, + } ) + ).toHaveCount( taxonomy === 'category' ? 0 : 1 ); + } ); + test( 'shows an empty result when searching for a missing term', async ( { admin, page,