Fix diff bottom expand button appears twice

This is a quick fix by only append match line once
when calling diff_lines_for_serializer multiple time.

Also enable feature by default
This commit is contained in:
Mark Chao 2019-03-21 21:38:52 +08:00
parent 8a59c9fdba
commit 8723f29255
4 changed files with 28 additions and 11 deletions

View file

@ -57,7 +57,7 @@ class DiffFileEntity < DiffFileBaseEntity
diff_file.diff_lines_for_serializer
end
expose :is_fully_expanded, if: -> (diff_file, _) { Feature.enabled?(:expand_diff_full_file) && diff_file.text? } do |diff_file|
expose :is_fully_expanded, if: -> (diff_file, _) { Feature.enabled?(:expand_diff_full_file, default_enabled: true) && diff_file.text? } do |diff_file|
diff_file.fully_expanded?
end

View file

@ -0,0 +1,5 @@
---
title: Fix duplicated bottom match line on merge request parallel diff view
merge_request: 26402
author:
type: fixed

View file

@ -158,7 +158,10 @@ module Gitlab
new_blob || old_blob
end
attr_writer :highlighted_diff_lines
def highlighted_diff_lines=(value)
clear_memoization(:diff_lines_for_serializer)
@highlighted_diff_lines = value
end
# Array of Gitlab::Diff::Line objects
def diff_lines
@ -314,10 +317,11 @@ module Gitlab
# This adds the bottom match line to the array if needed. It contains
# the data to load more context lines.
def diff_lines_for_serializer
strong_memoize(:diff_lines_for_serializer) do
lines = highlighted_diff_lines
return if lines.empty?
return if blob.nil?
next if lines.empty?
next if blob.nil?
last_line = lines.last
@ -328,6 +332,7 @@ module Gitlab
lines
end
end
def fully_expanded?
return true if binary?

View file

@ -72,6 +72,13 @@ describe Gitlab::Diff::File do
expect(diff_file.diff_lines_for_serializer.last.type).to eq('match')
end
context 'when called multiple times' do
it 'only adds bottom match line once' do
expect(diff_file.diff_lines_for_serializer.size).to eq(31)
expect(diff_file.diff_lines_for_serializer.size).to eq(31)
end
end
context 'when deleted' do
let(:commit) { project.commit('d59c60028b053793cecfb4022de34602e1a9218e') }
let(:diff_file) { commit.diffs.diff_file_with_old_path('files/js/commit.js.coffee') }