Commit d103e955 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'add-view-replaced-file-link' into 'master'

Add view replaced file link for image diffs

See merge request gitlab-org/gitlab-ce!14394
parents f357fc7d 9c096ddf
...@@ -176,13 +176,15 @@ module CommitsHelper ...@@ -176,13 +176,15 @@ module CommitsHelper
end end
end end
def view_file_button(commit_sha, diff_new_path, project) def view_file_button(commit_sha, diff_new_path, project, replaced: false)
title = replaced ? _('View replaced file @ ') : _('View file @ ')
link_to( link_to(
project_blob_path(project, project_blob_path(project,
tree_join(commit_sha, diff_new_path)), tree_join(commit_sha, diff_new_path)),
class: 'btn view-file js-view-file' class: 'btn view-file js-view-file'
) do ) do
raw('View file @ ') + content_tag(:span, Commit.truncate_sha(commit_sha), raw(title) + content_tag(:span, Commit.truncate_sha(commit_sha),
class: 'commit-sha') class: 'commit-sha')
end end
end end
......
- environment = local_assigns.fetch(:environment, nil) - environment = local_assigns.fetch(:environment, nil)
- file_hash = hexdigest(diff_file.file_path) - file_hash = hexdigest(diff_file.file_path)
- image_diff = diff_file.rich_viewer && diff_file.rich_viewer.partial_name == 'image'
- image_replaced = diff_file.old_content_sha && diff_file.old_content_sha != diff_file.content_sha
.diff-file.file-holder{ id: file_hash, data: diff_file_html_data(project, diff_file.file_path, diff_file.content_sha) } .diff-file.file-holder{ id: file_hash, data: diff_file_html_data(project, diff_file.file_path, diff_file.content_sha) }
.js-file-title.file-title-flex-parent .js-file-title.file-title-flex-parent
.file-header-content .file-header-content
...@@ -17,6 +20,9 @@ ...@@ -17,6 +20,9 @@
= edit_blob_link(@merge_request.source_project, @merge_request.source_branch, diff_file.new_path, = edit_blob_link(@merge_request.source_project, @merge_request.source_branch, diff_file.new_path,
blob: blob, link_opts: link_opts) blob: blob, link_opts: link_opts)
- if image_diff && image_replaced
= view_file_button(diff_file.old_content_sha, diff_file.old_path, project, replaced: true)
= view_file_button(diff_file.content_sha, diff_file.file_path, project) = view_file_button(diff_file.content_sha, diff_file.file_path, project)
= view_on_environment_button(diff_file.content_sha, diff_file.file_path, environment) if environment = view_on_environment_button(diff_file.content_sha, diff_file.file_path, environment) if environment
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
.two-up.view .two-up.view
%span.wrap %span.wrap
.frame.deleted .frame.deleted
%a{ href: project_blob_path(@project, tree_join(diff_file.old_content_sha, diff_file.old_path)) }
= image_tag(old_blob_raw_path, alt: diff_file.old_path) = image_tag(old_blob_raw_path, alt: diff_file.old_path)
%p.image-info.hide %p.image-info.hide
%span.meta-filesize= number_to_human_size(old_blob.size) %span.meta-filesize= number_to_human_size(old_blob.size)
...@@ -27,7 +26,6 @@ ...@@ -27,7 +26,6 @@
%span.meta-height %span.meta-height
%span.wrap %span.wrap
.frame.added .frame.added
%a{ href: project_blob_path(@project, tree_join(diff_file.content_sha, diff_file.new_path)) }
= image_tag(blob_raw_path, alt: diff_file.new_path) = image_tag(blob_raw_path, alt: diff_file.new_path)
%p.image-info.hide %p.image-info.hide
%span.meta-filesize= number_to_human_size(blob.size) %span.meta-filesize= number_to_human_size(blob.size)
......
---
title: Add view replaced file link for image diffs
merge_request:
author:
type: changed
...@@ -139,7 +139,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps ...@@ -139,7 +139,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
end end
step 'The diff links to both the previous and current image' do step 'The diff links to both the previous and current image' do
links = page.all('.two-up span div a') links = page.all('.file-actions a')
expect(links[0]['href']).to match %r{blob/#{sample_image_commit.old_blob_id}} expect(links[0]['href']).to match %r{blob/#{sample_image_commit.old_blob_id}}
expect(links[1]['href']).to match %r{blob/#{sample_image_commit.new_blob_id}} expect(links[1]['href']).to match %r{blob/#{sample_image_commit.new_blob_id}}
end end
......
...@@ -62,6 +62,7 @@ feature 'Diff file viewer', :js do ...@@ -62,6 +62,7 @@ feature 'Diff file viewer', :js do
end end
context 'Image file' do context 'Image file' do
context 'Replaced' do
before do before do
visit_commit('2f63565e7aac07bcdadb654e253078b727143ec4') visit_commit('2f63565e7aac07bcdadb654e253078b727143ec4')
end end
...@@ -71,6 +72,35 @@ feature 'Diff file viewer', :js do ...@@ -71,6 +72,35 @@ feature 'Diff file viewer', :js do
expect(page).to have_css('img[alt="files/images/6049019_460s.jpg"]') expect(page).to have_css('img[alt="files/images/6049019_460s.jpg"]')
end end
end end
it 'shows view replaced and view file links' do
expect(page.all('.file-actions a').length).to eq 2
expect(page.all('.file-actions a')[0]).to have_content 'View replaced file @'
expect(page.all('.file-actions a')[1]).to have_content 'View file @'
end
end
context 'Added' do
before do
visit_commit('33f3729a45c02fc67d00adb1b8bca394b0e761d9')
end
it 'shows view file link' do
expect(page.all('.file-actions a').length).to eq 1
expect(page.all('.file-actions a')[0]).to have_content 'View file @'
end
end
context 'Deleted' do
before do
visit_commit('7fd7a459706ee87be6f855fd98ce8c552b15529a')
end
it 'shows view file link' do
expect(page.all('.file-actions a').length).to eq 1
expect(page.all('.file-actions a')[0]).to have_content 'View file @'
end
end
end end
context 'ISO file (stored in LFS)' do context 'ISO file (stored in LFS)' do
......
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