Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "DataViews Sidebar: Display item count on DataViews sidebar" #65625

Merged
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
Expand Up @@ -27,7 +27,6 @@ export default function DataViewItem( {
isActive,
isCustom,
suffix,
navigationItemSuffix,
} ) {
const {
params: { postType },
Expand Down Expand Up @@ -56,7 +55,6 @@ export default function DataViewItem( {
<SidebarNavigationItem
icon={ iconToUse }
{ ...linkInfo }
suffix={ navigationItemSuffix }
aria-current={ isActive ? 'true' : undefined }
>
{ title }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
notAllowed,
} from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { store as coreStore, useEntityRecords } from '@wordpress/core-data';
import { store as coreStore } from '@wordpress/core-data';
import { useMemo } from '@wordpress/element';

/**
Expand Down Expand Up @@ -68,50 +68,6 @@ const DEFAULT_POST_BASE = {
layout: defaultLayouts[ LAYOUT_LIST ].layout,
};

export function useDefaultViewsWithItemCounts( { postType } ) {
const defaultViews = useDefaultViews( { postType } );
const { records, totalItems } = useEntityRecords( 'postType', postType, {
per_page: -1,
status: [ 'any', 'trash' ],
} );

return useMemo( () => {
if ( ! defaultViews ) {
return [];
}

// If there are no records, return the default views with no counts.
if ( ! records ) {
return defaultViews;
}

const counts = {
drafts: records.filter( ( record ) => record.status === 'draft' )
.length,
future: records.filter( ( record ) => record.status === 'future' )
.length,
pending: records.filter( ( record ) => record.status === 'pending' )
.length,
private: records.filter( ( record ) => record.status === 'private' )
.length,
published: records.filter(
( record ) => record.status === 'publish'
).length,
trash: records.filter( ( record ) => record.status === 'trash' )
.length,
};

// All items excluding trashed items as per the default "all" status query.
counts.all = totalItems ? totalItems - counts.trash : 0;

// Filter out views with > 0 item counts.
return defaultViews.map( ( _view ) => {
_view.count = counts[ _view.slug ];
return _view;
} );
}, [ defaultViews, records, totalItems ] );
}

export function useDefaultViews( { postType } ) {
const labels = useSelect(
( select ) => {
Expand Down
9 changes: 2 additions & 7 deletions packages/edit-site/src/components/sidebar-dataviews/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';
/**
* Internal dependencies
*/
import { useDefaultViewsWithItemCounts } from './default-views';
import { useDefaultViews } from './default-views';
import { unlock } from '../../lock-unlock';
import DataViewItem from './dataview-item';
import CustomDataViewsList from './custom-dataviews-list';
Expand All @@ -18,9 +18,7 @@ export default function DataViewsSidebarContent() {
const {
params: { postType, activeView = 'all', isCustom = 'false' },
} = useLocation();

const defaultViews = useDefaultViewsWithItemCounts( { postType } );

const defaultViews = useDefaultViews( { postType } );
if ( ! postType ) {
return null;
}
Expand All @@ -36,9 +34,6 @@ export default function DataViewsSidebarContent() {
slug={ dataview.slug }
title={ dataview.title }
icon={ dataview.icon }
navigationItemSuffix={
<span>{ dataview.count }</span>
}
type={ dataview.view.type }
isActive={
! isCustomBoolean &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
min-width: initial;
}

.edit-site-sidebar-navigation-item.with-suffix {
padding-right: $grid-unit-10;
}

&:hover,
&:focus,
&[aria-current] {
Expand Down
Loading