1+ import classnames from 'classnames' ;
12import isEmpty from 'lodash-es/isEmpty' ;
3+ import some from 'lodash-es/some' ;
4+ import filter from 'lodash-es/filter' ;
25import map from 'lodash-es/map' ;
36import partial from 'lodash-es/partial' ;
47import PropTypes from 'prop-types' ;
58import React from 'react' ;
9+ import { t } from 'i18next' ;
610
711import ProjectPreview from '../../containers/ProjectPreview' ;
812
@@ -23,8 +27,17 @@ const ProjectPicker = createMenu({
2327 isUserAuthenticated ;
2428 } ,
2529
26- renderItems ( { currentProjectKey, projectKeys, onChangeCurrentProject} ) {
27- return map ( projectKeys , projectKey => (
30+ renderItems ( {
31+ currentProjectKey,
32+ projects,
33+ shouldShowArchivedProjects,
34+ onChangeCurrentProject,
35+ onToggleViewArchived,
36+ } ) {
37+ const visibleProjects = shouldShowArchivedProjects ?
38+ projects :
39+ filter ( projects , ( { isArchived} ) => ! isArchived ) ;
40+ const items = map ( visibleProjects , ( { projectKey} ) => (
2841 < MenuItem
2942 isActive = { projectKey === currentProjectKey }
3043 key = { projectKey }
@@ -33,12 +46,37 @@ const ProjectPicker = createMenu({
3346 < ProjectPreview projectKey = { projectKey } />
3447 </ MenuItem >
3548 ) ) ;
49+
50+ if ( some ( projects , 'isArchived' ) ) {
51+ items . push (
52+ < div
53+ className = { classnames (
54+ 'top-bar__menu-item' ,
55+ 'top-bar__menu-item_toggle-archived-projects-button' ,
56+ ) }
57+ key = "toggleShowArchivedProjects"
58+ onClick = { onToggleViewArchived }
59+ >
60+ < div >
61+ {
62+ shouldShowArchivedProjects ?
63+ t ( 'top-bar.hide-projects' ) :
64+ t ( 'top-bar.show-projects' )
65+ }
66+ </ div >
67+ </ div > ,
68+ ) ;
69+ }
70+
71+ return items ;
3672 } ,
3773} ) ( ProjectPickerButton ) ;
3874
3975ProjectPicker . propTypes = {
4076 currentProjectKey : PropTypes . string ,
41- projectKeys : PropTypes . arrayOf ( PropTypes . string ) . isRequired ,
77+ projects : PropTypes . array . isRequired ,
78+ shouldShowArchivedProjects : PropTypes . bool . isRequired ,
79+ onToggleViewArchived : PropTypes . func . isRequired ,
4280} ;
4381
4482ProjectPicker . defaultProps = {
0 commit comments