Skip to content

Commit

Permalink
Filter counter: only count filters that actually have a value applied
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Dec 13, 2023
1 parent cd2b253 commit 8482576
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/dataviews/src/add-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export default function AddFilter( { filters, view, onChangeView } ) {
return null;
}

const filterCount = view.filters.reduce( ( acc, filter ) => {
if ( filter.value !== undefined ) {
return acc + 1;
}
return acc;
}, 0 );

return (
<DropdownMenu
label={ __( 'Filters' ) }
Expand All @@ -53,9 +60,9 @@ export default function AddFilter( { filters, view, onChangeView } ) {
icon={ funnel }
className="dataviews-filters-button"
>
{ view.type === LAYOUT_LIST && view.filters.length > 0 ? (
{ view.type === LAYOUT_LIST && filterCount > 0 ? (
<span className="dataviews-filters-count">
{ view.filters.length }
{ filterCount }
</span>
) : null }
</Button>
Expand Down

0 comments on commit 8482576

Please sign in to comment.