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
This commit is contained in:
commit
d103e95513
6 changed files with 53 additions and 12 deletions
|
@ -176,13 +176,15 @@ module CommitsHelper
|
|||
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(
|
||||
project_blob_path(project,
|
||||
tree_join(commit_sha, diff_new_path)),
|
||||
class: 'btn view-file js-view-file'
|
||||
) 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')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
- environment = local_assigns.fetch(:environment, nil)
|
||||
- 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) }
|
||||
.js-file-title.file-title-flex-parent
|
||||
.file-header-content
|
||||
|
@ -17,6 +20,9 @@
|
|||
= edit_blob_link(@merge_request.source_project, @merge_request.source_branch, diff_file.new_path,
|
||||
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_on_environment_button(diff_file.content_sha, diff_file.file_path, environment) if environment
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
.two-up.view
|
||||
%span.wrap
|
||||
.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
|
||||
%span.meta-filesize= number_to_human_size(old_blob.size)
|
||||
|
|
||||
|
@ -27,8 +26,7 @@
|
|||
%span.meta-height
|
||||
%span.wrap
|
||||
.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
|
||||
%span.meta-filesize= number_to_human_size(blob.size)
|
||||
|
|
||||
|
|
5
changelogs/unreleased/add-view-replaced-file-link.yml
Normal file
5
changelogs/unreleased/add-view-replaced-file-link.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Add view replaced file link for image diffs
|
||||
merge_request:
|
||||
author:
|
||||
type: changed
|
|
@ -139,7 +139,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
|
|||
end
|
||||
|
||||
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[1]['href']).to match %r{blob/#{sample_image_commit.new_blob_id}}
|
||||
end
|
||||
|
|
|
@ -62,13 +62,43 @@ feature 'Diff file viewer', :js do
|
|||
end
|
||||
|
||||
context 'Image file' do
|
||||
before do
|
||||
visit_commit('2f63565e7aac07bcdadb654e253078b727143ec4')
|
||||
context 'Replaced' do
|
||||
before do
|
||||
visit_commit('2f63565e7aac07bcdadb654e253078b727143ec4')
|
||||
end
|
||||
|
||||
it 'shows a rendered image' do
|
||||
within('.diff-file[id="e986451b8f7397b617dbb6fffcb5539328c56921"]') do
|
||||
expect(page).to have_css('img[alt="files/images/6049019_460s.jpg"]')
|
||||
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
|
||||
|
||||
it 'shows a rendered image' do
|
||||
within('.diff-file[id="e986451b8f7397b617dbb6fffcb5539328c56921"]') do
|
||||
expect(page).to have_css('img[alt="files/images/6049019_460s.jpg"]')
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue