@@ -18,7 +18,9 @@ var PageList = require( './page-list' ),
18
18
config = require ( 'config' ) ,
19
19
notices = require ( 'notices' ) ;
20
20
21
- module . exports = React . createClass ( {
21
+ const statuses = [ 'published' , 'drafts' , 'scheduled' , 'trashed' ] ;
22
+
23
+ module . exports = React . createClass ( {
22
24
23
25
displayName : 'Pages' ,
24
26
@@ -49,59 +51,58 @@ module.exports = React.createClass({
49
51
} ,
50
52
51
53
render : function ( ) {
52
- var siteFilter = this . props . sites . selected ? '/' + this . props . sites . selected : '' ,
53
- statusSlug = this . props . status ,
54
- searchPlaceholder , selectedText , filterStrings ;
55
-
56
- filterStrings = {
57
- drafts : this . translate ( 'Drafts' , { context : 'Filter label for pages list' } ) ,
54
+ const status = this . props . status || 'published' ;
55
+ const filterStrings = {
58
56
published : this . translate ( 'Published' , { context : 'Filter label for pages list' } ) ,
59
- trashed : this . translate ( 'Trash' , { context : 'Filter label for pages list' } ) ,
60
- status : this . translate ( 'Status' )
57
+ drafts : this . translate ( 'Drafts' , { context : 'Filter label for pages list' } ) ,
58
+ scheduled : this . translate ( 'Scheduled' , { context : 'Filter label for pages list' } ) ,
59
+ trashed : this . translate ( 'Trash' , { context : 'Filter label for pages list' } )
60
+ } ;
61
+ const searchStrings = {
62
+ published : this . translate ( 'Search published…' , { context : 'Search placeholder for pages list' , textOnly : true } ) ,
63
+ drafts : this . translate ( 'Search drafts…' , { context : 'Search placeholder for pages list' , textOnly : true } ) ,
64
+ scheduled : this . translate ( 'Search scheduled…' , { context : 'Search placeholder for pages list' , textOnly : true } ) ,
65
+ trashed : this . translate ( 'Search trash…' , { context : 'Search placeholder for pages list' , textOnly : true } )
61
66
} ;
62
-
63
-
64
-
65
- switch ( statusSlug ) {
66
- case 'drafts' :
67
- searchPlaceholder = this . translate ( 'Search drafts…' , { context : 'Search placeholder for pages list' , textOnly : true } ) ;
68
- selectedText = filterStrings . drafts ;
69
- break ;
70
- case 'trashed' :
71
- searchPlaceholder = this . translate ( 'Search trash…' , { context : 'Search placeholder for pages list' , textOnly : true } ) ;
72
- selectedText = filterStrings . trashed ;
73
- break ;
74
- default :
75
- searchPlaceholder = this . translate ( 'Search published…' , { context : 'Search placeholder for pages list' , textOnly : true } ) ;
76
- selectedText = filterStrings . published ;
77
- break ;
78
- }
79
-
80
67
return (
81
68
< div className = "main main-column pages" role = "main" >
82
69
< SidebarNavigation />
83
-
84
- < SectionNav selectedText = { selectedText } >
85
- < NavTabs label = { filterStrings . status } >
86
- < NavItem path = { '/pages' + siteFilter } selected = { ! statusSlug } > { filterStrings . published } </ NavItem >
87
- < NavItem path = { '/pages/drafts' + siteFilter } selected = { statusSlug === 'drafts' } > { filterStrings . drafts } </ NavItem >
88
- < NavItem path = { '/pages/trashed' + siteFilter } selected = { statusSlug === 'trashed' } > { filterStrings . trashed } </ NavItem >
70
+ < SectionNav selectedText = { filterStrings [ status ] } >
71
+ < NavTabs label = { this . translate ( 'Status' , { context : 'Filter page group label for tabs' } ) } >
72
+ { this . getNavItems ( filterStrings , status ) }
89
73
</ NavTabs >
90
74
< Search
91
75
pinned = { true }
92
76
onSearch = { this . doSearch }
93
77
initialValue = { this . props . search }
94
- placeholder = { searchPlaceholder }
78
+ placeholder = { searchStrings [ status ] }
95
79
analyticsGroup = "Pages"
96
80
delaySearch = { true }
97
81
/>
98
82
</ SectionNav >
99
-
100
83
< PageList { ...this . props } />
101
84
</ div >
102
85
) ;
103
86
} ,
104
87
88
+ getNavItems ( filterStrings , currentStatus ) {
89
+ const siteFilter = this . props . sites . selected ? '/' + this . props . sites . selected : '' ;
90
+ return statuses . map ( function ( status ) {
91
+ let path = `/pages${ siteFilter } ` ;
92
+ if ( status !== 'publish' ) {
93
+ path = `/pages/${ status } ${ siteFilter } ` ;
94
+ }
95
+ return (
96
+ < NavItem
97
+ path = { path }
98
+ selected = { currentStatus === status }
99
+ key = { `page-filter-${ status } ` } >
100
+ { filterStrings [ status ] }
101
+ </ NavItem >
102
+ ) ;
103
+ } ) ;
104
+ } ,
105
+
105
106
_setWarning ( selectedSite ) {
106
107
if ( selectedSite && selectedSite . jetpack && ! selectedSite . hasMinimumJetpackVersion ) {
107
108
notices . warning (
@@ -110,4 +111,4 @@ module.exports = React.createClass({
110
111
) ;
111
112
}
112
113
}
113
- } ) ;
114
+ } ) ;
0 commit comments