Skip to content
Open
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
21 changes: 12 additions & 9 deletions src/js/_enqueues/admin/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<tr class="no-items"><td class="colspanchange" colspan="' + colspan + '">' +
wp.i18n.__( 'No tags found.' ) +
'</td></tr>'
);
}
if ( ! $list.find( 'tr.no-items' ).length ) {
var colspan = $list.closest( 'table' ).find( 'thead > tr' ).first().children( ':not(.hidden)' ).length;

$( '<tr class="no-items"><td class="colspanchange"></td></tr>' )
.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 {
Expand Down
8 changes: 8 additions & 0 deletions src/wp-admin/edit-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
Expand Down
43 changes: 43 additions & 0 deletions tests/e2e/specs/taxonomies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading