@@ -7,7 +7,11 @@ import 'whatwg-fetch';
77export default class App extends React . Component {
88
99 static get allBranchName ( ) {
10- return 'all branches' ;
10+ return 'All Branches' ;
11+ }
12+
13+ static get defaultBranchName ( ) {
14+ return 'Default Branch' ;
1115 }
1216
1317 constructor ( props ) {
@@ -28,19 +32,28 @@ export default class App extends React.Component {
2832 this . fetchData ( { count : 100 } ) ;
2933 }
3034
31- selectBranch ( branch ) {
32- const params = { count : this . state . count } ;
33- if ( branch !== App . allBranchName ) {
34- params . branch = branch ;
35+ setParams ( branchName , params ) {
36+ const returnParams = params ;
37+ switch ( branchName ) {
38+ case App . allBranchName :
39+ returnParams . all = 1 ;
40+ break ;
41+ case App . defaultBranchName :
42+ returnParams . branch = this . state . defaultBranch ;
43+ break ;
44+ default :
45+ returnParams . branch = branchName ;
3546 }
47+ return returnParams ;
48+ }
49+
50+ selectBranch ( branch ) {
51+ const params = this . setParams ( branch , { count : this . state . count } ) ;
3652 this . fetchData ( params ) ;
3753 }
3854
3955 selectCount ( count ) {
40- const params = { count } ;
41- if ( this . state . currentBranch !== App . allBranchName ) {
42- params . branch = this . state . currentBranch ;
43- }
56+ const params = this . setParams ( this . state . currentBranch , { count } ) ;
4457 this . fetchData ( params ) ;
4558 }
4659
@@ -51,8 +64,7 @@ export default class App extends React.Component {
5164 r => r . json ( )
5265 ) . then ( data => {
5366 const newState = Object . assign ( { count : params . count , isFetching : false } , data ) ;
54- newState . branches . push ( App . allBranchName ) ;
55- if ( ! data . currentBranch ) {
67+ if ( data . all ) {
5668 newState . currentBranch = App . allBranchName ;
5769 }
5870 this . setState ( newState ) ;
@@ -72,6 +84,13 @@ export default class App extends React.Component {
7284 onSelect = { this . selectBranch }
7385 style = { { marginBottom : '10px' } }
7486 >
87+ < MenuItem key = { App . allBranchName } eventKey = { App . allBranchName } >
88+ { App . allBranchName }
89+ </ MenuItem >
90+ < MenuItem key = { App . defaultBranchName } eventKey = { App . defaultBranchName } >
91+ { App . defaultBranchName }
92+ </ MenuItem >
93+ < MenuItem divider />
7594 { this . state . branches . map ( branch =>
7695 < MenuItem key = { branch } eventKey = { branch } > { branch } </ MenuItem >
7796 ) }
0 commit comments