BigW Consortium Gitlab

Commit 5f0535ac by Dmitriy Zaporozhets

Improve merge request version feature

* Use version numbers instead of sha as more user-friendly * Make it clear that we compare later version (left) with older one (right) * Improve wording of version switch panel Signed-off-by: 's avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent ffdfdc27
...@@ -383,10 +383,6 @@ ...@@ -383,10 +383,6 @@
a.btn-link { a.btn-link {
color: $gl-dark-link-color; color: $gl-dark-link-color;
} }
.compare-dots {
margin: 0 $btn-side-margin;
}
} }
.merge-request-details { .merge-request-details {
......
...@@ -95,7 +95,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -95,7 +95,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
if params[:start_sha].present? if params[:start_sha].present?
@start_sha = params[:start_sha] @start_sha = params[:start_sha]
validate_start_sha @start_version = @comparable_diffs.find { |diff| diff.head_commit_sha == @start_sha }
unless @start_version
render_404
end
end end
respond_to do |format| respond_to do |format|
...@@ -554,10 +558,4 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -554,10 +558,4 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@diffs = @merge_request_diff.diffs(diff_options) @diffs = @merge_request_diff.diffs(diff_options)
end end
def validate_start_sha
unless @comparable_diffs.map(&:head_commit_sha).include?(@start_sha)
render_404
end
end
end end
...@@ -4,6 +4,6 @@ module GitHelper ...@@ -4,6 +4,6 @@ module GitHelper
end end
def short_sha(text) def short_sha(text)
text[0...8] Commit.truncate_sha(text)
end end
end end
...@@ -106,4 +106,8 @@ module MergeRequestsHelper ...@@ -106,4 +106,8 @@ module MergeRequestsHelper
project.namespace, project, merge_request, project.namespace, project, merge_request,
diff_id: merge_request_diff.id, start_sha: start_sha) diff_id: merge_request_diff.id, start_sha: start_sha)
end end
def version_index(merge_request_diff)
@merge_request_diffs.size - @merge_request_diffs.index(merge_request_diff)
end
end end
- if @merge_request_diffs.size > 1 - if @merge_request_diffs.size > 1
.mr-version-controls .mr-version-controls
Version Changes between
%span.dropdown.inline.mr-version-dropdown %span.dropdown.inline.mr-version-dropdown
%a.btn-link.dropdown-toggle{ data: {toggle: :dropdown} } %a.btn-link.dropdown-toggle{ data: {toggle: :dropdown} }
%strong.monospace< %strong
- if @merge_request_diff.latest? - if @merge_request_diff.latest?
Latest:&nbsp; latest version
#{short_sha(@merge_request_diff.head_commit_sha)} - else
version #{version_index(@merge_request_diff)}
%span.caret %span.caret
%ul.dropdown-menu.dropdown-menu-selectable %ul.dropdown-menu.dropdown-menu-selectable
- @merge_request_diffs.each_with_index do |merge_request_diff, i| - @merge_request_diffs.each do |merge_request_diff|
%li %li
= link_to merge_request_version_path(@project, @merge_request, merge_request_diff), class: ('is-active' if merge_request_diff == @merge_request_diff) do = link_to merge_request_version_path(@project, @merge_request, merge_request_diff), class: ('is-active' if merge_request_diff == @merge_request_diff) do
%strong.monospace %strong
- if i.zero? - if merge_request_diff.latest?
Latest: latest version
- else - else
#{@merge_request_diffs.size - i}. version #{version_index(merge_request_diff)}
#{short_sha(merge_request_diff.head_commit_sha)} .monospace #{short_sha(merge_request_diff.head_commit_sha)}
%br
%small %small
#{number_with_delimiter(merge_request_diff.commits.count)} #{'commit'.pluralize(merge_request_diff.commits.count)}, #{number_with_delimiter(merge_request_diff.commits.count)} #{'commit'.pluralize(merge_request_diff.commits.count)},
= time_ago_with_tooltip(merge_request_diff.created_at) = time_ago_with_tooltip(merge_request_diff.created_at)
- if @merge_request_diff.base_commit_sha - if @merge_request_diff.base_commit_sha
%span.compare-dots ... &nbsp;and&nbsp;
Compared with
%span.dropdown.inline.mr-version-compare-dropdown %span.dropdown.inline.mr-version-compare-dropdown
%a.btn-link.dropdown-toggle{ data: {toggle: :dropdown} } %a.btn-link.dropdown-toggle{ data: {toggle: :dropdown} }
%strong.monospace< %strong
- if @start_sha - if @start_sha
#{short_sha(@start_sha)} version #{version_index(@start_version)}
- else - else
Base: #{short_sha(@merge_request_diff.base_commit_sha)} #{@merge_request.target_branch}
%span.caret %span.caret
%ul.dropdown-menu.dropdown-menu-selectable %ul.dropdown-menu.dropdown-menu-selectable
- @comparable_diffs.each_with_index do |merge_request_diff, i| - @comparable_diffs.each do |merge_request_diff|
%li %li
= link_to merge_request_version_path(@project, @merge_request, @merge_request_diff, merge_request_diff.head_commit_sha), class: ('is-active' if merge_request_diff.head_commit_sha == @start_sha) do = link_to merge_request_version_path(@project, @merge_request, @merge_request_diff, merge_request_diff.head_commit_sha), class: ('is-active' if merge_request_diff == @start_version) do
%strong.monospace %strong
#{@comparable_diffs.size - i}. #{short_sha(merge_request_diff.head_commit_sha)} - if merge_request_diff.latest?
%br latest version
- else
version #{version_index(merge_request_diff)}
.monospace #{short_sha(merge_request_diff.head_commit_sha)}
%small %small
= time_ago_with_tooltip(merge_request_diff.created_at) = time_ago_with_tooltip(merge_request_diff.created_at)
%li %li
= link_to merge_request_version_path(@project, @merge_request, @merge_request_diff), class: ('is-active' unless @start_sha) do = link_to merge_request_version_path(@project, @merge_request, @merge_request_diff), class: ('is-active' unless @start_sha) do
%strong.monospace %strong
Base: #{short_sha(@merge_request_diff.base_commit_sha)} #{@merge_request.target_branch} (base)
.monospace #{short_sha(@merge_request_diff.base_commit_sha)}
- unless @merge_request_diff.latest? && !@start_sha - unless @merge_request_diff.latest? && !@start_sha
.prepend-top-10 .prepend-top-10
......
...@@ -12,7 +12,7 @@ feature 'Merge Request versions', js: true, feature: true do ...@@ -12,7 +12,7 @@ feature 'Merge Request versions', js: true, feature: true do
it 'show the latest version of the diff' do it 'show the latest version of the diff' do
page.within '.mr-version-dropdown' do page.within '.mr-version-dropdown' do
expect(page).to have_content 'Latest: 5937ac0a' expect(page).to have_content 'latest version'
end end
expect(page).to have_content '8 changed files' expect(page).to have_content '8 changed files'
...@@ -22,13 +22,13 @@ feature 'Merge Request versions', js: true, feature: true do ...@@ -22,13 +22,13 @@ feature 'Merge Request versions', js: true, feature: true do
before do before do
page.within '.mr-version-dropdown' do page.within '.mr-version-dropdown' do
find('.btn-link').click find('.btn-link').click
click_link '6f6d7e7e' click_link 'version 1'
end end
end end
it 'should show older version' do it 'should show older version' do
page.within '.mr-version-dropdown' do page.within '.mr-version-dropdown' do
expect(page).to have_content '6f6d7e7e' expect(page).to have_content 'version 1'
end end
expect(page).to have_content '5 changed files' expect(page).to have_content '5 changed files'
...@@ -43,13 +43,13 @@ feature 'Merge Request versions', js: true, feature: true do ...@@ -43,13 +43,13 @@ feature 'Merge Request versions', js: true, feature: true do
before do before do
page.within '.mr-version-compare-dropdown' do page.within '.mr-version-compare-dropdown' do
find('.btn-link').click find('.btn-link').click
click_link '6f6d7e7e' click_link 'version 1'
end end
end end
it 'should has correct value in the compare dropdown' do it 'should has correct value in the compare dropdown' do
page.within '.mr-version-compare-dropdown' do page.within '.mr-version-compare-dropdown' do
expect(page).to have_content '6f6d7e7e' expect(page).to have_content 'version 1'
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