@@ -2,6 +2,7 @@ import React from 'react';
22import DropdownButton from 'react-bootstrap/lib/DropdownButton' ;
33import MenuItem from 'react-bootstrap/lib/MenuItem' ;
44import CommitGraph from './CommitGraph' ;
5+ import FormControl from 'react-bootstrap/lib/FormControl' ;
56import 'whatwg-fetch' ;
67
78export default class App extends React . Component {
@@ -18,13 +19,17 @@ export default class App extends React.Component {
1819 super ( props ) ;
1920 this . selectBranch = this . selectBranch . bind ( this ) ;
2021 this . selectCount = this . selectCount . bind ( this ) ;
22+ this . clearFilter = this . clearFilter . bind ( this ) ;
23+ this . changeFilter = this . changeFilter . bind ( this ) ;
2124 this . state = {
2225 maxLane : 0 ,
2326 commits : [ ] ,
2427 branches : [ ] ,
2528 currentBranch : App . allBranchName ,
2629 isFetching : true ,
2730 count : 100 ,
31+ displayCount : 100 ,
32+ filter : '' ,
2833 } ;
2934 }
3035
@@ -48,6 +53,7 @@ export default class App extends React.Component {
4853 }
4954
5055 selectBranch ( branch ) {
56+ if ( branch . startsWith ( '.' ) ) return ;
5157 const params = this . setParams ( branch , { count : this . state . count } ) ;
5258 this . fetchData ( params ) ;
5359 }
@@ -63,7 +69,12 @@ export default class App extends React.Component {
6369 return window . fetch ( `./network/commits?${ query } ` , { credentials : 'include' } ) . then (
6470 r => r . json ( )
6571 ) . then ( data => {
66- const newState = Object . assign ( { count : params . count , isFetching : false } , data ) ;
72+ const newState = Object . assign ( { count : params . count , isFetching : false } ,
73+ data ,
74+ { branches : data . branches . map (
75+ branch => ( { branch, visible : true } ) ) } ,
76+ { displayCount : data . branches . length }
77+ ) ;
6778 if ( data . all ) {
6879 newState . currentBranch = App . allBranchName ;
6980 }
@@ -75,6 +86,40 @@ export default class App extends React.Component {
7586 } ) ;
7687 }
7788
89+ stopPropagation ( e ) {
90+ console . log ( e . target . value ) ;
91+ e . preventDefault ( ) ;
92+ e . stopPropagation ( ) ;
93+ }
94+
95+ changeFilter ( e ) {
96+ this . filter ( e . target . value ) ;
97+ }
98+
99+ clearFilter ( e ) {
100+ e . preventDefault ( ) ;
101+ e . stopPropagation ( ) ;
102+
103+ this . filter ( '' ) ;
104+ }
105+
106+ filter ( value ) {
107+ this . setState ( Object . assign ( this . state , { filter : value } ) ) ;
108+
109+ this . setState ( Object . assign ( this . state , {
110+ branches : this . state . branches . map ( ( { branch } ) => ( {
111+ branch,
112+ visible : this . state . filter ?
113+ branch . toLowerCase ( ) . indexOf ( this . state . filter . toLowerCase ( ) ) >= 0 : true ,
114+ } ) ) ,
115+ } ) ) ;
116+
117+ this . setState ( Object . assign ( this . state , {
118+ displayCount : this . state . branches . reduce ( ( prev , current ) =>
119+ prev + ( current . visible ? 1 : 0 ) , 0 ) ,
120+ } ) ) ;
121+ }
122+
78123 render ( ) {
79124 return (
80125 < div style = { { marginLeft : '20px' } } >
@@ -90,10 +135,27 @@ export default class App extends React.Component {
90135 < MenuItem key = { App . defaultBranchName } eventKey = { App . defaultBranchName } >
91136 { App . defaultBranchName }
92137 </ MenuItem >
138+ < MenuItem >
139+ < div style = { { display : 'flex' , alignItems : 'center' } } >
140+ < FormControl
141+ type = "text" placeholder = "Find branch..."
142+ style = { { width : '90%' } }
143+ value = { this . state . filter }
144+ onClick = { this . stopPropagation }
145+ onChange = { this . changeFilter }
146+ />
147+ < i
148+ className = "octicon octicon-x" style = { { display : 'flex' } }
149+ onClick = { this . clearFilter }
150+ />
151+ </ div >
152+ </ MenuItem >
93153 < MenuItem divider />
94- { this . state . branches . map ( branch =>
154+ { this . state . branches . filter ( ( { visible } ) => visible ) . map ( ( { branch } ) =>
95155 < MenuItem key = { branch } eventKey = { branch } > { branch } </ MenuItem >
96156 ) }
157+ { this . state . displayCount === 0 ?
158+ ( < MenuItem eventKey = "." > NO MATCHED BRANCH</ MenuItem > ) : ( null ) }
97159 </ DropdownButton >
98160 < DropdownButton
99161 id = "countSelector"
0 commit comments