Commit b502d90a authored by Lin Jen-Shin's avatar Lin Jen-Shin Committed by John Cai

Adapt that diverging commits could be just one bar

refactors the ui for diverging commits so that it's only a single
bar instead of two separate bars
parent 1f2f38f5
1.18.0 1.18.0
\ No newline at end of file
...@@ -11,15 +11,24 @@ ...@@ -11,15 +11,24 @@
} }
.divergence-graph { .divergence-graph {
$graph-side-width: 80px;
$graph-separator-width: 1px;
padding: 0 6px; padding: 0 6px;
.graph-side { .graph-side {
position: relative; position: relative;
width: 80px; width: $graph-side-width;
height: 22px; height: 22px;
padding: 5px 0 13px; padding: 5px 0 13px;
float: left; float: left;
&.full {
width: $graph-side-width * 2 + $graph-separator-width;
display: flex;
justify-content: center;
}
.bar { .bar {
position: absolute; position: absolute;
height: 4px; height: 4px;
...@@ -57,7 +66,7 @@ ...@@ -57,7 +66,7 @@
.graph-separator { .graph-separator {
position: relative; position: relative;
width: 1px; width: $graph-separator-width;
height: 18px; height: 18px;
margin: 5px 0 0; margin: 5px 0 0;
float: left; float: left;
......
...@@ -29,7 +29,8 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -29,7 +29,8 @@ class Projects::BranchesController < Projects::ApplicationController
Gitlab::GitalyClient.allow_n_plus_1_calls do Gitlab::GitalyClient.allow_n_plus_1_calls do
@max_commits = @branches.reduce(0) do |memo, branch| @max_commits = @branches.reduce(0) do |memo, branch|
diverging_commit_counts = repository.diverging_commit_counts(branch) diverging_commit_counts = repository.diverging_commit_counts(branch)
[memo, diverging_commit_counts[:behind], diverging_commit_counts[:ahead]].max [memo, diverging_commit_counts.values_at(:behind, :ahead, :distance)]
.flatten.compact.max
end end
end end
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
- commit = @repository.commit(branch.dereferenced_target) - commit = @repository.commit(branch.dereferenced_target)
- bar_graph_width_factor = @max_commits > 0 ? 100.0/@max_commits : 0 - bar_graph_width_factor = @max_commits > 0 ? 100.0/@max_commits : 0
- diverging_commit_counts = @repository.diverging_commit_counts(branch) - diverging_commit_counts = @repository.diverging_commit_counts(branch)
- number_commits_distance = diverging_commit_counts[:distance]
- number_commits_behind = diverging_commit_counts[:behind] - number_commits_behind = diverging_commit_counts[:behind]
- number_commits_ahead = diverging_commit_counts[:ahead] - number_commits_ahead = diverging_commit_counts[:ahead]
- merge_project = merge_request_source_project_for_project(@project) - merge_project = merge_request_source_project_for_project(@project)
...@@ -28,16 +29,23 @@ ...@@ -28,16 +29,23 @@
= s_('Branches|Cant find HEAD commit for this branch') = s_('Branches|Cant find HEAD commit for this branch')
- if branch.name != @repository.root_ref - if branch.name != @repository.root_ref
.divergence-graph.d-none.d-md-block{ title: s_('%{number_commits_behind} commits behind %{default_branch}, %{number_commits_ahead} commits ahead') % { number_commits_behind: diverging_count_label(number_commits_behind), - if number_commits_distance.nil?
default_branch: @repository.root_ref, .divergence-graph.d-none.d-md-block{ title: s_('%{number_commits_behind} commits behind %{default_branch}, %{number_commits_ahead} commits ahead') % { number_commits_behind: diverging_count_label(number_commits_behind),
number_commits_ahead: diverging_count_label(number_commits_ahead) } } default_branch: @repository.root_ref,
.graph-side number_commits_ahead: diverging_count_label(number_commits_ahead) } }
.bar.bar-behind{ style: "width: #{number_commits_behind * bar_graph_width_factor}%" } .graph-side
%span.count.count-behind= diverging_count_label(number_commits_behind) .bar.bar-behind{ style: "width: #{number_commits_behind * bar_graph_width_factor}%" }
.graph-separator %span.count.count-behind= diverging_count_label(number_commits_behind)
.graph-side .graph-separator
.bar.bar-ahead{ style: "width: #{number_commits_ahead * bar_graph_width_factor}%" } .graph-side
%span.count.count-ahead= diverging_count_label(number_commits_ahead) .bar.bar-ahead{ style: "width: #{number_commits_ahead * bar_graph_width_factor}%" }
%span.count.count-ahead= diverging_count_label(number_commits_ahead)
- else
.divergence-graph.d-none.d-md-block{ title: s_('More than %{number_commits_distance} commits different with %{default_branch}') % { number_commits_distance: diverging_count_label(number_commits_distance),
default_branch: @repository.root_ref} }
.graph-side.full
.bar{ style: "width: #{number_commits_distance * bar_graph_width_factor}%" }
%span.count= diverging_count_label(number_commits_distance)
.controls.d-none.d-md-block< .controls.d-none.d-md-block<
- if merge_project && create_mr_button?(@repository.root_ref, branch.name) - if merge_project && create_mr_button?(@repository.root_ref, branch.name)
......
...@@ -4630,6 +4630,9 @@ msgstr "" ...@@ -4630,6 +4630,9 @@ msgstr ""
msgid "More information is available|here" msgid "More information is available|here"
msgstr "" msgstr ""
msgid "More than %{number_commits_distance} commits different with %{default_branch}"
msgstr ""
msgid "Most stars" msgid "Most stars"
msgstr "" msgstr ""
......
...@@ -15,6 +15,8 @@ describe "User views branches" do ...@@ -15,6 +15,8 @@ describe "User views branches" do
it "shows branches" do it "shows branches" do
expect(page).to have_content("Branches").and have_content("master") expect(page).to have_content("Branches").and have_content("master")
expect(page.all(".graph-side")).to all( have_content(/\d+/) )
end end
end end
......
...@@ -302,6 +302,7 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -302,6 +302,7 @@ describe Gitlab::Git::Repository, :seed_helper do
before do before do
repository.create_branch('left-branch', 'master') repository.create_branch('left-branch', 'master')
repository.create_branch('right-branch', 'master') repository.create_branch('right-branch', 'master')
left.times do left.times do
new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff')
end end
...@@ -319,10 +320,10 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -319,10 +320,10 @@ describe Gitlab::Git::Repository, :seed_helper do
it 'returns the correct count bounding at max_count' do it 'returns the correct count bounding at max_count' do
branch_a_sha = repository_rugged.branches['left-branch'].target.oid branch_a_sha = repository_rugged.branches['left-branch'].target.oid
branch_b_sha = repository_rugged.branches['right-branch'].target.oid branch_b_sha = repository_rugged.branches['right-branch'].target.oid
expect(
repository.diverging_commit_count( count = repository.diverging_commit_count(branch_a_sha, branch_b_sha, max_count: 1000)
branch_a_sha, branch_b_sha, max_count: 1000)
).to eq(expected) expect(count).to eq(expected)
end end
end end
end end
...@@ -341,6 +342,7 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -341,6 +342,7 @@ describe Gitlab::Git::Repository, :seed_helper do
before do before do
repository.create_branch('left-branch', 'master') repository.create_branch('left-branch', 'master')
repository.create_branch('right-branch', 'master') repository.create_branch('right-branch', 'master')
left.times do left.times do
new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff')
end end
...@@ -358,7 +360,9 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -358,7 +360,9 @@ describe Gitlab::Git::Repository, :seed_helper do
it 'returns the correct count bounding at max_count' do it 'returns the correct count bounding at max_count' do
branch_a_sha = repository_rugged.branches['left-branch'].target.oid branch_a_sha = repository_rugged.branches['left-branch'].target.oid
branch_b_sha = repository_rugged.branches['right-branch'].target.oid branch_b_sha = repository_rugged.branches['right-branch'].target.oid
results = repository.diverging_commit_count(branch_a_sha, branch_b_sha, max_count: max_count) results = repository.diverging_commit_count(branch_a_sha, branch_b_sha, max_count: max_count)
expect(results[0] + results[1]).to eq(max_count) expect(results[0] + results[1]).to eq(max_count)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment