Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c9f6d16
feat: Add items count to post status tabs
im3dabasia Aug 31, 2026
40d0959
feat: Add count in the server side and use it in tabs
im3dabasia Sep 8, 2026
fae9bb3
fix: Invalidate stale counts for pages
im3dabasia Sep 8, 2026
e618f45
Revert "fix: Invalidate stale counts for pages"
im3dabasia Sep 9, 2026
0736cf4
feat: Move code logic from 7.1 to 7.2 for count schema and view-confi…
im3dabasia Sep 9, 2026
462cf8b
feat: Introduce a new view-tab-count component to show count of tabs
im3dabasia Sep 9, 2026
a048eb8
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Sep 9, 2026
fcb9518
fix: Remove tabs component from admin-ui
im3dabasia Sep 10, 2026
8ec5588
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Sep 10, 2026
41882f7
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 6, 2026
d09363c
Tests: Allow the item count in v2 status tab names
im3dabasia Oct 6, 2026
ed2060d
Post list: Refresh status tab counts after actions that change them
im3dabasia Oct 6, 2026
7ef8a12
Tests: Cover the post list status tab counts
im3dabasia Oct 6, 2026
b249b39
Post list: Refresh status tab counts when returning to the list
im3dabasia Oct 7, 2026
36b7b12
View config: Leave out the count of views narrowed by more than status
im3dabasia Oct 7, 2026
7f46b48
Add backport changelog entry for wordpress-develop#14070
im3dabasia Oct 7, 2026
0556bc9
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 7, 2026
dd40362
View config: Account for inherited filters when counting views
im3dabasia Oct 12, 2026
08e8734
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 12, 2026
2a68439
View config: Count a view only when every layout agrees on its filters
im3dabasia Oct 20, 2026
7a1b121
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 20, 2026
65b50ec
Actions: Report the items a partly failed restore or permanent delete…
im3dabasia Oct 20, 2026
37245e0
View config: Tighten the view counts for config search, repeated stat…
im3dabasia Oct 20, 2026
3db7456
Post list: Refresh status tab counts after any action
im3dabasia Oct 20, 2026
6cdf7f3
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 22, 2026
c73380b
Post list: Mute the tab count only on idle, unselected tabs
im3dabasia Oct 22, 2026
550a56a
Tests: Find the bulk actions in the table header
im3dabasia Oct 22, 2026
813beac
Post list: Mute the count on the selected tab too
im3dabasia Oct 23, 2026
33af598
View config: Target the view counts at WordPress 7.3
im3dabasia Oct 26, 2026
baf846d
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 26, 2026
6e8b4f2
Merge branch 'trunk' into feat/80683-add-tab-count
ciampo Oct 27, 2026
5f67102
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 28, 2026
d846a6d
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 28, 2026
529d5c3
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 28, 2026
0770f4a
Tests: Find the bulk actions outside the table
im3dabasia Oct 28, 2026
8479099
Site editor: Show the item counts in the v1 Pages sidebar
im3dabasia Oct 28, 2026
032edc5
Site editor: Refresh the v1 Pages sidebar counts after changes
im3dabasia Oct 28, 2026
ea52bfe
Tests: Cover the Pages status counts in both site editors
im3dabasia Oct 28, 2026
842a5c1
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 28, 2026
2225261
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Oct 29, 2026
3c29eae
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Nov 2, 2026
85e0199
Merge branch 'trunk' into feat/80683-add-tab-count
im3dabasia Nov 10, 2026
f371304
Tests: Convert the Pages status counts spec to TypeScript
im3dabasia Nov 10, 2026
6dcfa9e
View config: Count comma-separated and any statuses
im3dabasia Nov 16, 2026
63d312b
View config: Parse statuses as the REST API does
im3dabasia Nov 16, 2026
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
3 changes: 3 additions & 0 deletions backport-changelog/7.3/14070.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/14070

* https://github.com/WordPress/gutenberg/pull/82247
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* REST API: Gutenberg_REST_View_Config_Controller_7_3 class
*
* @package gutenberg
*/

/**
* Controller which provides a REST endpoint for retrieving the default
* view configuration for a given entity type.
*
* Extends the 7.2 controller to add the item count of each view in the `page`
* view list.
*
* @since 7.3.0
*
* @see Gutenberg_REST_View_Config_Controller_7_2
*/
class Gutenberg_REST_View_Config_Controller_7_3 extends Gutenberg_REST_View_Config_Controller_7_2 {

/**
* Returns the view configuration for the given entity type.
*
* Adds the item count of each view in the `page` view list. The counts are
* added here rather than through the view config filter, so that they are
* computed from the view list after every filter has changed it.
*
* @since 7.3.0
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_items( $request ) {
$response = parent::get_items( $request );
if ( is_wp_error( $response ) || 'postType' !== $request->get_param( 'kind' ) || 'page' !== $request->get_param( 'name' ) ) {
return $response;
}

// Skip the counting when the request leaves out the view list, such as
// the editor's request for the form alone.
if ( ! rest_is_field_included( 'view_list', $this->get_fields_for_response( $request ) ) ) {
return $response;
}

$data = $response->get_data();
if ( is_array( $data['view_list'] ) ) {
$data['view_list'] = _gutenberg_add_counts_to_view_list( 'page', $data['view_list'], $data['default_view'], $data['default_layouts'] );
$response->set_data( $data );
}

return $response;
}

/**
* Retrieves the view configuration schema, conforming to JSON Schema.
*
* Adds the `count` of each entry in the view list, which get_items()
* provides.
*
* @since 7.3.0
*
* @return array Item schema data.
*/
public function get_item_schema() {
$schema = parent::get_item_schema();

$schema['properties']['view_list']['items']['properties']['count'] = array(
'description' => __( 'Number of items the view holds.', 'gutenberg' ),
'type' => 'integer',
'readonly' => true,
);

return $schema;
}
}
19 changes: 19 additions & 0 deletions lib/compat/wordpress-7.3/rest-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* WordPress 7.3 compatibility functions for the Gutenberg
* editor plugin changes related to REST API.
*
* @package gutenberg
*/

/**
* Registers the View Config REST API routes.
*
* Replaces the 7.2 registration so the route is served by the 7.3 controller.
*/
function gutenberg_register_view_config_controller_endpoints_7_3() {
$view_config_controller = new Gutenberg_REST_View_Config_Controller_7_3();
$view_config_controller->register_routes();
}
remove_action( 'rest_api_init', 'gutenberg_register_view_config_controller_endpoints_7_2', PHP_INT_MAX );
add_action( 'rest_api_init', 'gutenberg_register_view_config_controller_endpoints_7_3', PHP_INT_MAX );
154 changes: 154 additions & 0 deletions lib/compat/wordpress-7.3/view-config-api.php

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three global functions are only used by the View Config controller. Even with an underscore prefix, global functions effectively become public API, and we take on the responsibility of maintaining them. It’s also unclear how, or whether, they’ll be used elsewhere in the future. For now, how about moving them into the controller as protected methods? The same applies to the Core PR.

Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
/**
* View config API: item counts of the view list.
*
* @package gutenberg
*/

/**
* Adds the item count of each view to a post type's view list.
*
* Runs on the view list as the client receives it, after every view config
* filter, so a count always describes the view it sits on. Only a view whose
* total a status count answers gets one: a view without filters, which lists
* every status but trash, and a view whose only filter is on the status. A view
* narrowed by anything else, such as a date filter a plugin added, is left
* without a count rather than showing a total it does not hold. That includes
* filters a view inherits from the default view or from the defaults of any
* layout it can be shown in.
*
* `wp_count_posts()` answers every view from one cached query, and its
* `readable` permission argument keeps private posts the current user cannot
* read out of the totals.
*
* @param string $post_type The post type the view list belongs to.
* @param array $view_list The view list.
* @param array|object $default_view The default view the views inherit from.
* @param array|object $default_layouts The default view properties of each layout.
* @return array The view list, with a count on each view a status total answers.
*/
function _gutenberg_add_counts_to_view_list( $post_type, $view_list, $default_view = array(), $default_layouts = array() ) {
$counts = (array) wp_count_posts( $post_type, 'readable' );

foreach ( $view_list as $index => $entry ) {
$statuses = _gutenberg_get_view_list_entry_statuses( $entry, $default_view, $default_layouts );
if ( null === $statuses ) {
continue;
}

$count = 0;
foreach ( $statuses as $status ) {
$count += isset( $counts[ $status ] ) ? (int) $counts[ $status ] : 0;
}
$view_list[ $index ]['count'] = $count;
}

return $view_list;
}

/**
* Returns the statuses a view list entry lists, when the status is all it
* filters by in every layout it can be shown in.
*
* The user can switch a view to any layout on offer, and each layout's defaults
* can bring filters of their own. The server cannot see which layout the user
* picked, so a count has to hold in all of them: when the layouts disagree, the
* entry gets none.
*
* The entry and defaults come from view config filters, so their shape is not
* trusted.
*
* @param mixed $entry A view list entry.
* @param array|object $default_view The default view the entry inherits from.
* @param array|object $default_layouts The default view properties of each layout.
* @return string[]|null The statuses, or null when the view filters by anything
* else in some layout or its shape is not recognized.
*/
function _gutenberg_get_view_list_entry_statuses( $entry, $default_view = array(), $default_layouts = array() ) {
if ( ! is_array( $entry ) ) {
return null;
}

$view = isset( $entry['view'] ) ? (array) $entry['view'] : array();
$default_view = (array) $default_view;
$default_layouts = (array) $default_layouts;

// Without layouts on offer, no layout defaults apply.
$layouts = empty( $default_layouts ) ? array( array() ) : $default_layouts;

$statuses = null;
foreach ( $layouts as $layout_defaults ) {
$layout_statuses = _gutenberg_get_layered_view_statuses(
array( $default_view, (array) $layout_defaults, $view )
);
if ( null === $layout_statuses || ( null !== $statuses && $layout_statuses !== $statuses ) ) {
return null;
}
$statuses = $layout_statuses;
}

return $statuses;
}

/**
* Returns the statuses a view lists, when the status is all it filters by.
*
* Resolves the view's filters out of its layers as the client does: a later
* layer that sets them replaces them outright rather than adding to them. A
* `search` in a layer is ignored, as the client drops it from the config and
* takes the search from the URL instead.
*
* @param array[] $layers The view's layers, lowest first.
* @return string[]|null The statuses, or null when the view filters by anything
* else or its shape is not recognized.
*/
function _gutenberg_get_layered_view_statuses( $layers ) {
$filters = array();
foreach ( $layers as $layer ) {
if ( array_key_exists( 'filters', $layer ) ) {
$filters = $layer['filters'];
}
}

if ( ! is_array( $filters ) ) {
return null;
}
if ( empty( $filters ) ) {
// Every status but trash, matching what a view without filters queries.
return array( 'publish', 'future', 'draft', 'pending', 'private' );
}
if ( 1 !== count( $filters ) ) {
return null;
}

$filter = (array) reset( $filters );
if (
! isset( $filter['field'], $filter['operator'], $filter['value'] ) ||
'status' !== $filter['field'] ||
! in_array( $filter['operator'], array( 'is', 'isAny' ), true )
) {
return null;
}

$values = is_array( $filter['value'] ) ? $filter['value'] : array( $filter['value'] );
$statuses = array();
foreach ( $values as $value ) {
if ( ! is_string( $value ) ) {
return null;
}

// The REST API also accepts several statuses in one value, separated by
// commas or spaces, and parses them the same way.
foreach ( wp_parse_slug_list( $value ) as $status ) {
if ( 'any' === $status ) {
// As in WP_Query, `any` is every status not excluded from search.
$statuses = array_merge( $statuses, array_values( get_post_stati( array( 'exclude_from_search' => false ) ) ) );
} else {
$statuses[] = $status;
}
}
}

// A status listed twice is still queried once.
return array_values( array_unique( $statuses ) );
}
5 changes: 5 additions & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ function gutenberg_get_experiment_default( $name ) {
require __DIR__ . '/compat/wordpress-7.2/entity-actions-api.php';
require __DIR__ . '/compat/wordpress-7.2/class-gutenberg-rest-entity-actions-controller-7-2.php';

// WordPress 7.3 compat.
require __DIR__ . '/compat/wordpress-7.3/view-config-api.php';
require __DIR__ . '/compat/wordpress-7.3/class-gutenberg-rest-view-config-controller-7-3.php';
require __DIR__ . '/compat/wordpress-7.3/rest-api.php';

// Real-time collaboration.
require __DIR__ . '/experimental/collaboration/class-gutenberg-rest-autosaves-controller.php';
require __DIR__ . '/experimental/collaboration/rest-api.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ const permanentlyDeletePost: ActionScriptParts< PostWithPermissions > = {
createErrorNotice( errorMessage, {
type: 'snackbar',
} );

// Some items may still have been deleted, so
// report those.
const deletedItems = items.filter(
( _item, index ) =>
promiseResult[ index ].status ===
'fulfilled'
);
if ( deletedItems.length > 0 ) {
onActionPerformed?.( deletedItems );
}
}

setIsBusy( false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ const restorePost: ActionScriptParts< PostWithPermissions > = {
createErrorNotice( errorMessage, {
type: 'snackbar',
} );

// Some posts may still have been restored, so report those.
const restoredPosts = posts.filter(
( _post, index ) =>
promiseResult[ index ].status === 'fulfilled'
);
if ( restoredPosts.length > 0 && onActionPerformed ) {
onActionPerformed( restoredPosts );
}
}
},
};
Expand Down
19 changes: 18 additions & 1 deletion packages/edit-site/src/components/post-list/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@wordpress/core-data';
import { useState, useMemo, useCallback, useEffect } from '@wordpress/element';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { DataViews } from '@wordpress/dataviews';
import { privateApis as editorPrivateApis } from '@wordpress/editor';
import { useEvent, usePrevious } from '@wordpress/compose';
Expand Down Expand Up @@ -222,9 +222,25 @@ export default function PostList( { postType } ) {
[ postType ]
);

// The sidebar counts come with the view config, which is cached per post
// type. Fetching it again after a change updates the counts only: the
// user's view lives in preferences, which this does not touch.
const { invalidateResolution } = useDispatch( coreStore );
const refreshViewCounts = useCallback( () => {
invalidateResolution( 'getViewConfig', [ 'postType', postType ] );
}, [ invalidateResolution, postType ] );

// Leaving the list, such as to publish a draft in the editor, can change
// the totals without any action here to report it. Marking the counts stale
// on the way out fetches them again on the way back.
useEffect( () => refreshViewCounts, [ refreshViewCounts ] );

const postTypeActions = usePostActions( {
postType,
context: 'list',
// Any action may change the totals, including a plugin's, so refresh
// after each one rather than tracking which do.
onActionPerformed: refreshViewCounts,
} );
const editAction = useEditPostAction();
const quickEditAction = useQuickEditPostAction();
Expand Down Expand Up @@ -319,6 +335,7 @@ export default function PostList( { postType } ) {
postType={ postType }
postId={ selection }
closeModal={ closeQuickEditModal }
onSave={ refreshViewCounts }
quickEditForm={ quickEditForm }
/>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function QuickEditModal( {
postType,
postId,
closeModal,
onSave: onSaved,
quickEditForm,
} ) {
const isBulk = postId.length > 1;
Expand Down Expand Up @@ -148,6 +149,7 @@ export function QuickEditModal( {
} else {
await saveEditedEntityRecord( 'postType', postType, postId[ 0 ] );
}
onSaved?.();
closeModal?.();
};

Expand Down
6 changes: 6 additions & 0 deletions packages/edit-site/src/components/sidebar-dataviews/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export default function DataViewsSidebarContent( {
<SidebarNavigationItem
key={ view.slug }
icon={ icon }
// Views narrowed by more than their status have no count.
suffix={
typeof view.count === 'number' && (
<span>{ view.count.toLocaleString() }</span>
)
}
to={ addQueryArgs( path, {
activeView: slug,
} ) }
Expand Down
Loading
Loading