forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataViews: add control to reset all filters at once (WordPress#55955)
* Add reset filters button * Set proper spacing/alignment for control * Fix lint * Also reset search * Disable reset button if no filters active * Properly manage keys * Managed undefined visibleFilters
- Loading branch information
Showing
2 changed files
with
63 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/edit-site/src/components/dataviews/reset-filters.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BaseControl, Button } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export default ( { view, onChangeView } ) => { | ||
return ( | ||
<BaseControl> | ||
<Button | ||
disabled={ view.search === '' && view.filters?.length === 0 } | ||
variant="tertiary" | ||
onClick={ () => { | ||
onChangeView( ( currentView ) => ( { | ||
...currentView, | ||
page: 1, | ||
search: '', | ||
filters: [], | ||
} ) ); | ||
} } | ||
> | ||
{ __( 'Reset filters' ) } | ||
</Button> | ||
</BaseControl> | ||
); | ||
}; |