From 017e3d5d8d6d8018f366f25b91a077567bb4bd95 Mon Sep 17 00:00:00 2001 From: Jason Moon Date: Wed, 4 Sep 2019 17:20:53 -0600 Subject: [PATCH] Add rudimentary support for filtering on post types --- .../components/search-filter-post-types.jsx | 27 +++++++++++++++---- .../components/search-filters-widget.jsx | 20 +++++++++----- .../components/search-widget.jsx | 25 ++++++++++------- modules/search/instant-search/index.jsx | 9 ++++--- modules/search/instant-search/lib/api.js | 18 +++++++++++-- modules/search/instant-search/lib/dom.js | 6 +++++ .../search/instant-search/lib/query-string.js | 27 +++++++++++++++++++ 7 files changed, 105 insertions(+), 27 deletions(-) diff --git a/modules/search/instant-search/components/search-filter-post-types.jsx b/modules/search/instant-search/components/search-filter-post-types.jsx index 3ff2751426221..188edb8cdca91 100644 --- a/modules/search/instant-search/components/search-filter-post-types.jsx +++ b/modules/search/instant-search/components/search-filter-post-types.jsx @@ -3,18 +3,33 @@ /** * External dependencies */ -import { h, Component } from 'preact'; +import { h, createRef, Component } from 'preact'; import strip from 'strip'; +import { getCheckedInputNames } from '../lib/dom'; export default class SearchFilterPostTypes extends Component { + constructor( props ) { + super( props ); + this.state = { selected: this.props.initialValue }; + this.filtersList = createRef(); + } + + toggleFilter = () => { + const selected = getCheckedInputNames( this.filtersList.current ); + this.setState( { selected }, () => { + this.props.onChange( 'postTypes', selected ); + } ); + }; + renderPostType = ( { key, doc_count: count } ) => { - const name = this.props.postTypes[ key ]; + const name = key in this.props.postTypes ? this.props.postTypes[ key ] : key; return (