Skip to content

Commit d2cd8ca

Browse files
committed
branch list modification & initial branch modification
* branch list modification ** "All Branch" is listed at the top of the branch menu. If repo has so many branches, I think more covenient. ** "Default Branch" short-cut menu entry added. * initial branch modification ** show graph with default branch at initial.
1 parent 1470c9b commit d2cd8ca

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

scripts/components/App.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import 'whatwg-fetch';
77
export 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
)}

src/main/scala/mrkm4ntr/gitbucket/network/controller/NetworkController.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,23 @@ trait NetworkControllerBase extends ControllerBase {
6464
}
6565
}
6666

67-
val currentBranch = params.get("branch")
67+
val allBranches = params.get("all")
68+
val currentBranch = params.getOrElse("branch", repository.repository.defaultBranch)
6869
val count = params.getOrElse("count", "100").toInt
6970
val repo = git.getRepository
7071
val revWalk = new PlotWalk(repo)
7172
revWalk.sort(RevSort.COMMIT_TIME_DESC)
7273
try {
73-
currentBranch match {
74-
case Some(branch) => revWalk.markStart(revWalk.parseCommit(repo.resolve(branch)))
75-
case _ => revWalk.markStart(repository.branchList.map(repo.resolve(_)).map(revWalk.parseCommit(_)).asJava)
74+
if(allBranches != None) {
75+
revWalk.markStart(repository.branchList.map(repo.resolve(_)).map(revWalk.parseCommit(_)).asJava)
76+
} else {
77+
revWalk.markStart(revWalk.parseCommit(repo.resolve(currentBranch)))
7678
}
7779
val plotCommitList = new PlotCommitList[PlotLane]
7880
plotCommitList.source(revWalk)
7981
plotCommitList.fillTo(count)
8082
val result = traverse(plotCommitList.asScala.zipWithIndex.toList, None, 0, Nil)
81-
Data(result._1, result._2.reverse, repository.branchList, currentBranch)
83+
Data(result._1, result._2.reverse, repository.branchList, currentBranch, repository.repository.defaultBranch, allBranches)
8284
} finally {
8385
revWalk.dispose()
8486
}
@@ -136,7 +138,9 @@ case class Data(
136138
maxLane: Int,
137139
commits: Seq[Commit],
138140
branches: Seq[String],
139-
currentBranch: Option[String])
141+
currentBranch: String,
142+
defaultBranch: String,
143+
all: Option[String])
140144

141145
case class Commit(
142146
index: Int,

test/components/App.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('App', () => {
8686
const wrapper = shallow(<App />);
8787
const instance = wrapper.instance();
8888
const mock = sinon.mock(instance);
89-
mock.expects('fetchData').withArgs({ count: 1000 });
89+
mock.expects('fetchData').withArgs({ all: 1, count: 1000 });
9090
instance.selectCount(1000);
9191
assert(mock.verify());
9292
});

0 commit comments

Comments
 (0)