@@ -30,7 +30,7 @@ import {
3030 versionStatusFilters
3131} from '../util'
3232import { getVersionValidationSummaryByFilterStrategy } from '../util/version'
33-
33+ import FeedLabel from '../../common/components/FeedLabel'
3434import type { ExtensionType } from '../../types'
3535import type { Props as ContainerProps } from '../containers/ProjectFeedListToolbar'
3636import type {
@@ -50,7 +50,8 @@ type Props = ContainerProps & {
5050 projectEditDisabled : boolean ,
5151 setFeedSort : typeof projectsActions . setFeedSort ,
5252 setFeedSourceTableFilterCountStrategy : typeof projectsActions . setFeedSourceTableFilterCountStrategy ,
53- setVisibilityFilter : typeof visibilityFilterActions . setVisibilitySearchText ,
53+ setVisibilityFilter : typeof visibilityFilterActions . setVisibilityFilter ,
54+ setVisibilityLabel : typeof visibilityFilterActions . setVisibilityLabel ,
5455 setVisibilitySearchText : typeof visibilityFilterActions . setVisibilitySearchText ,
5556 sort : FeedSourceTableSortStrategiesWithOrders ,
5657 thirdPartySync : typeof projectsActions . thirdPartySync ,
@@ -288,6 +289,33 @@ export default class ProjectFeedListToolbar extends PureComponent<Props> {
288289 return options
289290 }
290291
292+ _renderLabelFilter = ( ) => {
293+ const { project, setVisibilityLabel } = this . props
294+ // This variable must be set directly from this.props both
295+ // to allow the override and for flow
296+ const labels = this . props . filter . labels || [ ]
297+
298+ function handleClick ( labelId : string ) {
299+ const index = labels . indexOf ( labelId )
300+ index >= 0 ? labels . splice ( index , 1 ) : labels . push ( labelId )
301+ setVisibilityLabel ( labels )
302+ }
303+ return < MenuItem header style = { { minWidth : 275 } } >
304+ < h5 > Select labels to filter by</ h5 >
305+ < div className = 'feedLabelContainer' >
306+ { project . labels . map ( ( label ) => (
307+ < FeedLabel
308+ key = { label . id }
309+ label = { label }
310+ checked = { labels . includes ( label . id ) }
311+ small
312+ onClick = { ( ) => handleClick ( label . id ) }
313+ />
314+ ) ) }
315+ </ div >
316+ </ MenuItem >
317+ }
318+
291319 _renderFilterToolbarLabel = ( ) = > {
292320 const { filter, possibleComparisons} = this . props
293321
@@ -331,6 +359,7 @@ export default class ProjectFeedListToolbar extends PureComponent<Props> {
331359
332360 const activeFilter = filter . filter || 'all'
333361 const nonFilterColumnOffset = 25
362+ const activeFilterLabelCount = ( filter . labels && filter . labels . length ) || 0
334363
335364 return (
336365 < Row >
@@ -359,7 +388,7 @@ export default class ProjectFeedListToolbar extends PureComponent<Props> {
359388 < FormGroup id = 'feedFilterToolbarControl' >
360389 { this . _renderFilterToolbarLabel ( ) }
361390 < ButtonGroup >
362- { Object . keys ( versionStatusFilters ) . map ( filterOption => (
391+ { Object . keys ( versionStatusFilters ) . map ( ( filterOption ) => (
363392 < OptionButton
364393 active = { activeFilter === filterOption }
365394 className = { activeFilter === filterOption ? 'active' : '' }
@@ -368,12 +397,27 @@ export default class ProjectFeedListToolbar extends PureComponent<Props> {
368397 value = { filterOption }
369398 >
370399 { this . messages ( `filter.${ filterOption } ` ) } { ' ' }
371- < Badge
372- style = { { backgroundColor : '#babec0' } } >
400+ < Badge style = { { backgroundColor : '#babec0' } } >
373401 { filterCounts [ filterOption ] }
374402 </ Badge >
375403 </ OptionButton >
376404 ) ) }
405+ < DropdownButton
406+ id = 'project-feedsource-label-filter-button'
407+ // to match the buttons with badges
408+ style = { { paddingBottom : 7 } }
409+ title = {
410+ < span
411+ style = { {
412+ fontWeight : activeFilterLabelCount > 0 ? 'bold' : ''
413+ } }
414+ >
415+ Labels
416+ </ span >
417+ }
418+ >
419+ { this . _renderLabelFilter ( ) }
420+ </ DropdownButton >
377421 </ ButtonGroup >
378422 </ FormGroup >
379423 </ Col >
@@ -385,7 +429,7 @@ export default class ProjectFeedListToolbar extends PureComponent<Props> {
385429 style = { { marginLeft : 20 } }
386430 title = 'Actions'
387431 >
388- { ! projectEditDisabled &&
432+ { ! projectEditDisabled && (
389433 < MenuItem
390434 data-test-id = 'project-header-create-new-feed-source-button'
391435 disabled = { projectEditDisabled }
@@ -394,7 +438,7 @@ export default class ProjectFeedListToolbar extends PureComponent<Props> {
394438 >
395439 < Glyphicon glyph = 'plus' /> { this . messages ( 'feeds.new' ) }
396440 </ MenuItem >
397- }
441+ ) }
398442 { this . _renderSyncMenuItem ( 'transitland' ) }
399443 { this . _renderSyncMenuItem ( 'transitfeeds' ) }
400444 { this . _renderSyncMenuItem ( 'mtc' ) }
@@ -405,16 +449,10 @@ export default class ProjectFeedListToolbar extends PureComponent<Props> {
405449 >
406450 < Icon type = 'cloud-download' /> { this . messages ( 'feeds.update' ) }
407451 </ MenuItem >
408- < MenuItem
409- key = 'merge-feeds-button'
410- onClick = { this . _onDownloadMerged }
411- >
452+ < MenuItem key = 'merge-feeds-button' onClick = { this . _onDownloadMerged } >
412453 < Glyphicon glyph = 'download' /> { this . messages ( 'mergeFeeds' ) }
413454 </ MenuItem >
414- < MenuItem
415- key = 'csv-download-button'
416- onClick = { this . _onCsvDownload }
417- >
455+ < MenuItem key = 'csv-download-button' onClick = { this . _onCsvDownload } >
418456 < Icon type = 'table' /> { this . messages ( 'downloadCsv' ) }
419457 </ MenuItem >
420458 </ DropdownButton >
0 commit comments