Skip to content

Commit

Permalink
Allow resetting the own filter
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Dec 12, 2023
1 parent effaefd commit accafc8
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/dataviews/src/add-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Icon,
} from '@wordpress/components';
import { chevronRightSmall, funnel, check } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { Children, Fragment } from '@wordpress/element';

/**
Expand Down Expand Up @@ -240,6 +240,29 @@ export default function AddFilter( { filters, view, onChangeView } ) {
</DropdownMenuItem>
</DropdownSubMenu>
) }
<DropdownMenuItem
key={ 'reset-filter-' + filter.name }
disabled={ ! activeElement }
onSelect={ ( event ) => {
event.preventDefault();
onChangeView( ( currentView ) => ( {
...currentView,
page: 1,
filters:
currentView.filters.filter(
( f ) =>
f.field !==
filter.field
),
} ) );
} }
>
{ sprintf(
/* translators: 1: Filter name. e.g.: "Reset Author". */
__( 'Reset %1$s' ),
filter.name.toLowerCase()
) }
</DropdownMenuItem>
</WithSeparators>
</DropdownSubMenu>
);
Expand Down

0 comments on commit accafc8

Please sign in to comment.