-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Moves category multi select from LatestPosts to QueryControls #20832
Changes from 6 commits
958adbe
f66347d
ddb2c83
a0ffc4a
41ed91a
490b221
ed4ecfa
e24581a
213735f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { Platform } from '@wordpress/element'; | |
/** | ||
* Internal dependencies | ||
*/ | ||
import { RangeControl, SelectControl } from '../'; | ||
import { RangeControl, SelectControl, FormTokenField } from '../'; | ||
import CategorySelect from './category-select'; | ||
|
||
const DEFAULT_MIN_ITEMS = 1; | ||
|
@@ -26,7 +26,7 @@ const MOBILE_CONTROL_PROPS_SEPARATOR_NONE = Platform.select( { | |
|
||
export default function QueryControls( { | ||
categoriesList, | ||
selectedCategoryId, | ||
selectedCategories, | ||
numberOfItems, | ||
order, | ||
orderBy, | ||
|
@@ -37,6 +37,14 @@ export default function QueryControls( { | |
onOrderChange, | ||
onOrderByChange, | ||
} ) { | ||
const suggestions = categoriesList.reduce( | ||
( accumulator, category ) => ( { | ||
...accumulator, | ||
[ category.name ]: category, | ||
} ), | ||
{} | ||
); | ||
|
||
return [ | ||
onOrderChange && onOrderByChange && ( | ||
<SelectControl | ||
|
@@ -76,16 +84,20 @@ export default function QueryControls( { | |
/> | ||
), | ||
onCategoryChange && ( | ||
<CategorySelect | ||
key="query-controls-category-select" | ||
categoriesList={ categoriesList } | ||
label={ __( 'Category' ) } | ||
noOptionLabel={ __( 'All' ) } | ||
selectedCategoryId={ selectedCategoryId } | ||
<FormTokenField | ||
label={ __( 'Categories' ) } | ||
value={ | ||
selectedCategories && | ||
selectedCategories.map( ( item ) => ( { | ||
id: item.id, | ||
value: item.name || item.value, | ||
} ) ) | ||
} | ||
suggestions={ Object.keys( suggestions ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What value should be max? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use a constant and the same value the
|
||
onChange={ onCategoryChange } | ||
{ ...MOBILE_CONTROL_PROPS } | ||
/> | ||
), | ||
|
||
onNumberOfItemsChange && ( | ||
<RangeControl | ||
key="query-controls-range-control" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this
categorySuggestions
because if we add other flat taxonomies they'll also have suggestions.