Skip to content

Commit 84361e2

Browse files
committed
add branch drop down filter
1 parent 2b5ef92 commit 84361e2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"rules": {
1515
"react/jsx-uses-react": "error",
1616
"react/jsx-uses-vars": "error"
17+
},
18+
"env": {
19+
"jquery": true
1720
}
1821
}

scripts/components/App.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import DropdownButton from 'react-bootstrap/lib/DropdownButton';
33
import MenuItem from 'react-bootstrap/lib/MenuItem';
44
import CommitGraph from './CommitGraph';
5+
import FormControl from 'react-bootstrap/lib/FormControl';
56
import 'whatwg-fetch';
67

78
export default class App extends React.Component {
@@ -75,6 +76,30 @@ export default class App extends React.Component {
7576
});
7677
}
7778

79+
stopPropagation(e) {
80+
console.log(e.target.value);
81+
e.preventDefault();
82+
e.stopPropagation();
83+
}
84+
85+
doFilter(e) {
86+
const branchFilter = $(e.target);
87+
const inputVal = branchFilter.val();
88+
$.each(
89+
branchFilter.parent().parent().parent()
90+
.find('a'),
91+
(index, elem) => {
92+
if (!inputVal ||
93+
!elem.text.trim() ||
94+
elem.text.trim().toLowerCase().indexOf(inputVal.toLowerCase()) >= 0) {
95+
$(elem).parent().show();
96+
} else {
97+
$(elem).parent().hide();
98+
}
99+
}
100+
);
101+
}
102+
78103
render() {
79104
return (
80105
<div style={{ marginLeft: '20px' }}>
@@ -90,6 +115,15 @@ export default class App extends React.Component {
90115
<MenuItem key={App.defaultBranchName} eventKey={App.defaultBranchName}>
91116
{App.defaultBranchName}
92117
</MenuItem>
118+
<MenuItem>
119+
<FormControl
120+
type="text"
121+
value={this.state.value}
122+
placeholder="Find branch..."
123+
onClick={this.stopPropagation}
124+
onKeyUp={this.doFilter}
125+
/>
126+
</MenuItem>
93127
<MenuItem divider />
94128
{this.state.branches.map(branch =>
95129
<MenuItem key={branch} eventKey={branch}>{branch}</MenuItem>

0 commit comments

Comments
 (0)